You are here

function context_reaction_block::editor_form_submit in Context 6.3

Same name and namespace in other branches
  1. 6 plugins/context_reaction_block.inc \context_reaction_block::editor_form_submit()
  2. 7.3 plugins/context_reaction_block.inc \context_reaction_block::editor_form_submit()

Submit handler context editor form.

1 call to context_reaction_block::editor_form_submit()
context_layouts_reaction_block::editor_form_submit in context_layouts/plugins/context_layouts_reaction_block.inc
Override of editor form submit.
1 method overrides context_reaction_block::editor_form_submit()
context_layouts_reaction_block::editor_form_submit in context_layouts/plugins/context_layouts_reaction_block.inc
Override of editor form submit.

File

plugins/context_reaction_block.inc, line 150

Class

context_reaction_block
Expose blocks as context reactions.

Code

function editor_form_submit(&$context, $values) {
  $edited = !empty($values['state']) ? (array) $this
    ->json_decode($values['state']) : array();
  $options = array();

  // Take the existing context values and remove blocks that belong affected regions.
  $affected_regions = array_keys($edited);
  if (!empty($context->reactions['block']['blocks'])) {
    $options = $context->reactions['block'];
    foreach ($options['blocks'] as $key => $block) {
      if (in_array($block['region'], $affected_regions)) {
        unset($options['blocks'][$key]);
      }
    }
  }

  // Iterate through blocks and add in the ones that belong to the context.
  foreach ($edited as $region => $blocks) {
    foreach ($blocks as $weight => $block) {
      if ($block->context === $context->name) {
        $split = explode('-', $block->bid);
        $options['blocks'][$block->bid] = array(
          'module' => array_shift($split),
          'delta' => implode('-', $split),
          'region' => $region,
          'weight' => $weight,
        );
      }
    }
  }
  return $options;
}