You are here

function _icon_menu_form_alter in Icon API 7

Same name and namespace in other branches
  1. 8 modules/icon_menu/icon_menu.module \_icon_menu_form_alter()

Add the icon configuration to a menu item edit form.

Parameters

array $form: The menu item edit form passed by reference.

array $item: The optional existing menu item for context.

array $complete_form: The entire form from menu callback.

2 calls to _icon_menu_form_alter()
icon_menu_form_menu_edit_item_alter in modules/icon_menu/icon_menu.module
Implements hook_form_FORM_ID_alter().
icon_menu_form_node_form_alter in modules/icon_menu/icon_menu.module
Implements hook_form_FORM_ID_alter().

File

modules/icon_menu/icon_menu.module, line 123
icon_menu.module Implements an API for icon providers and an administrative UI for integrating icons through out the site.

Code

function _icon_menu_form_alter(array &$form, array $item = array(), array &$complete_form = array()) {
  $access = user_access('administer icons') || user_access('administer menu icons');
  $form['options']['#tree'] = TRUE;
  $form['options']['#weight'] = 50;

  // Unset the previous value so that the new values get saved.
  if (isset($form['options']['#value']['icon'])) {
    unset($form['options']['#value']['icon']);
  }

  // Determine proper parent names for states.
  $parents = 'options[icon]';
  if (isset($complete_form['menu']['link']) && isset($complete_form['#node']->menu)) {
    $parents = 'menu[options][icon]';
  }

  // Get the default values.
  $defaults = array_merge(icon_menu_defaults(), !empty($item['options']['icon']) ? $item['options']['icon'] : array());

  // Add an icon selector input element.
  $form['options']['icon'] = array(
    '#access' => $access,
    '#type' => 'icon_selector',
    '#default_bundle' => $defaults['bundle'],
    '#default_icon' => $defaults['icon'],
    '#default_wrapper' => $defaults['wrapper'],
    '#default_wrapper_class' => $defaults['wrapper_class'],
  );

  // Additional configuration on where to place the icon in the block.
  $icon_state = array(
    'invisible' => array(
      ':input[name="' . $parents . '[icon]"]' => array(
        'value' => '',
      ),
    ),
  );
  $form['options']['icon']['position'] = array(
    '#access' => $access,
    '#type' => 'select',
    '#title' => t('Position'),
    '#description' => t('Choose where to position the icon in the menu item.'),
    '#options' => array(
      'title_before' => t('Before title'),
      'title_after' => t('After title'),
      'title_invisible' => t('Invisible title'),
      'title_replace' => t('Replace title'),
    ),
    '#default_value' => $defaults['position'],
    '#states' => $icon_state,
  );
  $form['options']['icon']['breadcrumb'] = array(
    '#access' => $access,
    '#type' => 'checkbox',
    '#title' => t('Show in breadcrumbs'),
    '#description' => t('Choose whether to show the icon in breadcrumb links.'),
    '#default_value' => $defaults['breadcrumb'],
    '#states' => $icon_state,
  );
  $form['options']['icon']['title_wrapper'] = array(
    '#access' => $access,
    '#type' => 'checkbox',
    '#title' => t('Title Wrapper'),
    '#description' => t('Choose whether to wrap the title in a element tag or not.'),
    '#default_value' => $defaults['title_wrapper'],
    '#states' => $icon_state,
  );
  $wrap_state = array(
    'visible' => array(
      ':input[name="' . $parents . '[title_wrapper]"]' => array(
        'checked' => TRUE,
      ),
    ),
    'invisible' => array(
      ':input[name="' . $parents . '[icon]"]' => array(
        'value' => '',
      ),
    ),
  );
  $form['options']['icon']['title_wrapper_element'] = array(
    '#access' => $access,
    '#type' => 'select',
    '#title' => t('Title Wrapper Element'),
    '#description' => t('The type of element to use for the title wrapper.'),
    '#default_value' => $defaults['title_wrapper_element'],
    '#options' => drupal_map_assoc(array(
      'span',
      'div',
    )),
    '#states' => $wrap_state,
  );
  $form['options']['icon']['title_wrapper_class'] = array(
    '#access' => $access,
    '#type' => 'textfield',
    '#title' => t('Title Wrapper Class'),
    '#description' => t('The classes to apply to the title wrapper'),
    '#default_value' => $defaults['title_wrapper_class'],
    '#states' => $wrap_state,
  );
}