Skip to content

Commit

Permalink
Updating Context to 7.x-3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
mwanberg committed Dec 4, 2018
1 parent 699b0cb commit ac75a6f
Show file tree
Hide file tree
Showing 35 changed files with 727 additions and 332 deletions.
2 changes: 1 addition & 1 deletion sites/all/modules/contrib/context/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version. You will need the latest CTools (as of Sept. 16 2010) from here:
- all reactions
- context UI
- context layouts
- inline editor (with Admin 2.x for D7)
- inline editor (see the context_ui README file for info on enabling)

### Expect API changes

Expand Down
11 changes: 11 additions & 0 deletions sites/all/modules/contrib/context/context.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,14 @@ function hook_context_load_alter(&$context) {
);
}
}

/**
* Allows for finer grained access mechanisms to using the json
* rendering capabilities of the block reaction when a user isn't
* granted the administer contexts or context ajax block access
* permission
* @param $block_id
* ID of block in module-delta format
*/
function hook_context_allow_ajax_block_access($block_id) {
}
69 changes: 51 additions & 18 deletions sites/all/modules/contrib/context/context.core.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ function context_theme() {
'path' => drupal_get_path('module', 'context') . '/theme',
'file' => 'context_reaction_block.theme.inc',
);
$items['context_block_edit_wrap'] = array(
'render element' => 'element',
'path' => drupal_get_path('module', 'context') . '/theme',
'file' => 'context_reaction_block.theme.inc',
);
return $items;
}

Expand Down Expand Up @@ -89,11 +94,27 @@ function context_theme_registry_alter(&$theme_registry) {
*/
function context_ctools_render_alter($info, $page, $data) {
extract($data);
if ($page && in_array($task['name'], array('node_view', 'node_edit'), TRUE)) {
foreach ($contexts as $ctools_context) {
if (in_array('node', $ctools_context->type) && !empty($ctools_context->data)) {
context_node_condition($ctools_context->data, $task['name'] === 'node_view' ? 'view' : 'form');
break;

// Check for page handlers.
if ($page) {
// Check for node page handler.
if (in_array($task['name'], array('node_view', 'node_edit'), TRUE)) {
foreach ($contexts as $ctools_context) {
if (in_array('node', $ctools_context->type) && !empty($ctools_context->data)) {
context_node_condition($ctools_context->data, $task['name'] === 'node_view' ? 'view' : 'form');
break;
}
}
}
// Check for taxonomy term page handler.
elseif (in_array($task['name'], array('term_view', 'term_edit'), TRUE)) {
foreach ($contexts as $ctools_context) {
if (in_array('taxonomy_term', $ctools_context->type) && !empty($ctools_context->data)) {
if ($plugin = context_get_plugin('condition', 'taxonomy_term')) {
$plugin->execute($ctools_context->data, $task['name'] === 'term_view' ? 'view' : 'form');
}
break;
}
}
}
}
Expand All @@ -105,7 +126,8 @@ function context_ctools_render_alter($info, $page, $data) {
function context_entity_prepare_view($prepare, $entity_type) {
if ($entity_type === 'taxonomy_term' && count($prepare) === 1) {
$term = reset($prepare);
if ($term === menu_get_object('taxonomy_term', 2) && $plugin = context_get_plugin('condition', 'taxonomy_term')) {
$menu = menu_get_object('taxonomy_term', 2);
if ($menu && $term->tid == $menu->tid && $plugin = context_get_plugin('condition', 'taxonomy_term')) {
$plugin->execute($term, 'view');
}
}
Expand All @@ -115,11 +137,9 @@ function context_entity_prepare_view($prepare, $entity_type) {
* Implementation of hook_node_view().
*/
function context_node_view($node, $view_mode) {
if ($view_mode === 'full') {
$object = menu_get_object();
if (isset($object->nid) && $object->nid === $node->nid) {
context_node_condition($node, 'view');
}
$object = menu_get_object();
if (isset($object->nid) && $object->nid === $node->nid) {
context_node_condition($node, 'view');
}
}

Expand Down Expand Up @@ -315,21 +335,21 @@ function context_context_page_condition() {
if ($plugin = context_get_plugin('condition', 'menu')) {
$plugin->execute();
}
if ($plugin = context_get_plugin('condition', 'sitewide')) {
if ($plugin = context_get_plugin('condition', 'default')) {
$plugin->execute(1);
}
if ($plugin = context_get_plugin('condition', 'context')) {
$plugin->execute();
}
if ($plugin = context_get_plugin('condition', 'context_all')) {
$plugin->execute();
}
}

/**
* 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();
}
Expand All @@ -339,13 +359,13 @@ function context_context_page_reaction() {
}

/**
* Implementation of hook_page_alter().
* Implementation of hook_preprocess_page().
*/
function context_preprocess_page(&$vars) {
if ($plugin = context_get_plugin('reaction', 'menu')) {
if ($plugin = context_get_plugin('reaction', 'theme')) {
$plugin->execute($vars);
}
if ($plugin = context_get_plugin('reaction', 'theme')) {
if ($plugin = context_get_plugin('reaction', 'template_suggestions')) {
$plugin->execute($vars);
}
/*
Expand All @@ -358,6 +378,19 @@ 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().
*/
Expand Down
8 changes: 3 additions & 5 deletions sites/all/modules/contrib/context/context.info
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ description = "Provide modules with a cache that lasts for a single page request
package = "Context"
core = "7.x"

files[] = context.module
files[] = tests/context.test
files[] = tests/context.conditions.test
files[] = tests/context.reactions.test

; Information added by drupal.org packaging script on 2012-12-06
version = "7.x-3.0-beta5"
; Information added by Drupal.org packaging script on 2018-11-30
version = "7.x-3.9"
core = "7.x"
project = "context"
datestamp = "1354819308"

datestamp = "1543594688"
3 changes: 2 additions & 1 deletion sites/all/modules/contrib/context/context.install
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php


/**
* Implementation of hook_install().
*/
Expand Down Expand Up @@ -102,7 +103,7 @@ function context_update_7000() {
}
}
if (empty($updated)) {
$ret = t('No contexts requiring migration detected');
$ret = t('No contexts requiring migration detected.');
}
else {
$ret = t('The following contexts had theme reaction data migrated: @names', array('@names' => join(', ', $updated)));
Expand Down
73 changes: 67 additions & 6 deletions sites/all/modules/contrib/context/context.module
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ function context_context_registry() {
* Implementation of hook_init().
*/
function context_init() {
if ($plugin = context_get_plugin('condition', 'sitewide')) {
$plugin->execute(1);
}
if ($plugin = context_get_plugin('condition', 'path')) {
$plugin->execute();
}
if ($plugin = context_get_plugin('condition', 'query_string')) {
$plugin->execute();
}
if ($plugin = context_get_plugin('condition', 'language')) {
global $language;
$plugin->execute($language->language);
Expand All @@ -186,11 +192,66 @@ function context_init() {
* theme('menu_link') for the menu rendering to html.
*/
function context_preprocess_menu_link(&$variables) {
if($contexts = context_active_contexts()){
foreach($contexts as $context){
if((isset($context->reactions['menu']))){
if ($variables['element']['#href'] == $context->reactions['menu']) {
$variables['element']['#localized_options']['attributes']['class'][] = "active";
if ($contexts = context_active_contexts()) {
foreach ($contexts as $context) {
if (isset($context->reactions['menu'])) {
// In context module < v3.2 the url was a string. In version 3.3+ this is
// an array of urls. Implement interims BC layer.
//
// Examples:
// - OLD < v3.2 context reaction structure:
// array('menu' => 'taxonomy/term/1')
//
// - NEW 3.3+ context reaction structure:
// array(
// 'menu' => array(
// 0 => 'navigation:taxonomy/term/1'
// 1 => 'foo-menu:taxonomy/term/1'
// )
// )
$reactions_menu = is_array($context->reactions['menu']) ? array_values($context->reactions['menu']) : array($context->reactions['menu']);

// Get everything after the first ':' character (if found) as the url to
// match against element '#href'.
$urls = array();
foreach ($reactions_menu as $url) {
if (strpos($url, ':') !== FALSE) {
// Get unique menu name 'navigation' from 'navigation:taxonomy/term/1'
$reaction_menu = explode(':', $url);
$path = $reaction_menu[1];
$urls[$path] = $reaction_menu[0];
}
else {
// BC layer for menu contexts that have not re-saved. This is for
// urls like 'taxonomy/term/1'. We need to add a fake menu key
// 'bc-context-menu-layer' or the BC link get's removed by
// array_intersect below.
//
// @TODO: Remove BC layer in 4.x
$urls[$url] = 'context-reaction-menu-bc-layer';
}
}

// Filter urls by the menu name of the current link. The link reaction
// can be configured per menu link in specific menus and the contect
// reaction should not applied to other menus with the same menu link.
$menu_name = $variables['element']['#original_link']['menu_name'];
$menu_paths = array_intersect($urls, array($menu_name, 'context-reaction-menu-bc-layer'));
$reaction_menu_paths = array_keys($menu_paths);

// - If menu href and context reaction menu url match, add the 'active'
// css class to the link of this menu.
// - Do not add class twice on current page.
if (in_array($variables['element']['#href'], $reaction_menu_paths) && $variables['element']['#href'] != $_GET['q']) {
// Initialize classes array if not set.
if (!isset($variables['element']['#localized_options']['attributes']['class'])) {
$variables['element']['#localized_options']['attributes']['class'] = array();
}

// Do not add the 'active' class twice in views tabs.
if (!in_array('active', $variables['element']['#localized_options']['attributes']['class'])) {
$variables['element']['#localized_options']['attributes']['class'][] = 'active';
}
}
}
}
Expand Down Expand Up @@ -458,7 +519,7 @@ function context_empty($element) {
}
}
else {
$empty = $empty && empty($element);
$empty = $empty && !isset($element);
}
return $empty;
}
Expand Down
Loading

0 comments on commit ac75a6f

Please sign in to comment.