Commit f3e501b5 authored by Colan Schwartz's avatar Colan Schwartz

Revert "Issue #835090 by Karsa, Deciphered, nedjo, fearlsgroove, Dane Powell,...

Revert "Issue #835090 by Karsa, Deciphered, nedjo, fearlsgroove, Dane Powell, Angry Dan, mgifford, Jibus, Bußmeyer, tomb, c4rl | rjacobs: Set context reaction menu trail."

This reverts commit c6d2bd7d.
It's causing several other problems: #2358313 & #2374445.
Once there's a patch solving these, we'll add this back in.
parent 4eab91e5
......@@ -334,6 +334,9 @@ function context_context_page_condition() {
* Implementation of hook_context_page_reaction().
*/
function context_context_page_reaction() {
if ($plugin = context_get_plugin('reaction', 'breadcrumb')) {
$plugin->execute();
}
if ($plugin = context_get_plugin('reaction', 'css_injector')) {
$plugin->execute();
}
......@@ -346,6 +349,9 @@ function context_context_page_reaction() {
* Implementation of hook_preprocess_page().
*/
function context_preprocess_page(&$vars) {
if ($plugin = context_get_plugin('reaction', 'menu')) {
$plugin->execute($vars);
}
if ($plugin = context_get_plugin('reaction', 'theme')) {
$plugin->execute($vars);
}
......@@ -362,19 +368,6 @@ function context_preprocess_page(&$vars) {
*/
}
/**
* Implementation of hook_delivery_callback_alter().
* Based on menu_position's and menu_trail_by_path's implementations.
*/
function context_page_delivery_callback_alter() {
if ($plugin = context_get_plugin('reaction', 'menu')) {
$plugin->execute();
}
if ($plugin = context_get_plugin('reaction', 'breadcrumb')) {
$plugin->execute();
}
}
/**
* Implementation of hook_preprocess_html().
*/
......
......@@ -5,29 +5,34 @@
*/
class context_reaction_breadcrumb extends context_reaction_menu {
/**
* Overrides set_active_trail_from_link to set the breadcrumb instead of the menu path.
* Override of execute().
*/
function set_active_trail_from_link($item) {
$result = db_select('menu_links')
->fields('menu_links', array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8'))
->condition('hidden', 0)
->condition('link_path', $item['link_path'])
->execute();
while ($parents = $result->fetchAssoc()) {
$set = FALSE;
foreach (array_filter($parents) as $plid) {
$parent = menu_link_load($plid);
if ($parent && $parent['access'] && empty($parent['hidden']) && !empty($parent['title'])) {
$set = TRUE;
$breadcrumb[] = l($parent['title'], $parent['href']);
function execute(&$vars = NULL) {
if ($active_paths = $this->get_active_paths()) {
$breadcrumb = array(l(t('Home'), '<front>', array('purl' => array('disabled' => TRUE))));
foreach ($active_paths as $path) {
$result = db_select('menu_links')
->fields('menu_links', array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8'))
->condition('hidden', 0)
->condition('link_path', $path)
->execute();
while ($parents = $result->fetchAssoc()) {
$set = FALSE;
foreach (array_filter($parents) as $plid) {
$parent = menu_link_load($plid);
if ($parent && $parent['access'] && empty($parent['hidden']) && !empty($parent['title'])) {
$set = TRUE;
$breadcrumb[] = l($this->get_link_title($parent), $parent['href']);
}
}
// Only set the breadcrumb if one or more links were added to the
// trail. If not, continue iterating through possible menu links.
if ($set) {
drupal_set_breadcrumb($breadcrumb);
break;
}
}
}
// Only set the breadcrumb if one or more links were added to the
// trail. If not, continue iterating through possible menu links.
if ($set) {
drupal_set_breadcrumb($breadcrumb);
break;
}
}
}
/**
......
......@@ -8,33 +8,35 @@ class context_reaction_menu extends context_reaction {
* Provide a form element that allow the admin to chose a menu item.
*/
function options_form($context) {
$options = array("-- " . t('None') . " --");
if (module_exists('menu')) {
$menus = menu_parent_options(menu_get_menus(), array('mlid' => 0));
$menu_names = array();
foreach ($menus as $id => $title) {
list($menu_name, $mlid) = explode(':', $id);
// Store the title each menu for reference.
if ($mlid == '0') {
$menu_names[$menu_name] = check_plain($title);
$root_menus = array();
foreach ($menus as $key => $name) {
$id = explode(':', $key);
if ($id[1] == '0') {
$root_menus[$id[0]] = check_plain($name);
}
else {
$link = menu_link_load($mlid);
$link = menu_link_load($id[1]);
$identifier = $link['link_path'];
$root_menu = $menu_names[$menu_name];
while (isset($options[$root_menu][$identifier])) {
$root_menu = $root_menus[$id[0]];
while (isset($menus[$root_menu][$identifier])) {
$identifier .= "'";
}
$options[$root_menu][$menu_name . ':' . $identifier] = $title;
$menus[$root_menu][$identifier] = $name;
}
unset($menus[$key]);
}
array_unshift($menus, "-- " . t('None') . " --");
}
else {
$menus = array();
}
return array(
'#title' => $this->title,
'#description' => $this->description,
'#options' => $options,
'#options' => $menus,
'#type' => 'select',
'#multiple' => TRUE,
'#default_value' => $this->fetch_from_context($context),
);
}
......@@ -44,100 +46,97 @@ class context_reaction_menu extends context_reaction {
* Trim any identifier padding for non-unique path menu items.
*/
function options_form_submit($values) {
$trimmed = array();
foreach ($values as $value) {
$value = trim($value, "'");
$trimmed[] = $value;
}
return $trimmed;
return trim($values, "'");
}
/**
* Overrides parent function to include legacy handling for old format of just storing a single path.
* If primary + secondary links are pointed at the same menu, provide
* contextual trailing by default.
*/
function fetch_from_context($context) {
$values = parent::fetch_from_context($context);
// Legacy - convert single string value to an array with a preferred menu
if (is_string($values)) {
$menu = menu_link_get_preferred($values);
if (!$menu) {
return array();
function execute(&$vars = NULL) {
if (variable_get('menu_main_links_source', 'main-menu') == variable_get('menu_secondary_links_source', 'user-menu')) {
$vars['main_menu'] = theme_get_setting('toggle_main_menu') ? $this->menu_navigation_links(variable_get('menu_main_links_source', 'main-menu')) : $vars['main_menu'];
$vars['secondary_menu'] = theme_get_setting('toggle_secondary_menu') ? $this->menu_navigation_links(variable_get('menu_secondary_links_source', 'secondary-links'), 1) : $vars['secondary_menu'];
}
$vars['main_menu'] = $this->menu_set_active($vars['main_menu']);
$vars['secondary_menu'] = $this->menu_set_active($vars['secondary_menu']);
}
function get_active_paths() {
$active_paths = array();
foreach ($this->get_contexts() as $context) {
if (isset($context->reactions[$this->plugin])) {
$active_paths[] = $context->reactions[$this->plugin];
}
return array($menu['menu_name'] . ':' . $menu['link_path']);
}
return $values;
return $active_paths;
}
/**
* Provide active trail in all menus in which our path appears.
* Iterates through a provided links array for use with theme_links()
* (e.g. from menu_primary_links()) and provides an active class for
* any items that have a path that matches an active context.
*
* @param $links
* An array of links.
* @param $reset
* A boolean flag for resetting the static cache.
*
* @return
* A modified links array.
*/
function execute(&$vars = NULL) {
$menu_names = menu_get_active_menu_names();
$active_paths = $this->get_active_paths();
foreach ($menu_names as $menu_name) {
if (isset($active_paths[$menu_name])) {
foreach($active_paths[$menu_name] as $path) {
if ($link = menu_link_get_preferred($path, $menu_name)) {
$this->set_active_trail_from_link($link);
return;
function menu_set_active($links = array(), $reset = FALSE) {
$new_links = array();
if (!empty($links)) {
$active_paths = $this->get_active_paths();
// Iterate through the provided links and build a new set of links
// that includes active classes
foreach ($links as $key => $link) {
if (!empty($link['href']) && in_array($link['href'], $active_paths)) {
$link['attributes']['class'][] = 'active';
if (strpos(' active', $key) === FALSE) {
$new_links[$key . ' active'] = $link;
}
}
}
}
// None of the links can be found in their preferred menus. Instead we just try to find any of the paths in any
// menu. Note that the preferred menu names list is still used but not always honoured.
// We hope to not have to fall into this section as we could end up doing rather a lot of lookups.
foreach ($active_paths as $menu_name => $paths) {
foreach($paths as $path) {
if ($link = menu_link_get_preferred($path)) {
$this->set_active_trail_from_link($link);
return;
else {
$new_links[$key] = $link;
}
}
}
return $new_links;
}
/**
* Helper function to build and set the active trail from a menu link.
*
* @param $item
* A menu link item.
* Wrapper around menu_navigation_links() that gives themers the option of
* building navigation links based on an active context trail.
*/
function set_active_trail_from_link($item) {
menu_tree_set_path($item['menu_name'], $item['link_path']);
$trail = array();
while($item) {
array_unshift($trail, $item);
$item = menu_link_load($item['plid']);
}
array_unshift($trail, array(
'title' => t('Home'),
'href' => '<front>',
'link_path' => '',
'localized_options' => array(),
'type' => 0,
));
menu_set_active_trail($trail);
}
function menu_navigation_links($menu_name, $level = 0) {
// Retrieve original path so we can repair it after our hack.
$original_path = $_GET['q'];
$original_menu_trail = drupal_static('menu_set_active_trail');
/**
* Helper function to return the list of currently active paths.
*
* The paths are grouped by menu name.
*/
function get_active_paths() {
$active_paths = array();
foreach ($this->get_contexts() as $context) {
$paths = $this->fetch_from_context($context);
$active_paths = array_merge($active_paths, $paths);
// Retrieve the first active menu path found.
if ($active_paths = $this->get_active_paths()) {
$path = current($active_paths);
if (menu_get_item($path)) {
menu_set_active_item($path);
}
}
$by_menu_name = array();
foreach ($active_paths as $id) {
list($menu_name, $path) = explode(':', $id);
$by_menu_name[$menu_name][] = $path;
// Build the links requested
if (module_exists('i18n_menu')) {
$links = i18n_menu_navigation_links($menu_name, $level);
} else {
$links = menu_navigation_links($menu_name, $level);
}
return $by_menu_name;
// Repair and get out
menu_set_active_item($original_path);
$repair_menu_trail = &drupal_static('menu_set_active_trail');
$repair_menu_trail = $original_menu_trail;
return $links;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment