1 system.menu.inc system_menu_block_form($config)

Returns the configuration form for a menu tree.

Parameters

$config: An associated array of settings passed in by hook_block_configure(). If none are given, default configuration is assumed.

Return value

The form array. This is a form fragment and not in full Form API format.:

File

core/modules/system/system.menu.inc, line 52
Menu block configuration form and display.

Code

function system_menu_block_form($config) {
  $form['menu_name'] = array(
    '#type' => 'value',
    '#value' => $config['menu_name'],
  );

  $form['style'] = array(
    '#type' => 'select',
    '#title' => t('Menu style'),
    '#options' => array(
      'top_only' => t('Top level only'),
      'dropdown' => t('Dropdown menu'),
      'tree' => t('Hierarchical tree'),
    ),
    '#default_value' => empty($config['style']) ? 'tree' : $config['style'],
  );

  $form['level'] = array(
    '#type' => 'select',
    '#title' => t('Starting level'),
    '#default_value' => $config['level'],
    '#options' => array(
      '1' => t('1st level (primary)'),
      '2' => t('2nd level (secondary)'),
      '3' => t('3rd level (tertiary)'),
      '4' => t('4th level'),
      '5' => t('5th level'),
      '6' => t('6th level'),
      '7' => t('7th level'),
      '8' => t('8th level'),
      '9' => t('9th level'),
    ),
    '#description' => t('The block will be visible only if the current page has its menu item at or below the level set here.'),
    '#states' => array(
      'visible' => array(
        'select[name="block_settings[style]"]' => array('value' => 'tree'),
      ),
    ),
  );
  $form['depth'] = array(
    '#type' => 'select',
    '#title' => t('Maximum depth'),
    '#default_value' => $config['depth'],
    '#options' => array(
      '1' => '1',
      '2' => '2',
      '3' => '3',
      '4' => '4',
      '5' => '5',
      '6' => '6',
      '7' => '7',
      '8' => '8',
      '9' => '9',
      '0' => t('Unlimited'),
    ),
    '#description' => t('The maximum depth of the menu tree from the starting level (if available).'),
    '#states' => array(
      'invisible' => array(
        'select[name="block_settings[style]"]' => array('value' => 'top_only'),
      ),
    ),
  );
  $form['expand_all'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show all menu links'),
    '#default_value' => $config['expand_all'],
    '#description' => t('When unchecked, only expanded or active trail menu links will be displayed.'),
    '#states' => array(
      'visible' => array(
        'select[name="block_settings[style]"]' => array('value' => 'tree'),
      ),
    ),
  );
  $form['clickdown'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use a click to open, instead of a hover'),
    '#default_value' => $config['clickdown'],
    '#description' => t('Menus that don\'t appear or disappear on hover can be better for usability in some cases.'),
    '#states' => array(
      'visible' => array(
        'select[name="block_settings[style]"]' => array('value' => 'dropdown'),
      ),
    ),
  );
  $link = t('menu settings');
  if (user_access('administer menu')) {
    $link = l($link, 'admin/structure/menu/settings', array(
      'attributes' => array('target' => '_blank'),
    ));
  }
  $form['toggle'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display menu toggle button on small screens'),
    '#default_value' => $config['toggle'],
    '#description' => t('On devices with small screens, this option reduces the menu to a toggle button, commonly known as <a href="https://en.wikipedia.org/wiki/Hamburger_button" target="_blank"><em>hamburger button</em></a>. Clicking the icon reveals or hides the menu, saving screen space. The breakpoint for small screens can be configured in the global !menu_settings.', array(
      '!menu_settings' => $link,
    )),
  );
  $toggle_text_default = system_menu_block_defaults($config['menu_name'])['toggle_text'];
  $form['toggle_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Toggle button text'),
    '#default_value' => $config['toggle_text'],
    '#description' => t('Text to display beside the toggle button. Default: %toggle_text.', array(
      '%toggle_text' => $toggle_text_default,
    )),
    '#indentation' => 1,
    '#states' => array(
      'visible' => array(
        'input[name="block_settings[toggle]"]' => array('checked' => TRUE),
      ),
    ),
  );
  $form['collapse'] = array(
    '#type' => 'radios',
    '#title' => t('Collapsible behavior'),
    '#default_value' => (!empty($config['collapse'])) ? $config['collapse'] : 'default',
    '#options' => array(
      'default' => t('Default'),
      'toggle' => t('Toggle'),
      'link' => t('Link'),
    ),
    '#description' => t('Determines how parent menu items behave when the menu is shown on small screens.'),
    '#states' => array(
      'visible' => array(
        'select[name="block_settings[style]"]' => array('value' => 'dropdown'),
      ),
    ),
  );
  $form['collapse']['default']['#description'] = t('Parent expands on first tap, acts as a link on second tap.');
  $form['collapse']['toggle']['#description'] = t('Parent expands or collapses on each tap and does not act as a link.');
  $form['collapse']['link']['#description'] = t('Parent text acts as a link and the +/- element expands or collapses.');

  $form['accordion'] = array('#type' => 'checkbox',
    '#title' => t('Accordion-style'),
    '#default_value' => (!empty($config['accordion'])) ? $config['accordion'] : FALSE,
    '#description' => t('Close all sub-menus when closing parent menu items.'),
    '#states' => array(
      'visible' => array(
        'select[name="block_settings[style]"]' => array('value' => 'dropdown'),
      ),
    ),
  );

  return $form;
}