View source
<?php
function spaces_context_load_alter(&$context) {
$space = spaces_get_space();
if ($space) {
foreach (array_keys(context_reactions()) as $plugin) {
$override = $space->controllers->context
->get("{$context->name}:reaction:{$plugin}");
if (!is_null($override)) {
$context->reactions[$plugin] = $override;
}
}
}
}
function spaces_form_system_site_information_settings_alter(&$form, &$form_state) {
$form['front_page']['site_frontpage']['#disabled'] = TRUE;
$form['front_page']['site_frontpage']['#value'] = $form['front_page']['site_frontpage']['#default_value'];
$form['front_page']['site_frontpage']['#description'] = t('The front page is controlled by the spaces module and can be set !link.', array(
'!link' => l(t('here'), 'features'),
));
}
function spaces_form_context_ui_editor_alter(&$form, &$form_state) {
$space = spaces_get_space();
if ($space && isset($form['buttons']['save']['#submit'])) {
$form['buttons']['save']['#submit'] = array(
'spaces_context_ui_editor_submit',
);
if (isset($form['contexts'])) {
foreach (element_children($form['contexts']) as $context) {
if (isset($form['contexts'][$context]['reaction-block']['layout'])) {
$form['contexts'][$context]['reaction-block']['layout']['update']['#submit'] = array(
'spaces_context_ui_editor_submit',
);
}
}
}
}
}
function spaces_context_ui_editor_submit(&$form, &$form_state) {
$space = spaces_get_space();
if ($space) {
$saved = FALSE;
foreach ($form_state['values']['contexts'] as $name => $values) {
$original = clone $values['context'];
$context = context_ui_editor_process($values);
foreach (array_keys(context_conditions(TRUE)) as $condition) {
if ($context->conditions[$condition] != $original->conditions[$condition]) {
$space->controllers->context
->set("{$context->name}:condition:{$condition}", $context->conditions[$condition]);
$saved = TRUE;
}
}
foreach (array_keys(context_reactions(TRUE)) as $reaction) {
if ($context->reactions[$reaction] != $original->reactions[$reaction]) {
$space->controllers->context
->set("{$context->name}:reaction:{$reaction}", $context->reactions[$reaction]);
$saved = TRUE;
}
}
}
if ($saved) {
drupal_set_message(t('Saved %title for %space.', array(
'%title' => !empty($context->description) ? $context->description : $context->name,
'%space' => $space
->title(),
)));
}
}
}
function spaces_form_system_modules_alter(&$form, &$form_state) {
$form['#submit'][] = 'spaces_form_system_modules_submit';
}
function spaces_form_system_modules_submit($form, &$form_state) {
cache_clear_all('spaces_types', 'cache');
}
function spaces_form_alter(&$form, &$form_state, $form_id) {
if ($space = spaces_get_space()) {
if (!empty($form['#submit'])) {
$position = array_search('system_settings_form_submit', $form['#submit'], TRUE);
if ($position !== FALSE) {
$form['#submit'][$position] = 'spaces_system_settings_form_submit';
if (count(element_children($form['buttons'])) == 2 && spaces_access_admin_perms(array(
'administer spaces',
))) {
if ($preset = $space->controllers->variable
->get('spaces_preset_' . $space->type)) {
$preset = spaces_preset_load($preset, $space->type);
$form['buttons']['preset'] = array(
'#type' => 'submit',
'#value' => t('Save to @title', array(
'@title' => $preset->title,
)),
);
$form['buttons']['submit']['#value'] = t('Save for @name', array(
'@name' => $space
->title(),
));
$form['buttons']['reset']['#weight'] = 100;
}
}
}
}
$form['#space'] = array(
'#type' => 'value',
'#value' => $space->type . ':' . $space->id,
);
}
}
function spaces_system_settings_form_submit($form, &$form_state) {
if ($space = spaces_get_space()) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['preset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token'], $form_state['values']['form_build_id']);
if ($preset = $space->controllers->variable
->get('spaces_preset_' . $space->type)) {
$preset = spaces_preset_load($preset, $space->type);
}
foreach ($form_state['values'] as $key => $value) {
if ($op == t('Reset to defaults')) {
$space->controllers->variable
->del($key);
}
elseif ($preset && $op == t('Save to @title', array(
'@title' => $preset->title,
))) {
$space->controllers->variable
->del($key);
$preset->value['variable'][$key] = $value;
}
else {
if (is_array($value) && isset($form_state['values']['array_filter'])) {
$value = array_keys(array_filter($value));
}
$space->controllers->variable
->set($key, $value);
}
}
if ($op == t('Reset to defaults')) {
drupal_set_message(t('The configuration options have been reset to their default values for %space.', array(
'%space' => $space
->title(),
)));
}
elseif ($preset && $op == t('Save to @title', array(
'@title' => $preset->title,
))) {
drupal_set_message(t('The configuration options have been saved for %title.', array(
'%title' => $preset->title,
)));
spaces_preset_save($preset);
}
else {
drupal_set_message(t('The configuration options have been saved for %space.', array(
'%space' => $space
->title(),
)));
}
}
}