function menu_icons_form_alter in Menu Icons 7.3
Same name and namespace in other branches
- 8 menu_icons.module \menu_icons_form_alter()
- 6.2 menu_icons.module \menu_icons_form_alter()
- 6 menu_icons.module \menu_icons_form_alter()
Implements hook_form_alter().
File
- ./
menu_icons.module, line 42 - Module to associate icons with menu items
Code
function menu_icons_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'menu_edit_item') {
if (isset($form['mlid']['#value'])) {
$options = unserialize(db_query('SELECT options FROM {menu_links} WHERE mlid = :mlid', array(
':mlid' => $form['mlid']['#value'],
))
->fetchField());
}
if (!isset($options) || !isset($options['menu_icon'])) {
$options = array(
'menu_icon' => array(
'enable' => NULL,
'image_style' => NULL,
),
);
}
$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(
'classes' => array(
'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.'),
);
$form['icon']['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#options' => image_style_options(FALSE),
'#empty_option' => '<' . t('Menu Icons default') . '>',
'#default_value' => $options['menu_icon']['image_style'],
'#description' => t('The preview image will be shown while editing the content.'),
'#required' => FALSE,
);
$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_path']['#states'] = array(
'visible' => array(
':input[name="use_icon_logo"]' => array(
'checked' => TRUE,
),
),
);
$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['icon']['icon_upload']['#states'] = array(
'visible' => array(
':input[name="use_icon_logo"]' => array(
'checked' => TRUE,
),
),
);
$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 image style forms.
if (in_array($form_id, array(
'image_style_form',
'image_effect_form',
'image_style_revert_form',
'image_style_delete_form',
'menu_icons_admin_settings',
))) {
$form['#submit'][] = 'menu_icons_css_generate';
}
}