class context_layouts_reaction_block in Context 7.3
Same name and namespace in other branches
- 6.3 context_layouts/plugins/context_layouts_reaction_block.inc \context_layouts_reaction_block
- 6 context_layouts/plugins/context_layouts_reaction_block.inc \context_layouts_reaction_block
Hierarchy
- class \context_reaction
- class \context_reaction_block
Expanded class hierarchy of context_layouts_reaction_block
2 string references to 'context_layouts_reaction_block'
- context_layouts_context_plugins in context_layouts/
context_layouts.module - Implementation of hook_context_plugins(). This is a ctools plugins hook.
- context_layouts_context_registry_alter in context_layouts/
context_layouts.module - Implementation of hook_context_registry_alter().
File
- context_layouts/
plugins/ context_layouts_reaction_block.inc, line 3
View source
class context_layouts_reaction_block extends context_reaction_block {
/**
* Override of is_enabled_region().
* Check that there is an active layout and it supports the given region.
*/
protected function is_enabled_region($region) {
$layout = $this
->get_active_layout();
if ($layout && isset($layout['regions']) && is_array($layout['regions'])) {
return in_array($region, $layout['regions'], TRUE) && parent::is_enabled_region($region);
}
return parent::is_enabled_region($region);
}
/**
* Retrieve the first layout specified found by any active contexts.
*/
function get_active_layout($info = TRUE) {
$contexts = $this
->get_contexts();
$layouts = context_layouts_get_layouts();
if (!empty($contexts) && !empty($layouts)) {
foreach ($contexts as $context) {
$values = $this
->fetch_from_context($context);
if (isset($values['layout']) && isset($layouts[$values['layout']])) {
return $info ? $layouts[$values['layout']] : $values['layout'];
}
}
}
// Fallback to default layout if provided.
if (isset($layouts['default'])) {
return $info ? $layouts['default'] : 'default';
}
return FALSE;
}
/**
* Add the layout template to page vars.
*/
function add_layout_template(&$vars) {
if ($layout = $this
->get_active_layout()) {
if (!empty($layout['template'])) {
global $theme;
$vars['theme_hook_suggestion'] = "page__context_layouts_{$theme}_{$layout['layout']}";
}
}
}
/**
* Add the layout stylesheet to the CSS.
*/
function add_layout_stylesheet() {
if ($layout = $this
->get_active_layout()) {
if (!empty($layout['stylesheet'])) {
drupal_add_css(drupal_get_path('theme', $layout['theme']) . '/' . $layout['stylesheet']);
}
}
}
/**
* Override of editor form.
*/
function editor_form($context) {
drupal_add_css(drupal_get_path('module', 'context_layouts') . '/plugins/context_layouts_reaction_block.css');
$form = parent::editor_form($context);
if ($layouts = $this
->get_layout_options()) {
$options = $this
->fetch_from_context($context);
$form['layout'] = array(
// #tree *must* be true for our values to be nested correctly.
'#tree' => TRUE,
'#prefix' => '<div class="context-editor-block-layouts">',
'#suffix' => '</div>',
'#weight' => -100,
'layout' => array(
'#title' => t('Layout'),
'#options' => $layouts,
'#type' => 'select',
'#weight' => -100,
'#default_value' => isset($options['layout']) ? $options['layout'] : NULL,
'#required' => FALSE,
'#empty_value' => 0,
'#empty_option' => '- ' . t('Site default') . ' -',
),
'update' => array(
'#value' => t('Change layout'),
'#type' => 'submit',
),
);
}
return $form;
}
/**
* Override of editor form submit.
*/
function editor_form_submit(&$context, $values) {
// Someone has changed the layout, assume that the block values are not actually usable here.
if (isset($context->reactions['block']['layout']) && $context->reactions['block']['layout'] != $values['layout']['layout']) {
$options = $context->reactions['block'];
}
else {
$options = parent::editor_form_submit($context, $values);
}
if (!empty($values['layout']['layout'])) {
$options['layout'] = $values['layout']['layout'];
}
else {
unset($options['layout']);
}
return $options;
}
/**
* Override of options form.
*/
function options_form($context) {
$form = parent::options_form($context);
$options = $this
->fetch_from_context($context);
// Only alter the options form if the theme provides layouts.
$theme_key = variable_get('theme_default', 'garland');
$layouts = $this
->get_layout_options();
if (!empty($layouts)) {
$form['layout'] = array(
'#title' => t('Layout'),
'#description' => t('Choose one of the layouts provided by the default theme.'),
'#options' => $layouts,
'#type' => 'select',
'#weight' => -100,
'#default_value' => !empty($options['layout']) ? $options['layout'] : NULL,
'#attributes' => array(
'class' => array(
'context-blockform-layout',
),
),
'#required' => FALSE,
'#empty_value' => 0,
'#empty_option' => '- ' . t('Site default') . ' -',
);
// Add js.
// @TODO: Move this to a theme function or somewhere that will get called even
// if the form is using a cached version of itself (e.g. when validate fails).
drupal_add_js(drupal_get_path('module', 'context_layouts') . '/plugins/context_layouts_reaction_block.js');
drupal_add_js(array(
'contextLayouts' => array(
'layouts' => $this
->get_layout_regions(),
),
), 'setting');
}
return $form;
}
/**
* Override of submit handler.
*/
function options_form_submit($values) {
$options = parent::options_form_submit($values);
// Only alter the options form if the theme provides layouts.
$theme_key = variable_get('theme_default', 'garland');
$layouts = context_layouts_get_layouts($theme_key);
// Check that this is a valid layout.
if (!empty($values['layout']) && isset($layouts[$values['layout']])) {
$layout = $values['layout'];
$options['layout'] = $layout;
// Remove blocks that don't belong to regions in this layout.
if (isset($layouts[$layout]['regions'])) {
foreach ($options['blocks'] as $bid => $block) {
if (!in_array($block['region'], $layouts[$layout]['regions'])) {
unset($options['blocks'][$bid]);
}
}
}
}
return $options;
}
/**
* Get layout options for the given theme.
*/
protected function get_layout_options($theme_key = NULL) {
$theme_key = !isset($theme_key) ? variable_get('theme_default', 'garland') : $theme_key;
$layouts = context_layouts_get_layouts($theme_key);
$layout_options = array();
if (!empty($layouts)) {
foreach ($layouts as $layout => $info) {
$layout_options[$layout] = isset($info['name']) ? $info['name'] : $layout_options;
}
}
return $layout_options;
}
/**
* Get a layout to region map for the given theme.
*/
protected function get_layout_regions($theme_key = NULL) {
$theme_key = !isset($theme_key) ? variable_get('theme_default', 'garland') : $theme_key;
$layouts = context_layouts_get_layouts($theme_key);
if (!empty($layouts)) {
$layout_regions = array();
foreach ($layouts as $layout => $info) {
$layout_regions[$layout] = is_array($info['regions']) ? $info['regions'] : array();
}
}
return $layout_regions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
context_layouts_reaction_block:: |
function | Add the layout stylesheet to the CSS. | ||
context_layouts_reaction_block:: |
function | Add the layout template to page vars. | ||
context_layouts_reaction_block:: |
function |
Override of editor form. Overrides context_reaction_block:: |
||
context_layouts_reaction_block:: |
function |
Override of editor form submit. Overrides context_reaction_block:: |
||
context_layouts_reaction_block:: |
function | Retrieve the first layout specified found by any active contexts. | ||
context_layouts_reaction_block:: |
protected | function | Get layout options for the given theme. | |
context_layouts_reaction_block:: |
protected | function | Get a layout to region map for the given theme. | |
context_layouts_reaction_block:: |
protected | function |
Override of is_enabled_region().
Check that there is an active layout and it supports the given region. Overrides context_reaction_block:: |
|
context_layouts_reaction_block:: |
function |
Override of options form. Overrides context_reaction_block:: |
||
context_layouts_reaction_block:: |
function |
Override of submit handler. Overrides context_reaction_block:: |
||
context_reaction:: |
property | |||
context_reaction:: |
property | |||
context_reaction:: |
property | |||
context_reaction:: |
function | Retrieve options from the context provided. | 1 | |
context_reaction:: |
function | Retrieve active contexts that have values for this reaction. | ||
context_reaction:: |
function | Clone our references when we're being cloned. | ||
context_reaction:: |
function | Constructor. Do not override. | ||
context_reaction_block:: |
function | Get a renderable array of a region containing all enabled blocks. | ||
context_reaction_block:: |
function | An alternative version of block_list() that provides any context enabled blocks. | ||
context_reaction_block:: |
static | function | Sort callback. | |
context_reaction_block:: |
private | function | Allow modules to selectively allow ajax rendering of a specific block | |
context_reaction_block:: |
protected | function | Add markup for making a block editable. | |
context_reaction_block:: |
protected | function | Add markup for making a region editable. | |
context_reaction_block:: |
function | Execute. | ||
context_reaction_block:: |
function | Helper function to generate a list of blocks from a specified region. If provided a context object, will generate a full list of blocks for that region distinguishing between system blocks and context-provided blocks. | ||
context_reaction_block:: |
function | Determine if there is an active context editor block, and set a flag. We will set a flag so that we can make sure that blocks with empty content have some default content. This is needed so the save of the context inline editor does not remove the… | ||
context_reaction_block:: |
protected | function | Determine whether inline editing requirements are met and that the current user may edit. | |
context_reaction_block:: |
protected | function | Compatibility wrapper around json_decode(). | |
context_reaction_block:: |
protected | function | Generate the safe weight range for a block being added to a region such that there are enough potential unique weights to support all blocks. | |
context_reaction_block:: |
function | Check or set whether a rebuild of the block info cache is needed. | ||
context_reaction_block:: |
function | Block renderer for AJAX requests. Triggered when $_GET['context_block'] is set. See ->execute() for how this is called. | ||
context_reaction_block:: |
function |
Settings form for variables. Overrides context_reaction:: |
||
context_reaction_block:: |
protected | function | 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 |