You are here

function menu_block_configure_form in Menu Block 6.2

Same name and namespace in other branches
  1. 7.3 menu_block.admin.inc \menu_block_configure_form()
  2. 7.2 menu_block.admin.inc \menu_block_configure_form()

Returns the configuration form for a menu tree.

Parameters

$form_state: array An associated array of configuration options should be present in the 'values' key. If none are given, default configuration is assumed.

Return value

array The form in Form API format.

2 calls to menu_block_configure_form()
menu_block_menu_tree_content_type_edit_form in plugins/content_types/menu_tree/menu_tree.inc
'Edit form' callback for the content type.
_menu_block_block_configure in ./menu_block.admin.inc
Returns the 'configure' $op info for hook_block().

File

./menu_block.admin.inc, line 182
Provides infrequently used functions for menu_block.

Code

function menu_block_configure_form(&$form_state) {
  $config = array();

  // Get the config from the form state.
  if (!empty($form_state['values'])) {
    $config = $form_state['values'];
    if (!empty($config['parent'])) {
      list($config['menu_name'], $config['parent_mlid']) = explode(':', $config['parent']);
    }
  }

  // Merge in the default configuration.
  $config += menu_block_get_config();

  // Don't display the config form if this delta is exported to code.
  if (!empty($config['exported_to_code'])) {
    $form['exported_message'] = array(
      '#markup' => '<p><em>' . t('Configuration is being provided by code.') . '</em></p>',
    );
    return $form;
  }

  // Build the standard form.
  drupal_add_js(drupal_get_path('module', 'menu_block') . '/menu-block.js');
  drupal_add_css(drupal_get_path('module', 'menu_block') . '/menu-block-admin.css');
  $form['menu-block-wrapper-start'] = array(
    '#value' => '<div id="menu-block-settings" class="menu-block-configure-form">',
  );
  $form['title_link'] = array(
    '#prefix' => '<div class="menu-block-title-link">',
    '#type' => 'checkbox',
    '#title' => t('Block title as link'),
    '#default_value' => $config['title_link'],
    '#description' => t('Make the default block title a link to that menu item. An overridden block title will not be a link.'),
    '#suffix' => '</div>',
  );
  $form['admin_title'] = array(
    '#type' => 'textfield',
    '#default_value' => $config['admin_title'],
    '#title' => t('Administrative title'),
    '#description' => t('This title will be used administratively to identify this block. If blank, the regular title will be used.'),
  );
  $menus = menu_block_get_all_menus();
  $form['menu_name'] = array(
    '#type' => 'select',
    '#title' => t('Menu'),
    '#default_value' => $config['menu_name'],
    '#options' => $menus,
    '#description' => t('The preferred menus used by <em>&lt;the menu selected by the page&gt;</em> can be customized on the <a href="!url">Menu block settings page</a>.', array(
      '!url' => url('admin/settings/menu_block'),
    )),
    '#attributes' => array(
      'class' => 'menu-block-menu-name',
    ),
  );
  $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('Blocks that start with the 1st level will always be visible. Blocks that start with the 2nd level or deeper will only be visible when the trail to the active menu item is in the block’s tree.'),
  );

  // The value of "follow" in the database/config array is either FALSE or the
  // value of the "follow_parent" form element.
  if ($follow = $config['follow']) {
    $follow_parent = $follow;
    $follow = 1;
  }
  else {
    $follow_parent = 'active';
  }
  $form['follow'] = array(
    '#type' => 'checkbox',
    '#title' => t('Make the starting level follow the active menu item.'),
    '#default_value' => $follow,
    '#description' => t('If the active menu item is deeper than the level specified above, the starting level will follow the active menu item. Otherwise, the starting level of the tree will remain fixed.'),
    '#element_validate' => array(
      'menu_block_configure_form_follow_validate',
    ),
    '#attributes' => array(
      'class' => 'menu-block-follow',
    ),
  );
  $form['follow_parent'] = array(
    '#prefix' => '<div class="menu-block-follow-parent">',
    '#type' => 'select',
    '#title' => t('Starting level will be'),
    '#default_value' => $follow_parent,
    '#options' => array(
      'active' => t('Active menu item'),
      'child' => t('Children of active menu item'),
    ),
    '#description' => t('When following the active menu item, specify if the starting level should be the active menu item or its children.'),
    '#suffix' => '</div>',
  );
  $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('From the starting level, specify the maximum depth of the menu tree.'),
  );
  $form['expanded'] = array(
    '#type' => 'checkbox',
    '#title' => t('<strong>Expand all children</strong> of this tree.'),
    '#default_value' => $config['expanded'],
  );
  $form['sort'] = array(
    '#type' => 'checkbox',
    '#title' => t('<strong>Sort</strong> menu tree by the active menu item’s trail.'),
    '#default_value' => $config['sort'],
    '#description' => t('Sort each item in the active trail to the top of its level. When used on a deep or wide menu tree, the active menu item’s children will be easier to see when the page is reloaded.'),
  );
  $form['parent_mlid'] = array(
    '#type' => 'select',
    '#title' => t('Fixed parent item'),
    '#default_value' => $config['menu_name'] . ':' . $config['parent_mlid'],
    '#options' => menu_parent_options($menus, array(
      'mlid' => 0,
    )),
    '#description' => t('Alter the “starting level” and “maximum depth” options to be relative to the fixed parent item. The tree of links will only contain children of the selected menu item.'),
    '#attributes' => array(
      'class' => 'menu-block-parent-mlid',
    ),
    '#element_validate' => array(
      'menu_block_configure_form_parent_validate',
    ),
  );
  $form['parent_mlid']['#options'][MENU_TREE__CURRENT_PAGE_MENU . ':0'] = '<' . t('the menu selected by the page') . '>';
  $form['menu-block-wrapper-close'] = array(
    '#value' => '</div>',
  );
  return $form;
}