Hey there,

After reading many posts and this excellent description of the menu generation process - http://drupal.org/node/10901 - I have questions of exactly how to start building a module to supplant the menu items and links derived from the menu callback with icons. It would seem there are a few ways to do this:

1) possibly with CSS : to implement this properly I think you would have to patch core to add/have both an 'id=' and a 'class=' to the menu output so that you end up with, for example

Comments

andypost’s picture

I got same task. I try to choose 3rd way a module development, because cant find a different way.

First of all i need to insert my form into menu item editing form. There's two ways:
1) use hook_menu() (quick draft but works)

  if ($may_cache) {
    if (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'menu' && arg(3) == 'item' && arg(4) == 'edit' && is_numeric(arg(5))) {
      $items[] = array('path' => 'admin/build/menu/item/edit/'. arg(5),
        'title' => t('Edit menu item'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array('menu_edit_item_form', 'edit', arg(5)),
        'access' => user_access('administer menu'),
        'type' => MENU_CALLBACK);
      $items[] = array('path' => 'admin/build/menu/item/edit/'. arg(5) .'/edit',
        'title' => t('Edit'),
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -10);
      $items[] = array('path' => 'admin/build/menu/item/edit/'. arg(5) .'/image',
        'title' => t('Image'),
        'description' => t('Image for menu item'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array('miimage_menuitem', arg(5)),
        'access' => user_access('administer menu'),
        'type' => MENU_LOCAL_TASK);
    }
  }

1) use hook_form_alter() (quick draft but works)

  if ($form_id == 'menu_edit_item_form' && isset($form['mid']['#value']) && $form['mid']['#value']) {
    $item = db_fetch_array(db_query('SELECT * FROM {miimage} WHERE mid = %d', $form['mid']['#value']));
    $form['miimage'] = array(
      '#type' => 'fieldset',
      '#title' => t('Image'),
      '#collapsible' => TRUE,
      '#collapsed' => empty($item['mid']),
      '#tree' => TRUE,
    );
//some controls for view & upload
    $form['submit']['#weight'] = 10;
  }

I prefer 1st way - it seems more flexible to control and scale module and better performance if page have more then one form.

Next i need to render menu items with images. Overload of theme_menu_item() gives a full control on this.

Any thoughts? Please, post a comment!