You are here

function menu_icons_form_alter in Menu Icons 8

Same name and namespace in other branches
  1. 6.2 menu_icons.module \menu_icons_form_alter()
  2. 6 menu_icons.module \menu_icons_form_alter()
  3. 7.3 menu_icons.module \menu_icons_form_alter()

Implementation of hook_form_alter().

File

./menu_icons.module, line 28
Module to associate icons with menu items

Code

function menu_icons_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'menu_edit_item') {
    $options = unserialize(db_result(db_query('SELECT options FROM {menu_links} WHERE mlid = %d', $form['menu']['mlid']['#value'])));
    $form['icon'] = array(
      '#type' => 'fieldset',
      '#weight' => 5,
      '#title' => t('Menu icon settings'),
      '#description' => t('If checked, the following icon will be used as background image for this menu item.'),
      '#attributes' => array(
        'class' => 'theme-settings-bottom',
      ),
    );
    $form['icon']["use_icon_logo"] = array(
      '#type' => 'checkbox',
      '#title' => t('Use an icon'),
      '#default_value' => $options['menu_icon']['enable'],
      '#tree' => FALSE,
      '#description' => t('Check this if you want this icon to be used.'),
    );
    if (module_exists('imagecache')) {
      $preset_options = array(
        t('- Menu Icons default -'),
      );
      foreach (imagecache_presets() as $pid => $preset) {
        $preset_options[$preset['presetname']] = $preset['presetname'];
      }
      $form['icon']['imagecache_preset'] = array(
        '#type' => 'select',
        '#title' => t('Imagecache preset'),
        '#default_value' => $options['menu_icon']['imagecache_preset'],
        '#description' => t('Choose an !link to be used for this menu item.', array(
          '!link' => l(t('Imagecache preset'), 'admin/build/imagecache'),
        )),
        '#required' => FALSE,
        '#options' => $preset_options,
      );
    }
    $form['icon']['icon_path'] = array(
      '#type' => 'textfield',
      '#title' => t('Path to the icon'),
      '#default_value' => isset($options['menu_icon']['path']) ? $options['menu_icon']['path'] : variable_get('menu_icons_default_icon', drupal_get_path('module', 'menu_icons') . '/images/default_icon.png'),
      '#description' => t('The path to the image you would like to use as a background image for this menu item.'),
    );
    $form['icon']['icon_upload'] = array(
      '#type' => 'file',
      '#title' => t('Upload a new icon image'),
      '#maxlength' => 40,
      '#description' => t("If you don't have direct file access to the server, use this field to upload your icon."),
    );
    $form['submit']['#weight'] = 9;
    $form['delete']['#weight'] = 10;
    $form['#attributes']['enctype'] = 'multipart/form-data';
    $form['#submit'][] = 'menu_icons_form_submit';
  }

  // Add a custom submit callback for imagecache forms.
  if (in_array($form_id, array(
    'imagecache_ui_preset_form',
    'imagecache_ui_action_form',
    'imagecache_ui_preset_flush_form',
    'imagecache_ui_preset_delete_form',
    'menu_icons_admin_settings',
  ))) {
    $form['#submit'][] = 'menu_icons_css_generate';
  }
}