function _menu_views_get_item in Menu Views 7.2
Same name and namespace in other branches
- 8.3 menu_views.module \_menu_views_get_item()
Helper function to return the menu view array from a menu item array or form array.
14 calls to _menu_views_get_item()
- menu_views_form_menu_overview_form_alter in ./
menu_views.admin.inc - Implements hook_form_FORM_ID_alter().
- menu_views_menu_breadcrumb_alter in ./
menu_views.module - Implements hook_menu_breadcrumb_alter().
- menu_views_menu_link in ./
menu_views.module - Implements theme_menu_link(). Overrides default theming function to intercept views.
- menu_views_menu_link_alter in ./
menu_views.module - menu_views_node_presave in ./
menu_views.module - Implements hook_node_presave().
File
- ./
menu_views.module, line 283 - Module to allow Views to be attached as menu items.
Code
function _menu_views_get_item(array &$element = array(), array &$form_state = array()) {
// Default values.
$item = $default = _menu_views_default_values();
// Remove the type of menu item, will get set afterwards.
unset($item['type']);
$provided = FALSE;
$ajax_type = FALSE;
// If $form_state is empty, this is a menu item.
if (empty($form_state)) {
if (isset($element['menu_views'])) {
$provided =& $element['menu_views'];
}
elseif (isset($element['localized_options']['menu_views'])) {
$provided =& $element['localized_options']['menu_views'];
}
elseif (isset($element['#localized_options']['menu_views'])) {
$provided =& $element['#localized_options']['menu_views'];
}
elseif (isset($element['options']['menu_views'])) {
$provided =& $element['options']['menu_views'];
}
}
else {
$original_element = $element;
$values =& $form_state['values'];
// Determine if this is a node form.
if (isset($element['#node'])) {
$element =& $element['menu']['link'];
$values =& $values['menu'];
}
// Save the menu item type before proceeding.
if (isset($values['menu_item_type'])) {
$ajax_type = $values['menu_item_type'];
}
elseif (isset($values['menu']['menu_views']['menu_item_type'])) {
$ajax_type = $values['menu']['menu_views']['menu_item_type'];
}
// Save the menu item provided for initial form population.
if (isset($element['original_item']['#value']['options']['menu_views'])) {
$provided =& $element['original_item']['#value']['options']['menu_views'];
if (isset($provided['type'])) {
$item['type'] = $provided['type'];
}
}
elseif (isset($original_element['#node']->menu['options']['menu_views'])) {
$provided =& $original_element['#node']->menu['options']['menu_views'];
if (isset($provided['type'])) {
$item['type'] = $provided['type'];
}
}
// Determine if the options has a tree value.
if (_menu_views_options_tree($original_element)) {
$element =& $element['options'];
$values =& $values['options'];
}
if (!$provided && isset($element['menu_views'])) {
if (isset($element['menu_views']['#value'])) {
$provided = $element['menu_views']['#value'];
}
elseif (isset($element['menu_views'])) {
$provided = $element['menu_views'];
}
}
// Allow submitted values to override form values.
if (isset($values['menu_views'])) {
$provided = $values['menu_views'];
}
if (isset($provided['type']) && isset($item['type'])) {
$provided['type'] = $item['type'];
}
}
// If the menu view element were not set, attempt to determine if this is a form.
// By default, the menu view returns default values (no view). If settings were provided by an element or form item, then use those.
if ($provided) {
// Extract available element settings to use for this menu view.
foreach (array(
'mlid',
'original_path',
'view',
) as $property) {
if (isset($provided[$property])) {
if (isset($item[$property]) && is_array($item[$property])) {
$item[$property] = _menu_views_array_merge_recursive($item[$property], $provided[$property]);
}
else {
$item[$property] = $provided[$property];
}
}
}
}
// Set the type of menu item.
if ($ajax_type) {
$item['type'] = $ajax_type;
}
elseif (isset($provided['type'])) {
$item['type'] = $provided['type'];
}
else {
$item['type'] = $default['type'];
}
// Filter out any disabled views.
$views = array_keys(views_get_enabled_views());
if (!in_array($item['view']['name'], $views)) {
$item['view'] = $default['view'];
}
return $item;
}