security updates
have to check views and entityreference for custom patches
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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) {
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
@@ -105,7 +110,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');
|
||||
}
|
||||
}
|
||||
@@ -115,11 +121,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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,21 +319,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();
|
||||
}
|
||||
@@ -342,10 +346,10 @@ function context_context_page_reaction() {
|
||||
* 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);
|
||||
}
|
||||
/*
|
||||
@@ -358,6 +362,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().
|
||||
*/
|
||||
|
@@ -8,9 +8,9 @@ files[] = tests/context.test
|
||||
files[] = tests/context.conditions.test
|
||||
files[] = tests/context.reactions.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-07-29
|
||||
version = "7.x-3.0-beta7"
|
||||
; Information added by Drupal.org packaging script on 2015-01-06
|
||||
version = "7.x-3.6"
|
||||
core = "7.x"
|
||||
project = "context"
|
||||
datestamp = "1375065368"
|
||||
datestamp = "1420573188"
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
|
@@ -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);
|
||||
@@ -458,7 +464,7 @@ function context_empty($element) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
$empty = $empty && empty($element);
|
||||
$empty = $empty && !isset($element);
|
||||
}
|
||||
return $empty;
|
||||
}
|
||||
|
@@ -7,10 +7,15 @@ function _context_context_registry() {
|
||||
$registry = array();
|
||||
$registry['conditions'] = array(
|
||||
'context' => array(
|
||||
'title' => t('Context'),
|
||||
'description' => t('Set this context on the basis of other active contexts. Put each context on a separate line. You can use the <code>*</code> character (asterisk) as a wildcard and the <code>~</code> character (tilde) to prevent this context from activating if the listed context is active. Other contexts which use context conditions can not be used to exclude this context from activating.'),
|
||||
'title' => t('Context (any)'),
|
||||
'description' => t('Set this context on the basis of other active contexts. Put each context on a separate line. The condition will pass if <em>any</em> of the contexts are active. You can use the <code>*</code> character (asterisk) as a wildcard and the <code>~</code> character (tilde) to prevent this context from activating if the listed context is active. Other contexts which use context conditions can not be used to exclude this context from activating.'),
|
||||
'plugin' => 'context_condition_context',
|
||||
),
|
||||
'context_all' => array(
|
||||
'title' => t('Context (all)'),
|
||||
'description' => t('Set this context on the basis of other active contexts. Put each context on a separate line. The condition will pass only if <em>all</em> of the contexts are active. You can use the <code>*</code> character (asterisk) as a wildcard and the <code>~</code> character (tilde) to prevent this context from activating if the listed context is active. Other contexts which use context conditions can not be used to exclude this context from activating.'),
|
||||
'plugin' => 'context_condition_context_all',
|
||||
),
|
||||
'node' => array(
|
||||
'title' => t('Node type'),
|
||||
'description' => t('Set this context when viewing a node page or using the add/edit form of one of these content types.'),
|
||||
@@ -21,11 +26,21 @@ function _context_context_registry() {
|
||||
'description' => t('Should this context always be set? If <strong>true</strong>, this context will be active across your entire site.'),
|
||||
'plugin' => 'context_condition_sitewide',
|
||||
),
|
||||
'default' => array(
|
||||
'title' => t('Default context'),
|
||||
'description' => t('This context will be set if no other context is active except sitewide contexts.'),
|
||||
'plugin' => 'context_condition_default',
|
||||
),
|
||||
'path' => array(
|
||||
'title' => t('Path'),
|
||||
'description' => t('Set this context when any of the paths above match the page path. Put each path on a separate line. You can use the <code>*</code> character (asterisk) as a wildcard and the <code>~</code> character (tilde) to exclude one or more paths. Use <front> for the site front page.'),
|
||||
'plugin' => 'context_condition_path',
|
||||
),
|
||||
'query_string' => array(
|
||||
'title' => t('Query String'),
|
||||
'description' => t('Set this context when any of the query strings above match the page query string. Put each query string on a separate line. You can use the "*" character as a wildcard and <code>~</code> to exclude one or more query strings.'),
|
||||
'plugin' => 'context_condition_query_string',
|
||||
),
|
||||
'user' => array(
|
||||
'title' => t('User role'),
|
||||
'description' => t('Set this context when the current user has one of the selected role(s).'),
|
||||
@@ -98,6 +113,11 @@ function _context_context_registry() {
|
||||
'description' => t('Set the breadcrumb trail to the selected menu item.'),
|
||||
'plugin' => 'context_reaction_breadcrumb',
|
||||
),
|
||||
'template_suggestions' => array(
|
||||
'title' => t('Template suggestions'),
|
||||
'description' => t('Add template suggestions using context.'),
|
||||
'plugin' => 'context_reaction_template_suggestions',
|
||||
),
|
||||
'theme' => array(
|
||||
'title' => t('Theme Page'),
|
||||
'description' => t('Control page theme variables using context.'),
|
||||
@@ -155,6 +175,14 @@ function _context_context_plugins() {
|
||||
'parent' => 'context_condition_path',
|
||||
),
|
||||
);
|
||||
$plugins['context_condition_context_all'] = array(
|
||||
'handler' => array(
|
||||
'path' => drupal_get_path('module', 'context') . '/plugins',
|
||||
'file' => 'context_condition_context_all.inc',
|
||||
'class' => 'context_condition_context_all',
|
||||
'parent' => 'context_condition_path',
|
||||
),
|
||||
);
|
||||
$plugins['context_condition_node'] = array(
|
||||
'handler' => array(
|
||||
'path' => drupal_get_path('module', 'context') . '/plugins',
|
||||
@@ -171,6 +199,14 @@ function _context_context_plugins() {
|
||||
'parent' => 'context_condition',
|
||||
),
|
||||
);
|
||||
$plugins['context_condition_default'] = array(
|
||||
'handler' => array(
|
||||
'path' => drupal_get_path('module', 'context') . '/plugins',
|
||||
'file' => 'context_condition_default.inc',
|
||||
'class' => 'context_condition_default',
|
||||
'parent' => 'context_condition',
|
||||
),
|
||||
);
|
||||
$plugins['context_condition_path'] = array(
|
||||
'handler' => array(
|
||||
'path' => drupal_get_path('module', 'context') . '/plugins',
|
||||
@@ -179,6 +215,14 @@ function _context_context_plugins() {
|
||||
'parent' => 'context_condition',
|
||||
),
|
||||
);
|
||||
$plugins['context_condition_query_string'] = array(
|
||||
'handler' => array(
|
||||
'path' => drupal_get_path('module', 'context') .'/plugins',
|
||||
'file' => 'context_condition_query_string.inc',
|
||||
'class' => 'context_condition_query_string',
|
||||
'parent' => 'context_condition_path',
|
||||
),
|
||||
);
|
||||
$plugins['context_condition_user'] = array(
|
||||
'handler' => array(
|
||||
'path' => drupal_get_path('module', 'context') . '/plugins',
|
||||
@@ -294,6 +338,14 @@ function _context_context_plugins() {
|
||||
'parent' => 'context_reaction_menu',
|
||||
),
|
||||
);
|
||||
$plugins['context_reaction_template_suggestions'] = array(
|
||||
'handler' => array(
|
||||
'path' => drupal_get_path('module', 'context') . '/plugins',
|
||||
'file' => 'context_reaction_template_suggestions.inc',
|
||||
'class' => 'context_reaction_template_suggestions',
|
||||
'parent' => 'context_reaction',
|
||||
),
|
||||
);
|
||||
$plugins['context_reaction_menu'] = array(
|
||||
'handler' => array(
|
||||
'path' => drupal_get_path('module', 'context') . '/plugins',
|
||||
|
@@ -6,9 +6,9 @@ core = 7.x
|
||||
|
||||
files[] = plugins/context_layouts_reaction_block.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-07-29
|
||||
version = "7.x-3.0-beta7"
|
||||
; Information added by Drupal.org packaging script on 2015-01-06
|
||||
version = "7.x-3.6"
|
||||
core = "7.x"
|
||||
project = "context"
|
||||
datestamp = "1375065368"
|
||||
datestamp = "1420573188"
|
||||
|
||||
|
@@ -49,7 +49,7 @@ function context_layouts_theme() {
|
||||
if (!empty($layout['template'])) {
|
||||
$info["page__context_layouts_{$theme->name}_{$layout['layout']}"] = array(
|
||||
'template' => $layout['template'],
|
||||
'path' => drupal_get_path('theme', $theme->name),
|
||||
'path' => $layout['path'],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -107,10 +107,12 @@ function context_layouts_get_layouts($theme = NULL, $reset = FALSE) {
|
||||
|
||||
// Merge layout info into a single array.
|
||||
foreach ($themes as $key => $info) {
|
||||
$path = drupal_get_path('theme', $key);
|
||||
if (!empty($info['layouts'])) {
|
||||
foreach ($info['layouts'] as $layout => $layout_info) {
|
||||
$layout_info['layout'] = str_replace('-', '_', $layout);
|
||||
$layout_info['theme'] = $key;
|
||||
$layout_info['path'] = $path;
|
||||
$layouts[$theme][$layout] = $layout_info;
|
||||
}
|
||||
}
|
||||
|
@@ -8,9 +8,9 @@ configure = admin/structure/context
|
||||
files[] = context.module
|
||||
files[] = tests/context_ui.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-07-29
|
||||
version = "7.x-3.0-beta7"
|
||||
; Information added by Drupal.org packaging script on 2015-01-06
|
||||
version = "7.x-3.6"
|
||||
core = "7.x"
|
||||
project = "context"
|
||||
datestamp = "1375065368"
|
||||
datestamp = "1420573188"
|
||||
|
||||
|
@@ -80,6 +80,10 @@ function context_ui_permission() {
|
||||
'title' => 'Administer contexts',
|
||||
'description' => 'Associate menus, views, blocks, etc. with different contexts to structure your site.'
|
||||
);
|
||||
$permissions['context ajax block access'] = array(
|
||||
'title' => t('Access All Blocks'),
|
||||
'description' => t('Allows users to access all rendered blocks via an AJAX callback. If you have some blocks that should not be rendered for some users but need those users to be able to use context UI, then implement hook_context_allow_ajax_block_access with the necessary logic.'),
|
||||
);
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
@@ -383,8 +387,10 @@ function context_ui_menu_contextual_links_alter(&$links, $router_item, $root_pat
|
||||
* A page call back to activate the context_ui inline editor dialog.
|
||||
*/
|
||||
function context_ui_activate() {
|
||||
$_SESSION['context_ui_active'] = $_GET['destination'];
|
||||
drupal_goto($_GET['destination']);
|
||||
if (isset($_GET['destination']) && !url_is_external($_GET['destination'])) {
|
||||
$_SESSION['context_ui_active'] = $_GET['destination'];
|
||||
drupal_goto($_GET['destination']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,8 +400,10 @@ function context_ui_activate() {
|
||||
* to navigate to when deactivating context_ui_editor
|
||||
*/
|
||||
function context_ui_deactivate() {
|
||||
$_SESSION['context_ui_active'] = FALSE;
|
||||
drupal_goto($_GET['destination']);
|
||||
if (isset($_GET['destination']) && !url_is_external($_GET['destination'])) {
|
||||
$_SESSION['context_ui_active'] = FALSE;
|
||||
drupal_goto($_GET['destination']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -73,6 +73,7 @@ class context_export_ui extends ctools_export_ui {
|
||||
if (!empty($this->plugin['form']['submit'])) {
|
||||
$this->plugin['form']['submit']($form, $form_state);
|
||||
}
|
||||
context_invalidate_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -24,6 +24,7 @@ class ContextUiTestCase extends DrupalWebTestCase {
|
||||
$admin_user = $this->drupalCreateUser(array(
|
||||
'access administration pages',
|
||||
'administer site configuration',
|
||||
'administer contexts',
|
||||
'access content',
|
||||
'create blog content'
|
||||
));
|
||||
|
@@ -9,7 +9,8 @@ class context_condition_context extends context_condition_path {
|
||||
$active_contexts = array_keys(context_active_contexts());
|
||||
foreach ($this->get_contexts() as $context) {
|
||||
if (!in_array($context->name, $active_contexts, TRUE) && $values = $this->fetch_from_context($context, 'values')) {
|
||||
if ($this->match($active_contexts, $values)) {
|
||||
// Always check against the active contexts.
|
||||
if ($this->match(array_keys(context_active_contexts()), $values)) {
|
||||
$this->condition_met($context);
|
||||
}
|
||||
}
|
||||
@@ -20,4 +21,45 @@ class context_condition_context extends context_condition_path {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all context conditions.
|
||||
*
|
||||
* This method is slightly adapted to context_condition::get_contexts() in
|
||||
* order to ensure that a context that is used as condition in another context
|
||||
* gets handled before.
|
||||
*/
|
||||
function get_contexts($value = NULL) {
|
||||
$map = context_condition_map();
|
||||
$map = isset($map[$this->plugin]) ? $map[$this->plugin] : array();
|
||||
|
||||
$contexts = array();
|
||||
|
||||
// Add the contexts that are needed for conditions in the other contexts
|
||||
// first. Start with the negated ones first, as we can not unset a met
|
||||
// condition afterwards.
|
||||
krsort($map);
|
||||
foreach ($map as $key => $submap) {
|
||||
// Negated context conditions start with a "~".
|
||||
if (substr($key, 0, 1) == "~") {
|
||||
$key = substr($key, 1);
|
||||
}
|
||||
if (!isset($contexts[$key])) {
|
||||
$context = context_load($key);
|
||||
// Check if context exists. This will fail for wildcards.
|
||||
if ($context) {
|
||||
$contexts[$context->name] = $context;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($map as $key => $submap) {
|
||||
foreach ($submap as $name) {
|
||||
if (!isset($contexts[$name])) {
|
||||
$context = context_load($name);
|
||||
$contexts[$context->name] = $context;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $contexts;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Expose active contexts as a context condition.
|
||||
*/
|
||||
class context_condition_context_all extends context_condition_path {
|
||||
function execute() {
|
||||
if ($this->condition_used()) {
|
||||
$active_contexts = array_keys(context_active_contexts());
|
||||
foreach ($this->get_contexts() as $context) {
|
||||
|
||||
// Only test contexts that haven't been activated yet,
|
||||
// and have values set.
|
||||
if (!in_array($context->name, $active_contexts, TRUE) && $values = $this->fetch_from_context($context, 'values')) {
|
||||
|
||||
// The condition is met if all contexts are active.
|
||||
if (count(array_intersect($values, $active_contexts)) == count($values)) {
|
||||
$this->condition_met($context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the list of active contexts has changed, we need to recurse.
|
||||
if ($active_contexts != array_keys(context_active_contexts())) {
|
||||
$this->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Simple condition that sets context active if no other non-default and non
|
||||
* sitewide context is active.
|
||||
*/
|
||||
class context_condition_default extends context_condition {
|
||||
function condition_values() {
|
||||
return array('context_condition_default' => t('Default context'));
|
||||
}
|
||||
|
||||
function editor_form($context = NULL) {
|
||||
$form = parent::editor_form($context);
|
||||
$form[1]['#title'] = t('Default context');
|
||||
$form['#weight'] = -10;
|
||||
return $form;
|
||||
}
|
||||
|
||||
function execute() {
|
||||
if ($this->condition_used()) {
|
||||
$active_contexts = context_active_contexts();
|
||||
|
||||
foreach ($active_contexts as $name => $context) {
|
||||
foreach (array_keys($context->conditions) as $cond) {
|
||||
if (!in_array($cond, array('default', 'sitewide'))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($this->get_contexts('context_condition_default') as $context) {
|
||||
$this->condition_met($context, 'context_condition_default');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file context_condition_query_string.inc
|
||||
*
|
||||
* Similar to context_condition_path but for entire query string.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Expose query strings as a context condition.
|
||||
*/
|
||||
class context_condition_query_string extends context_condition_path {
|
||||
|
||||
/**
|
||||
* Execute.
|
||||
*/
|
||||
function execute() {
|
||||
if ($this->condition_used()) {
|
||||
$current_query_string = $_SERVER["QUERY_STRING"];
|
||||
foreach ($this->get_contexts() as $context) {
|
||||
$query_strings = $this->fetch_from_context($context, 'values');
|
||||
if ($this->match($current_query_string, $query_strings, TRUE)) {
|
||||
$this->condition_met($context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -168,7 +168,6 @@ body.context-editing .draggable:hover a.context-block-remove {
|
||||
* Block visibility ===================================================
|
||||
*/
|
||||
#context-blockform .context-blockform-selector {
|
||||
height:20em;
|
||||
overflow:auto;
|
||||
}
|
||||
|
||||
@@ -179,6 +178,7 @@ body.context-editing .draggable:hover a.context-block-remove {
|
||||
border:1px solid #ddd;
|
||||
padding:10px;
|
||||
width:50%;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#context-blockform td.blocks .label,
|
||||
|
@@ -42,13 +42,19 @@ class context_reaction_block extends context_reaction {
|
||||
$group = isset($block->context_group) ? $block->context_group : $block->module;
|
||||
if (!isset($form['selector'][$group])) {
|
||||
$form['selector'][$group] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#title' => isset($block->context_group) ? $block->context_group : $modules[$block->module],
|
||||
);
|
||||
$form['selector'][$group]['checkboxes'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => array(),
|
||||
);
|
||||
}
|
||||
$form['selector'][$group]['#options'][$block->bid] = check_plain($block->info);
|
||||
$form['selector'][$group]['checkboxes']['#options'][$block->bid] = check_plain($block->info);
|
||||
}
|
||||
|
||||
ksort($form['selector']);
|
||||
|
||||
/**
|
||||
@@ -58,7 +64,7 @@ class context_reaction_block extends context_reaction {
|
||||
'#tree' => TRUE,
|
||||
'#theme' => 'context_block_regions_form',
|
||||
);
|
||||
foreach (system_region_list($theme_key, REGIONS_VISIBLE) as $region => $label) {
|
||||
foreach ($this->system_region_list($theme_key, REGIONS_VISIBLE) as $region => $label) {
|
||||
$form['blocks'][$region] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => $label,
|
||||
@@ -215,7 +221,7 @@ class context_reaction_block extends context_reaction {
|
||||
}
|
||||
|
||||
// Populate all block regions
|
||||
$all_regions = system_region_list($theme);
|
||||
$all_regions = $this->system_region_list($theme);
|
||||
|
||||
// Load all region content assigned via blocks.
|
||||
foreach (array_keys($all_regions) as $region) {
|
||||
@@ -255,7 +261,7 @@ class context_reaction_block extends context_reaction {
|
||||
*/
|
||||
protected function is_enabled_region($region) {
|
||||
global $theme;
|
||||
$regions = array_keys(system_region_list($theme));
|
||||
$regions = array_keys($this->system_region_list($theme));
|
||||
return in_array($region, $regions, TRUE);
|
||||
}
|
||||
|
||||
@@ -290,7 +296,7 @@ class context_reaction_block extends context_reaction {
|
||||
return FALSE;
|
||||
}
|
||||
// Check that this region is not hidden
|
||||
$visible = system_region_list($theme, REGIONS_VISIBLE);
|
||||
$visible = $this->system_region_list($theme, REGIONS_VISIBLE);
|
||||
return $requirements && $this->is_enabled_region($region) && isset($visible[$region]);
|
||||
}
|
||||
|
||||
@@ -299,15 +305,7 @@ class context_reaction_block extends context_reaction {
|
||||
*/
|
||||
protected function editable_block($block) {
|
||||
if (!empty($block->content)) {
|
||||
$block->content = array(
|
||||
'content' => $block->content,
|
||||
'context' => array('#markup' => "<a id='context-block-{$block->module}-{$block->delta}' class='context-block editable edit-{$block->context}'></a>"),
|
||||
);
|
||||
//Contextual links are in the wrong spot in the render array once we've nested them
|
||||
if (isset($block->content['content']['#contextual_links'])) {
|
||||
$block->content['#contextual_links'] = $block->content['content']['#contextual_links'];
|
||||
unset($block->content['content']['#contextual_links']);
|
||||
}
|
||||
$block->content['#theme_wrappers'][] = 'context_block_edit_wrap';
|
||||
}
|
||||
else {
|
||||
// the block alter in context.module should ensure that blocks are never
|
||||
@@ -328,7 +326,7 @@ class context_reaction_block extends context_reaction {
|
||||
context_isset('context_ui', 'context_ui_editor_present'))
|
||||
) {
|
||||
global $theme;
|
||||
$regions = system_region_list($theme);
|
||||
$regions = $this->system_region_list($theme);
|
||||
$name = isset($regions[$region]) ? $regions[$region] : $region;
|
||||
// The negative weight + sorted will push our region marker to the top of the region
|
||||
$build['context'] = array(
|
||||
@@ -388,13 +386,29 @@ class context_reaction_block extends context_reaction {
|
||||
}
|
||||
|
||||
$this->is_editable_check($context_blocks);
|
||||
foreach ($context_blocks as $r => $blocks) {
|
||||
$context_blocks[$r] = _block_render_blocks($blocks);
|
||||
global $theme;
|
||||
$active_regions = $this->system_region_list($theme);
|
||||
|
||||
// Make blocks editable if allowed.
|
||||
if ($this->is_editable_region($r)) {
|
||||
foreach ($context_blocks[$r] as $key => $block) {
|
||||
$context_blocks[$r][$key] = $this->editable_block($block);
|
||||
// Make context renders regions in the same order as core.
|
||||
$_context_blocks = array();
|
||||
foreach ($active_regions as $r => $name) {
|
||||
if (isset($context_blocks[$r])) {
|
||||
$_context_blocks[$r] = $context_blocks[$r];
|
||||
}
|
||||
}
|
||||
$context_blocks = $_context_blocks;
|
||||
unset($_context_blocks);
|
||||
|
||||
foreach ($context_blocks as $r => $blocks) {
|
||||
//only render blocks in an active region
|
||||
if (array_key_exists($r, $active_regions)) {
|
||||
$context_blocks[$r] = _block_render_blocks($blocks);
|
||||
|
||||
// Make blocks editable if allowed.
|
||||
if ($this->is_editable_region($r)) {
|
||||
foreach ($context_blocks[$r] as $key => $block) {
|
||||
$context_blocks[$r][$key] = $this->editable_block($block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,7 +528,12 @@ class context_reaction_block extends context_reaction {
|
||||
$result = db_select('block')
|
||||
->fields('block')
|
||||
->condition('theme', $theme_key)
|
||||
->execute();
|
||||
->execute()
|
||||
->fetchAllAssoc('bid');
|
||||
|
||||
drupal_alter('block_list', $result);
|
||||
drupal_alter('context_block_list', $result);
|
||||
|
||||
foreach ($result as $row) {
|
||||
if (isset($block_info["{$row->module}-{$row->delta}"])) {
|
||||
$block_info["{$row->module}-{$row->delta}"] = (object) array_merge((array) $row, (array) $block_info["{$row->module}-{$row->delta}"]);
|
||||
@@ -576,50 +595,9 @@ class context_reaction_block extends context_reaction {
|
||||
if (function_exists('json_decode')) {
|
||||
return json_decode($json, $assoc);
|
||||
}
|
||||
return context_reaction_block::_json_decode($json);
|
||||
}
|
||||
|
||||
/**
|
||||
* From http://www.php.net/manual/en/function.json-decode.php#91216
|
||||
* with modifications for consistency with output of json_decode().
|
||||
*
|
||||
* Original author: walidator.info 2009.
|
||||
*/
|
||||
static function _json_decode($json) {
|
||||
$comment = FALSE;
|
||||
$out = '$x = ';
|
||||
for ($i=0; $i < strlen($json); $i++) {
|
||||
if (!$comment) {
|
||||
switch ($json[$i]) {
|
||||
case '{':
|
||||
$out .= ' (object) array(';
|
||||
break;
|
||||
case '}':
|
||||
$out .= ')';
|
||||
break;
|
||||
case '[':
|
||||
$out .= ' array(';
|
||||
break;
|
||||
case ']':
|
||||
$out .= ')';
|
||||
break;
|
||||
case ':';
|
||||
$out .= '=>';
|
||||
break;
|
||||
default:
|
||||
$out .= $json[$i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$out .= $json[$i];
|
||||
}
|
||||
if ($json[$i] == '"') {
|
||||
$comment = !$comment;
|
||||
}
|
||||
else {
|
||||
watchdog('context', 'Please upgrade your PHP version to one that supports json_decode.');
|
||||
}
|
||||
eval($out . ';');
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -640,7 +618,7 @@ class context_reaction_block extends context_reaction {
|
||||
list($bid, $context) = explode(',', $param);
|
||||
list($module, $delta) = explode('-', $bid, 2);
|
||||
// Check token to make sure user has access to block.
|
||||
if (empty($_GET['context_token']) || $_GET['context_token'] != drupal_get_token($bid)) {
|
||||
if (!(user_access('administer contexts') || user_access('context ajax block access') || $this->context_block_ajax_rendering_allowed($bid))) {
|
||||
echo drupal_json_encode(array('status' => 0));
|
||||
exit;
|
||||
}
|
||||
@@ -670,4 +648,34 @@ class context_reaction_block extends context_reaction {
|
||||
echo drupal_json_encode(array('status' => 0));
|
||||
drupal_exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide caching for system_region_list since it can get called
|
||||
* frequently. Evaluate for removal once https://drupal.org/node/1873450
|
||||
* lands or system_region_list is otherwise cached in core
|
||||
*/
|
||||
protected function system_region_list($theme_key, $show = REGIONS_ALL) {
|
||||
static $cache = array();
|
||||
if (!isset($cache[$theme_key])) {
|
||||
$cache[$theme_key] = array();
|
||||
}
|
||||
if (!isset($cache[$theme_key][$show])) {
|
||||
$cache[$theme_key][$show] = system_region_list($theme_key, $show);
|
||||
}
|
||||
return $cache[$theme_key][$show];
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow modules to selectively allow ajax rendering of a specific block
|
||||
*/
|
||||
private function context_block_ajax_rendering_allowed($bid) {
|
||||
$allowed = FALSE;
|
||||
foreach (module_invoke_all('context_allow_ajax_block_access', $bid) as $module_allow) {
|
||||
$allowed = $allow || $module_allow;
|
||||
if ($allowed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $allowed;
|
||||
}
|
||||
}
|
||||
|
@@ -327,11 +327,6 @@ DrupalContextBlockEditor.prototype = {
|
||||
// Construct query params for our AJAX block request.
|
||||
var params = Drupal.settings.contextBlockEditor.params;
|
||||
params.context_block = bid + ',' + context;
|
||||
if (!Drupal.settings.contextBlockEditor.block_tokens || !Drupal.settings.contextBlockEditor.block_tokens[bid]) {
|
||||
alert(Drupal.t('An error occurred trying to retrieve block content. Please contact a site administer.'));
|
||||
return;
|
||||
}
|
||||
params.context_token = Drupal.settings.contextBlockEditor.block_tokens[bid];
|
||||
|
||||
// Replace item with loading block.
|
||||
//ui.sender.append(ui.item);
|
||||
@@ -443,7 +438,7 @@ DrupalContextBlockEditor.prototype = {
|
||||
dropOnEmpty: true,
|
||||
placeholder: 'draggable-placeholder',
|
||||
forcePlaceholderSize: true,
|
||||
items: '> .block:has(a.context-block.editable)',
|
||||
items: '> *:has(a.context-block.editable)',
|
||||
handle: 'a.context-block-handle',
|
||||
start: function(event, ui) { self.scriptFix(event, ui, editor, context); },
|
||||
stop: function(event, ui) { self.addBlock(event, ui, editor, context); },
|
||||
|
@@ -5,35 +5,35 @@
|
||||
*/
|
||||
class context_reaction_breadcrumb extends context_reaction_menu {
|
||||
/**
|
||||
* Override of execute().
|
||||
* Overrides set_active_trail_from_link to set the breadcrumb instead of the menu path.
|
||||
*/
|
||||
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($parent['title'], $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;
|
||||
}
|
||||
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']);
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return the title to be used for the current menu item.
|
||||
*/
|
||||
function get_link_title($item) {
|
||||
return module_exists('i18n_menu') ? _i18n_menu_link_title($item) : $item['title'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -12,13 +12,27 @@ class context_reaction_debug extends context_reaction {
|
||||
return array('debug' => 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for variables.
|
||||
*/
|
||||
function settings_form() {
|
||||
$form = array();
|
||||
$form['context_reaction_debug_enable_global'] = array(
|
||||
'#title' => t('Enable debug reaction on all contexts'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => variable_get('context_reaction_debug_enable_global', FALSE),
|
||||
'#description' => t('Enable the debug reaction on all contexts.')
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a list of active contexts.
|
||||
*/
|
||||
function execute() {
|
||||
$contexts = context_active_contexts();
|
||||
foreach ($contexts as $context) {
|
||||
if (!empty($context->reactions['debug'])) {
|
||||
if (!empty($context->reactions['debug']) || variable_get('context_reaction_debug_enable_global', FALSE)) {
|
||||
if (user_access('administer site configuration') && module_exists('context_ui')) {
|
||||
$name = l($context->name, "admin/structure/context/list/{$context->name}", array('query' => array('destination' => $_GET['q'])));
|
||||
}
|
||||
|
@@ -8,35 +8,33 @@ 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));
|
||||
$root_menus = array();
|
||||
foreach ($menus as $key => $name) {
|
||||
$id = explode(':', $key);
|
||||
if ($id[1] == '0') {
|
||||
$root_menus[$id[0]] = check_plain($name);
|
||||
$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] = $title;
|
||||
}
|
||||
else {
|
||||
$link = menu_link_load($id[1]);
|
||||
$link = menu_link_load($mlid);
|
||||
$identifier = $link['link_path'];
|
||||
$root_menu = $root_menus[$id[0]];
|
||||
while (isset($menus[$root_menu][$identifier])) {
|
||||
$root_menu = $menu_names[$menu_name];
|
||||
while (isset($options[$root_menu][$identifier])) {
|
||||
$identifier .= "'";
|
||||
}
|
||||
$menus[$root_menu][$identifier] = $name;
|
||||
$options[$root_menu][$menu_name . ':' . $identifier] = $title;
|
||||
}
|
||||
unset($menus[$key]);
|
||||
}
|
||||
array_unshift($menus, "-- " . t('None') . " --");
|
||||
}
|
||||
else {
|
||||
$menus = array();
|
||||
}
|
||||
return array(
|
||||
'#title' => $this->title,
|
||||
'#description' => $this->description,
|
||||
'#options' => $menus,
|
||||
'#options' => $options,
|
||||
'#type' => 'select',
|
||||
'#multiple' => TRUE,
|
||||
'#default_value' => $this->fetch_from_context($context),
|
||||
);
|
||||
}
|
||||
@@ -46,97 +44,100 @@ class context_reaction_menu extends context_reaction {
|
||||
* Trim any identifier padding for non-unique path menu items.
|
||||
*/
|
||||
function options_form_submit($values) {
|
||||
return trim($values, "'");
|
||||
$trimmed = array();
|
||||
foreach ($values as $value) {
|
||||
$value = trim($value, "'");
|
||||
$trimmed[] = $value;
|
||||
}
|
||||
return $trimmed;
|
||||
}
|
||||
|
||||
/**
|
||||
* If primary + secondary links are pointed at the same menu, provide
|
||||
* contextual trailing by default.
|
||||
* Overrides parent function to include legacy handling for old format of just storing a single path.
|
||||
*/
|
||||
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'];
|
||||
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();
|
||||
}
|
||||
return array($menu['menu_name'] . ':' . $menu['link_path']);
|
||||
}
|
||||
|
||||
$vars['main_menu'] = $this->menu_set_active($vars['main_menu']);
|
||||
$vars['secondary_menu'] = $this->menu_set_active($vars['secondary_menu']);
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide active trail in all menus in which our path appears.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to build and set the active trail from a menu link.
|
||||
*
|
||||
* @param $item
|
||||
* A menu link item.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (isset($context->reactions[$this->plugin])) {
|
||||
$active_paths[] = $context->reactions[$this->plugin];
|
||||
}
|
||||
}
|
||||
return $active_paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$new_links[$key] = $link;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $new_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around menu_navigation_links() that gives themers the option of
|
||||
* building navigation links based on an active context 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');
|
||||
|
||||
// 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);
|
||||
}
|
||||
$paths = $this->fetch_from_context($context);
|
||||
$active_paths = array_merge($active_paths, $paths);
|
||||
}
|
||||
|
||||
// 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);
|
||||
$by_menu_name = array();
|
||||
foreach ($active_paths as $id) {
|
||||
list($menu_name, $path) = explode(':', $id);
|
||||
$by_menu_name[$menu_name][] = $path;
|
||||
}
|
||||
|
||||
// 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;
|
||||
return $by_menu_name;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Add template suggestions as a context reaction.
|
||||
*/
|
||||
class context_reaction_template_suggestions extends context_reaction {
|
||||
|
||||
/**
|
||||
* Display the text area field for adding new template suggestions.
|
||||
*/
|
||||
function options_form($context) {
|
||||
$default_value = $this->fetch_from_context($context);
|
||||
|
||||
return array(
|
||||
'#title' => t('Template suggestions'),
|
||||
'#type' => 'textarea',
|
||||
'#description' => t('Enter template suggestions such as "page__front", one per line, in order of preference (using underscores instead of hyphens). For more information, please visit ') . l(t('Drupal 7 Template (Theme Hook) Suggestions'), 'http://drupal.org/node/1089656', array(array('target' => '_blank'), 'html' => TRUE,)) . '.',
|
||||
'#default_value' => is_string($default_value) ? $default_value : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any new template suggestions to the current list.
|
||||
*/
|
||||
function execute(&$vars = NULL) {
|
||||
|
||||
// Get the list of contexts associated with this reaction.
|
||||
$contexts = $this->get_contexts();
|
||||
|
||||
// Iterate through each, and process those with something set.
|
||||
foreach ($contexts as $context) {
|
||||
if (isset($context->reactions) && (!empty($context->reactions[$this->plugin]))) {
|
||||
|
||||
// Get the suggestion data entered by the user.
|
||||
$suggestions = $this->fetch_from_context($context, 'values');
|
||||
|
||||
// Convert it to an list and reverse it (as higher priority items
|
||||
// should be on the bottom).
|
||||
$suggestions = array_reverse(explode("\n", $suggestions));
|
||||
|
||||
// Append the suggested list to the existing list.
|
||||
$vars['theme_hook_suggestions'] = array_merge($vars['theme_hook_suggestions'], $suggestions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -88,19 +88,44 @@ class ContextReactionBlockAjaxTest extends DrupalWebTestCase {
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('context', 'ctools');
|
||||
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
|
||||
parent::setUp('context', 'context_ui', 'ctools');
|
||||
$admin_user = $this->drupalCreateUser(array('context ajax block access'));
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
function test() {
|
||||
$token = drupal_hmac_base64('user-online', $this->session_id . drupal_get_private_key() . drupal_get_hash_salt());
|
||||
$this->drupalGet('node', array(
|
||||
'query' => array('context_block' => 'user-online,testcontext', 'context_token' => $token)
|
||||
'query' => array('context_block' => 'user-online,testcontext')
|
||||
));
|
||||
|
||||
$this->assertText('"status":1', 'Successful return status. $drupal_hash_salt must be set explicitly for this test to pass');
|
||||
$this->assertText('Who\\u0027s online', 'Expected text in block data. drupal_hash_salt must be set explicitly for this test to pass');
|
||||
$this->assertText('"status":1', 'Successful return status.');
|
||||
$this->assertText('Who\\u0027s online', 'Expected text in block data.');
|
||||
}
|
||||
}
|
||||
|
||||
class ContextReactionBlockAjaxAccessTest extends DrupalWebTestCase {
|
||||
protected $profile = 'testing';
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Reaction: block ajax access',
|
||||
'description' => 'Test block reaction ajax access behavior.',
|
||||
'group' => 'Context',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('context', 'ctools');
|
||||
$admin_user = $this->drupalCreateUser();
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
function test() {
|
||||
$this->drupalGet('node', array(
|
||||
'query' => array('context_block' => 'user-online,testcontext')
|
||||
));
|
||||
|
||||
$this->assertText('"status":0', 'Failed return status.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -121,11 +121,16 @@ function template_preprocess_context_block_browser(&$vars) {
|
||||
* Preprocessor for theme('context_block_browser_item').
|
||||
*/
|
||||
function template_preprocess_context_block_browser_item(&$vars) {
|
||||
static $added = array();
|
||||
$vars['bid'] = $vars['block']->bid;
|
||||
$vars['info'] = check_plain($vars['block']->info);
|
||||
if (empty($added[$vars['bid']])) {
|
||||
drupal_add_js(array('contextBlockEditor' => array('block_tokens' => array($vars['bid'] => drupal_get_token($vars['bid'])))), 'setting');
|
||||
$added[$vars['bid']] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme wrapper for editable blocks.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_context_block_edit_wrap($vars) {
|
||||
$block = $vars['element']['#block'];
|
||||
return $vars['element']['#children'] . "<a id='context-block-{$block->module}-{$block->delta}' class='context-block editable edit-{$block->context}'></a>";
|
||||
}
|
||||
|
Reference in New Issue
Block a user