summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--delta.install6
-rw-r--r--delta.module52
-rw-r--r--delta_ui/delta_ui.admin.inc20
-rw-r--r--plugins/context_reaction_delta.inc1
4 files changed, 58 insertions, 21 deletions
diff --git a/delta.install b/delta.install
index 1ee30cf..2f1a463 100644
--- a/delta.install
+++ b/delta.install
@@ -30,6 +30,12 @@ function delta_schema() {
'length' => 128,
'not null' => TRUE,
),
+ 'mode' => array(
+ 'description' => 'The mode that this template operrates in.',
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => TRUE,
+ ),
'settings' => array(
'description' => t('Serialized data which is a copy of the theme settings array stored in the system table based on these overrides'),
'type' => 'blob',
diff --git a/delta.module b/delta.module
index b93a40f..892d5a8 100644
--- a/delta.module
+++ b/delta.module
@@ -4,6 +4,11 @@
* @file Provide contextual theme settings via context module
*/
+define('DELTA_PRESERVE', 'preserve');
+define('DELTA_OVERRIDE', 'override');
+
+global $delta;
+
/**
* Implements hook_context_plugins().
*/
@@ -52,7 +57,7 @@ function delta_load($delta) {
if (!isset($cache[$delta])) {
$query = db_select('delta_theme_settings', 'dt')
- ->fields('dt', array('machine_name', 'name', 'theme', 'settings'))
+ ->fields('dt', array('machine_name', 'name', 'theme', 'mode', 'settings'))
->condition('machine_name', $delta)
->execute()
->fetchAll();
@@ -78,7 +83,10 @@ function delta_valid($delta, $key) {
function delta_inject_settings($delta, $key) {
global $conf;
- $conf['theme_' . $key . '_settings'] = delta_settings($delta, $key);
+ $cache = &drupal_static('theme_get_setting');
+ $cache[$key] = NULL;
+
+ return $conf['theme_' . $key . '_settings'] = delta_settings($delta, $key);
}
/**
@@ -97,8 +105,10 @@ function delta_layouts() {
*/
function delta_settings($delta, $key) {
$delta = delta_load($delta);
-
- return !empty($delta) ? unserialize($delta->settings) : delta_defaults($key);
+ $settings = $delta ? unserialize($delta->settings) : array();
+ $settings = isset($GLOBALS['conf']['theme_' . $key . '_settings']) ? array_merge($GLOBALS['conf']['theme_' . $key . '_settings'], $settings) : $settings;
+
+ return $settings;
}
/**
@@ -116,7 +126,27 @@ function delta_layout_options() {
/**
* @todo
*/
-function delta_save_settings($delta, $settings) {
+function delta_settings_prepare($settings, $original, $mode) {
+ if ($mode == DELTA_PRESERVE) {
+ foreach ($settings as $setting => $value) {
+ if (isset($original[$setting]) && $value === $original[$setting]) {
+ unset($settings[$setting]);
+ }
+ }
+ }
+ else {
+ $settings = array_merge($original, $settings);
+ }
+
+ return $settings;
+}
+
+/**
+ * @todo
+ */
+function delta_save_settings($delta, $settings, $original, $mode = DELTA_PRESERVE) {
+ $settings = delta_settings_prepare($settings, $original, $mode);
+
return db_update('delta_theme_settings')
->fields(array('settings' => serialize($settings)))
->condition('machine_name', $delta)
@@ -142,18 +172,6 @@ function delta_theme_options() {
/**
* @todo
*/
-function delta_defaults($theme) {
- // Fake theme_get_setting call for filling the static variable.
- theme_get_setting('logo', $theme);
-
- $settings = &drupal_static('theme_get_setting');
-
- return isset($settings[$theme]) ? $settings[$theme] : array();
-}
-
-/**
- * @todo
- */
function delta_save(&$item) {
if (!empty($item['old'])) {
drupal_write_record('delta_theme_settings', $item, 'machine_name');
diff --git a/delta_ui/delta_ui.admin.inc b/delta_ui/delta_ui.admin.inc
index 8931c7f..b14fdd0 100644
--- a/delta_ui/delta_ui.admin.inc
+++ b/delta_ui/delta_ui.admin.inc
@@ -59,7 +59,7 @@ function delta_ui_layout_edit($form, &$form_state, $layout = NULL) {
else {
drupal_set_title(t('Add Delta Layout'));
}
-
+
$form['old'] = array(
'#type' => 'value',
'#value' => $layout,
@@ -104,6 +104,17 @@ function delta_ui_layout_edit($form, &$form_state, $layout = NULL) {
'#disabled' => isset($layout),
);
+ $form['delta']['mode'] = array(
+ '#type' => 'radios',
+ '#title' => t('Operation mode'),
+ '#description' => t('This setting controls the way that settings are being stored and overriden.'),
+ '#default_value' => isset($layout) ? $layout->mode : (isset($form_state['values']['mode']) ? $form_state['values']['mode'] : DELTA_PRESERVE),
+ '#options' => array(
+ DELTA_PRESERVE => t('Only override different values'),
+ DELTA_OVERRIDE => t('Override all values'),
+ ),
+ );
+
$form['delta']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
@@ -119,8 +130,10 @@ function delta_ui_layout_edit($form, &$form_state, $layout = NULL) {
function delta_ui_layout_edit_submit($form, &$form_state) {
$values = $form_state['values'];
$themes = list_themes();
+ $settings = delta_settings($values['machine_name'], $values['theme']);
+ $original = isset($GLOBALS['conf']['theme_' . $values['theme'] . '_settings']) ? $GLOBALS['conf']['theme_' . $values['theme'] . '_settings'] : array();
- $values['settings'] = delta_settings($values['machine_name'], $values['theme']);
+ $values['settings'] = delta_settings_prepare($settings, $original, $values['mode']);
delta_save($values);
@@ -138,6 +151,7 @@ function delta_ui_layout_configure($form, &$form_state, $layout) {
delta_inject_settings($layout->machine_name, $layout->theme);
$form_state['delta'] = $layout->machine_name;
+ $form_state['delta_mode'] = $layout->mode;
$form_state['build_info']['args'][0] = $layout->theme;
$form = system_theme_settings($form, &$form_state, $layout->theme);
@@ -160,7 +174,7 @@ function delta_ui_layout_configure_submit($form, &$form_state) {
$backup = variable_get($key);
system_theme_settings_submit($form, &$form_state);
- delta_save_settings($form_state['delta'], variable_get($key));
+ delta_save_settings($form_state['delta'], variable_get($key), $backup, $form_state['delta_mode']);
variable_set($key, $backup);
}
diff --git a/plugins/context_reaction_delta.inc b/plugins/context_reaction_delta.inc
index f9f534b..9e90a6d 100644
--- a/plugins/context_reaction_delta.inc
+++ b/plugins/context_reaction_delta.inc
@@ -21,7 +21,6 @@ class context_reaction_delta extends context_reaction {
'#title' => t('Select Custom theme settings template.'),
'#default_value' => isset($values['delta']) ? $values['delta'] : '',
'#options' => $options,
- '#required' => TRUE,
);
return $form;