context_omega_reaction_omega_layout.inc in Context omega 7
File
plugins/context_omega_reaction_omega_layout.inc
View source
<?php
class context_omega_reaction_omega_layout extends context_reaction_block {
function options_form($context) {
$form = parent::options_form($context);
if ($layouts = context_omega_get_layouts()) {
$options = $regions = array();
foreach ($layouts as $key => $layout) {
$regions[$key] = array_keys($layout['info']['regions']);
$options[$key] = $layout['info']['name'];
}
asort($layouts);
$values = $this
->fetch_from_context($context);
$form['layout'] = array(
'#title' => t('Choose an Omega layout'),
'#description' => t('Choose the Omega layout to use.'),
'#type' => 'select',
'#options' => $options,
'#default_value' => isset($values['layout']) ? $values['layout'] : NULL,
'#weight' => -10,
'#empty_value' => '_default',
'#empty_option' => t('Default'),
'#attributes' => array(
'class' => array(
'context-omega-layout-select',
),
),
);
drupal_add_js(drupal_get_path('module', 'context_omega') . '/plugins/context_omega_reaction_omega_layout.js');
drupal_add_js(array(
'contextOmega' => array(
'regions' => $regions,
),
), 'setting');
}
return $form;
}
function options_form_submit($values) {
$options = parent::options_form_submit($values);
$layouts = context_omega_get_layouts();
if (!empty($values['layout']) && isset($layouts[$values['layout']])) {
$options['layout'] = $values['layout'];
foreach ($options['blocks'] as $key => $block) {
if (!isset($layouts[$options['layout']]['info']['regions'][$block['region']])) {
unset($options['blocks'][$key]);
}
}
}
return $options;
}
function get_active_layout() {
foreach ($this
->get_contexts() as $context) {
$values = $this
->fetch_from_context($context);
if (isset($values['layout'])) {
return $values['layout'];
}
}
return FALSE;
}
}