first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
<?php
/**
* Expose themes as context reactions.
*/
class context_reaction_delta extends context_reaction {
/**
* @todo
*/
function options_form($context) {
$values = $this->fetch_from_context($context);
$options = _delta_options();
$form = array(
'#tree' => TRUE,
'#title' => t('Delta Override Template'),
);
$form['delta_template'] = array(
'#type' => count($options) > 10 ? 'select' : 'radios',
'#title' => t('Select Custom theme settings template.'),
'#description' => empty($options) ? t('There are no valid (enabled) Delta templates available.') : t('The theme settings of the selected Delta template will override the default theme settings for all pages that match this context.'),
'#default_value' => isset($values['delta_template']) ? $values['delta_template'] : NULL,
'#options' => $options,
);
return $form;
}
/**
* @todo
*/
function execute() {
foreach (context_active_contexts() as $context) {
if (!empty($context->reactions['delta']['delta_template'])) {
$template = $context->reactions['delta']['delta_template'];
if (delta_enabled($template)) {
delta_inject($template);
}
}
}
}
}
/**
* @todo
*/
function _delta_options() {
$options = array();
foreach (delta_load_all() as $item) {
if (delta_enabled($item->machine_name)) {
$options[$item->machine_name] = $item->name;
}
}
return $options;
}

View File

@@ -0,0 +1,134 @@
<?php
class delta_injection {
var $plugin;
var $delta;
var $original;
var $settings;
/**
* Constructor. Do not override.
*/
function __construct($plugin, $delta) {
$this->plugin = $plugin;
$this->delta = delta_load($delta);
}
/**
* @todo
*/
function variables() {
return array();
}
/**
* @todo
*/
function config($name) {
if (isset($this->settings[$name])) {
return $this->settings[$name];
}
if (!empty($this->delta->parent)) {
if ($plugin = delta_get_plugin($this->delta->parent, $this->plugin['name'])) {
$this->settings[$name] = isset($this->delta->settings[$name]) ? delta_merge($plugin->config($name), $this->delta->settings[$name]) : $plugin->config($name);
}
}
if (!isset($this->settings[$name])) {
$this->settings[$name] = isset($this->delta->settings[$name]) ? delta_merge(variable_get($name), $this->delta->settings[$name]) : variable_get($name);
}
return $this->settings[$name];
}
/**
* @todo
*/
function inject() {
foreach ($this->variables() as $name) {
$settings = $this->config($name);
if (isset($settings)) {
$this->backup($name, delta_variable_set($name, $settings));
}
}
}
/**
* @todo
*/
function revoke() {
foreach ($this->variables() as $name) {
delta_variable_set($name, $this->backup($name));
}
}
/**
* @todo
*/
function backup($name, $value = NULL) {
if (isset($value) && !isset($this->original[$name])) {
$this->original[$name] = $value;
}
if (isset($this->original[$name])) {
return $this->original[$name];
}
}
/**
* @todo
*/
function presave($form, &$form_state) {
if ($this->delta->mode == DELTA_PRESERVE) {
$base = array();
if (!empty($this->delta->parent)) {
if ($plugin = delta_get_plugin($this->delta->parent, $this->plugin['name'])) {
foreach ($this->variables() as $variable) {
$base[$variable] = $plugin->config($variable);
}
}
}
foreach ($this->variables() as $variable) {
if (isset($base[$variable])) {
$this->delta->settings[$variable] = delta_reduce($this->delta->settings[$variable], $base[$variable]);
}
else {
$this->delta->settings[$variable] = delta_reduce(
is_array($this->delta->settings[$variable]) ? $this->delta->settings[$variable] : array(),
is_array(variable_get($variable)) ? variable_get($variable) : array());
}
}
}
}
/**
* @todo
*/
function form_alter(&$form, &$form_state) {
// Nothing to do here.
}
/**
* @todo
*/
function form_validate($form, &$form_state) {
foreach ($this->variables() as $name) {
$this->backup($name, variable_get($name));
}
}
/**
* @todo
*/
function form_submit($form, &$form_state) {
foreach ($this->variables() as $name) {
$this->delta->settings[$name] = variable_get($name);
variable_set($name, $this->backup($name));
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
class delta_injection_theme_settings extends delta_injection {
/**
* @todo
*/
function variables() {
return array('theme_' . $this->delta->theme . '_settings');
}
/**
* @todo
*/
function inject() {
$cache = &drupal_static('theme_get_setting');
$cache[$this->delta->theme] = NULL;
parent::inject();
}
/**
* @todo
*/
function revoke() {
$cache = &drupal_static('theme_get_setting');
$cache[$this->delta->theme] = NULL;
parent::revoke();
}
}