function menu_block_configure_form in Menu Block 7.2
Same name and namespace in other branches
- 6.2 menu_block.admin.inc \menu_block_configure_form()
- 7.3 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 - Implements hook_block_configure().
File
- ./
menu_block.admin.inc, line 225 - Provides infrequently used functions and hooks for menu_block.
Code
function menu_block_configure_form($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_default_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.
$form['#attached']['js'][] = drupal_get_path('module', 'menu_block') . '/js/menu-block.js';
$form['#attached']['css'][] = drupal_get_path('module', 'menu_block') . '/css/menu-block.admin.css';
$form['#attached']['library'][] = array(
'system',
'ui.button',
);
$form['menu-block-wrapper-start'] = array(
'#markup' => '<div id="menu-block-settings">',
'#weight' => -30,
);
$form['display_options'] = array(
'#type' => 'radios',
'#title' => t('Display'),
'#default_value' => 'basic',
'#options' => array(
'basic' => t('Basic options'),
'advanced' => t('Advanced options'),
),
'#attributes' => array(
'class' => array(
'clearfix',
),
),
'#weight' => -29,
);
$form['title_link'] = array(
'#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.'),
'#states' => array(
'visible' => array(
':input[name=title]' => array(
'value' => '',
),
),
),
);
// We need a different state if the form is in a Panel overlay.
if (isset($form['override_title'])) {
$form['title_link']['#states'] = array(
'visible' => array(
':input[name=override_title]' => array(
'checked' => FALSE,
),
),
);
}
$form['display_empty'] = array(
'#type' => 'checkbox',
'#title' => t('Always display title'),
'#description' => t('Display the block with its title even if the block content is empty.'),
'#default_value' => $config['display_empty'],
);
$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><the menu selected by the page></em> can be customized on the <a href="!url">Menu block settings page</a>.', array(
'!url' => url('admin/config/user-interface/menu-block'),
)),
'#attributes' => array(
'class' => array(
'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 passes though the block’s starting level.'),
);
// 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',
),
);
$form['follow_parent'] = array(
'#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.'),
'#states' => array(
'visible' => array(
':input[name=follow]' => array(
'checked' => TRUE,
),
),
),
);
$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['depth_relative'] = array(
'#type' => 'checkbox',
'#title' => t('Make the maximum depth relative to the starting level while following the active menu item.'),
'#default_value' => $config['depth_relative'],
'#states' => array(
'visible' => array(
':input[name=follow]' => array(
'checked' => TRUE,
),
':input[name=depth]' => array(
'!value' => '0',
),
),
),
);
$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'] = 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' => array(
'menu-block-parent-mlid',
),
),
'#element_validate' => array(
'menu_block_configure_form_parent_validate',
),
);
$form['parent']['#options'][MENU_TREE__CURRENT_PAGE_MENU . ':0'] = '<' . t('the menu selected by the page') . '>';
$form['menu-block-wrapper-close'] = array(
'#markup' => '</div>',
);
// Set visibility of advanced options.
foreach (array(
'title_link',
'display_empty',
'follow',
'depth_relative',
'follow_parent',
'expanded',
'sort',
'parent',
) as $key) {
$form[$key]['#states']['visible'][':input[name=display_options]'] = array(
'value' => 'advanced',
);
}
// depth_relative and follow_parent aren't listed below because they require
// $follow to be true.
if ($config['title_link'] || $config['display_empty'] || $follow || $config['expanded'] || $config['sort'] || $config['parent_mlid']) {
$form['display_options']['#default_value'] = 'advanced';
}
return $form;
}