function _menu_views_form in Menu Views 7.2
Same name and namespace in other branches
- 8.3 menu_views.admin.inc \_menu_views_form()
Adds Menu Views settings to an existing form.
Parameters
$item: The menu views item array passed by reference. @see _menu_views_get_item()
$element: The top level menu item edit form element passed by reference.
$form: The complete form array passed by reference.
$form_state: The complete form state array passed by reference.
1 call to _menu_views_form()
- _menu_views_form_alter in ./
menu_views.admin.inc - Alters existing forms in preparation for adding Menu Views to it.
File
- ./
menu_views.admin.inc, line 362 - Form hooks for the menu_views module.
Code
function _menu_views_form(&$item, &$element, &$form, &$form_state) {
$element['mlid'] = array(
'#type' => 'value',
'#value' => $item['mlid'],
);
$element['type'] = array(
'#type' => 'value',
'#value' => $item['type'],
);
$element['original_path'] = array(
'#type' => 'value',
'#value' => $item['original_path'],
);
// Container for the actual view settings.
$element['view'] = array(
'#type' => 'container',
'#access' => $item['type'] == 'view' ? TRUE : FALSE,
);
$view_options = array();
$display_options = array();
foreach (views_get_enabled_views() as $view_name => $view) {
$view_options[$view_name] = $view->human_name . ' (' . $view_name . ')';
foreach ($view->display as $display_name => $display) {
if ('default' !== $display_name && 'page' !== $display_name && 'rss' !== $display_name) {
$display_options[$view_name][$display_name] = $display->display_title . ' (' . $display_name . ')';
}
}
// If view has no compatiable displays, remove the view as an option.
if (empty($display_options[$view_name])) {
unset($view_options[$view_name]);
}
else {
// Sort the displays for the view.
ksort($display_options[$view_name]);
}
}
ksort($view_options);
$element['view']['container'] = array(
'#type' => 'fieldset',
'#title' => t('View'),
'#parents' => _menu_views_form_parents($form),
);
$element['view']['container']['name'] = array(
'#type' => 'select',
'#title' => t('Name'),
'#empty_option' => t('- Select View -'),
'#description' => t('Select the name of a view to use. The following view displays cannot be used: Master (default), Page and RSS. If the view or display you are looking for does not exist, create a block display in that view.'),
'#required' => TRUE,
'#default_value' => $item['view']['name'],
'#options' => $view_options,
'#ajax' => array(
'callback' => '_menu_views_form_ajax',
'wrapper' => 'menu-edit-item-wrapper',
),
);
if ($item['view']['name'] && !empty($display_options[$item['view']['name']])) {
$element['view']['container']['display'] = array(
'#type' => 'select',
'#title' => t('Display'),
'#description' => t('Select the name of a view display to use. The following view displays cannot be used: Master (default), Page and RSS. If the view or display you are looking for does not exist, create a block display in that view.'),
'#required' => TRUE,
'#empty_option' => t('- Select Display -'),
'#default_value' => $item['view']['display'],
'#options' => $display_options[$item['view']['name']],
'#ajax' => array(
'callback' => '_menu_views_form_ajax',
'wrapper' => 'menu-edit-item-wrapper',
),
);
if ($item['view']['display']) {
$element['view']['container']['arguments'] = array(
'#type' => 'textfield',
'#title' => t('Arguments'),
'#description' => t('You can reference the node associated with this menu link by using <code>[menu-link:node:nid]</code>.<br />You can reference the node associated with the parent of this menu link by using <code>[menu-link:parent:node:nid]</code>.'),
'#default_value' => $item['view']['arguments'],
);
_menu_views_form_tokens_ui($element['view']['container']);
// Advanced Settings.
$element['view']['settings'] = array(
'#type' => 'container',
);
$parents = _menu_views_form_parents($form);
$parents[] = 'settings';
$parents_name = $parents;
$parents_name_first = array_shift($parents_name);
$parents_name = $parents_name_first . '[' . implode('][', $parents_name);
$settings =& $element['view']['settings'];
// Wrapper Class
$settings['wrapper_classes'] = array(
'#type' => 'fieldset',
'#title' => t('Wrapper Classes'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#parents' => $parents,
);
$settings['wrapper_classes']['wrapper_classes'] = array(
'#type' => 'textfield',
'#description' => t('Provide any additional classes, separated by spaces.'),
'#default_value' => $item['view']['settings']['wrapper_classes'],
);
// View Title
$settings['title'] = array(
'#type' => 'fieldset',
'#title' => t('View Title'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#parents' => $parents,
);
$settings['title']['title'] = array(
'#type' => 'checkbox',
'#title' => t('Show view title'),
'#default_value' => $item['view']['settings']['title'],
);
$settings['title']['title_settings'] = array(
'#type' => 'container',
'#parents' => $parents,
'#states' => array(
'visible' => array(
':input[name="' . $parents_name . '][title]"]' => array(
'checked' => TRUE,
),
),
),
);
$title =& $settings['title']['title_settings'];
$title['title_wrapper'] = array(
'#type' => 'select',
'#title' => t('Element Wrapper'),
'#description' => t('Choose which element wrapper to use around the title of the view. Default: H3'),
'#default_value' => $item['view']['settings']['title_wrapper'],
'#options' => variable_get('views_field_rewrite_elements', array(
'' => t('- Use default -'),
'0' => t('- None -'),
'div' => 'DIV',
'span' => 'SPAN',
'h1' => 'H1',
'h2' => 'H2',
'h3' => 'H3',
'h4' => 'H4',
'h5' => 'H5',
'h6' => 'H6',
'p' => 'P',
'strong' => 'STRONG',
'em' => 'EM',
)),
);
$title['title_classes'] = array(
'#type' => 'textfield',
'#title' => t('Classes'),
'#description' => t('Provide any additional classes, separated by spaces. Title must use the element wrapper above for this take effect.'),
'#default_value' => $item['view']['settings']['title_classes'],
);
$title['title_override'] = array(
'#type' => 'textfield',
'#title' => t('Override Title'),
'#description' => t('Enter custom text to override title output. Default: Title will be provided from the view.'),
'#default_value' => $item['view']['settings']['title_override'],
);
_menu_views_form_tokens_ui($title);
// Breadcrumb
$settings['breadcrumb'] = array(
'#type' => 'fieldset',
'#title' => t('Breadcrumb'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#parents' => $parents,
);
$settings['breadcrumb']['breadcrumb'] = array(
'#type' => 'checkbox',
'#title' => t('Show breadcrumb link'),
'#default_value' => $item['view']['settings']['breadcrumb'],
);
$settings['breadcrumb']['breadcrumb_settings'] = array(
'#type' => 'container',
'#parents' => $parents,
'#states' => array(
'visible' => array(
':input[name="' . $parents_name . '][breadcrumb]"]' => array(
'checked' => TRUE,
),
),
),
);
$breadcrumb =& $settings['breadcrumb']['breadcrumb_settings'];
$breadcrumb['breadcrumb_title'] = array(
'#type' => 'textfield',
'#title' => t('Link Title'),
'#description' => t('Title to use for the breadcrumb link. Note: If there is not a title provided by the view then the breadcrumb will not be displayed. Default: View Title'),
'#default_value' => $item['view']['settings']['breadcrumb_title'],
);
_menu_views_form_tokens_ui($breadcrumb);
$breadcrumb['breadcrumb_path'] = array(
'#type' => 'textfield',
'#title' => t('Link Path'),
'#description' => t('Path to use for the breadcrumb link. Default: %front.', array(
'%front' => '<front>',
)),
'#default_value' => $item['view']['settings']['breadcrumb_path'],
);
_menu_views_form_tokens_ui($breadcrumb);
}
}
}