D6 Support

agoel96 - August 19, 2008 - 17:23
Project:Auto Menu
Version:5.x-1.0
Component:Code
Category:support request
Priority:normal
Assigned:danielfs
Status:closed
Description

Can someone please port this to D6?

#1

Manuel Garcia - September 5, 2008 - 14:35

yes, it would be nice...
while you're at it, can i18n integration be included also ? :>

This module would be a great usability addition!

#2

harouni - September 23, 2008 - 11:02

I'd love this too :)

#3

Babalu - September 23, 2008 - 11:13

subscribing

#4

danielfs - September 29, 2008 - 18:47
Assigned to:Anonymous» danielfs

Porting it to D6 doesn't seem to be as easy as I expected. Besides, we don't use D6 in the company I work at (yet). Will do when I find the time.

Patches from someone having more free time are more than welcome.

#5

farbridges - October 8, 2008 - 08:18

Did a quick update to D6: it should have the same functionality as the D5 version plus the possibility to set a parent menu item for every node type in each active language.
There is still some work to do, though. Haven't thoroughly tested it and not taken into account any other feature requests or improvements yet. Anyway, here it is:

automenu.module:

<?php
// $Id$

/**
* Implementation of hook_nodeapi().
* Fill in menu section values if user left them empty AND there's a parent
* menu item selected for this node type.
*/

function automenu_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
      $parent_menu = explode(":", variable_get('parentmenu' . $node->language . '_' . $node->type, '0'));
      if ($parent_menu != '0') {
        if (($node->menu['link_title'] == '') || ($node->menu['delete'])) {
          $new_menu = array(
            'link_path' => 'node/' . $node->nid,
            'link_title' => $node->title,
            'plid' => $parent_menu[1],
            //'customized' => true, // ?
          );
          if (!menu_link_save($new_menu)) {
            drupal_set_message(t('There was an error saving the menu link.'), 'error');
          }
          menu_link_save($new_menu); 
        }
      }
      break;
  }
}

/**
* Implementation of hook_form_alter().
* Add the "Default Parent Menu" section to content type edit node.
*/
function automenu_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
    // Get a list of enabled languages.
    // TODO: add language neutral
    $languages = language_list('enabled');
    $languages = $languages[1];

    foreach ($languages as $language) {
      $form['workflow']['parentmenu'. $language->language] = array(
        '#type' => 'select',
        '#title' => t('Default parent menu for nodes ' . $language->name),
        '#default_value' => variable_get('parentmenu' . $language->language . '_' . $form['#node_type']->type, 0),
        '#options' => menu_parent_options(menu_get_menus(), 0),  // TODO filter on menu items of current language
      );
    }
  }
}

automenu.info:

  ; $Id$
  name = AutoMenu
  description = "Automatically set parent menu item for nodes"
  dependencies[] = menu
  core = 6.x

#6

AlexisWilke - October 8, 2008 - 22:22

Hi farbridges,

Excellent! That certainly saved me a lot of research time! 8-)

I create a tarball which is more usual for Drupal, and I fixed the code so it works with the "language neutral" (at least, I think that's what I bumped into.) The $node->language is set to '' whenever you don't turn on the Translation module.

Next, the explode() code generates an array and even the default value of '0' is in the array. So the test to see whether a type has a variable set would fail and all my pages would end up in the default menu (Navigation.)

Also, functionality wise, I need some Content Type to NOT be affected by the Auto-menu feature. For that I simply added an entry called "None". If you select that, then nothing happens (i.e. you're on your own for those types of content.)

The author also had a fix in the hook_nodeapi() that does not appear in your code. I did make the fix in this code.

In any event, this is great! I do not even want my users to know that this is happening so as to force the content in specific menus. The best would be to be able to add the node in multiple menus at once. But at this time I do not need that much functionality! 8-)

Ah! And I added a message so the user knows that his page was saved in a menu (and more or less which one).

Thank you.
Alexis

AttachmentSize
automenu-6.x-1.x-dev.tar_.gz 7.04 KB

#7

farbridges - October 9, 2008 - 08:10

Hi Alexis,

thanks! That's quite an improvement again :-)

Regarding packaging: the automenu.info in the tarball you posted has a "; Information added by drupal.org packaging script on 2008-10-08" section, but the new code has not been added to drupal CVS. Would be nice to have a new branch for this module. Already sent danielfs a message that I'm willing to take over maintenance of this module (if still needed / nobody else wants to).

Farbridges

#8

AlexisWilke - October 9, 2008 - 19:54

Hi Farbridges,

I mentioned to Daniels that I could fix the tarball .info file. I suppose it is not required for the module to work... I could test to see what happens. 8-)

For D6, a new branch would certainly be a good idea. Especially because it is really not 1 to 1 compatible with 5.x.

Thank you.
Alexis

#9

danielfs - October 10, 2008 - 14:48
Status:active» fixed

Sorry for the delay, guys. I've been really busy. :(

Creating a branch for D6 is just the way to go in drupal.org unless we don't care about generating proper D6 releases nor honoring drupal development standards. ;) I've just created it with all the patches you two have sent. The corresponding D6 official release package will be generated automatically by drupal.org scripts within 12 hours.

I'm closing this issue since automenu now DOES have D6 support. For problems with that release, please create additional issues as needed.

#10

Anonymous (not verified) - October 24, 2008 - 14:51
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.