You are here

public function Blocks::submitConfigurationForm in Context 8.0

Same name and namespace in other branches
  1. 8.4 src/Plugin/ContextReaction/Blocks.php \Drupal\context\Plugin\ContextReaction\Blocks::submitConfigurationForm()
  2. 8 src/Plugin/ContextReaction/Blocks.php \Drupal\context\Plugin\ContextReaction\Blocks::submitConfigurationForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides PluginFormInterface::submitConfigurationForm

File

src/Plugin/ContextReaction/Blocks.php, line 583

Class

Blocks
Provides a content reaction that will let you place blocks in the current themes regions.

Namespace

Drupal\context\Plugin\ContextReaction

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  $blocks = $form_state
    ->getValue([
    'blocks',
    'blocks',
  ], []);
  if (is_array($blocks)) {
    foreach ($blocks as $block_id => $configuration) {
      $block = $this
        ->getBlock($block_id);
      $configuration += $block
        ->getConfiguration();
      $block_state = (new FormState())
        ->setValues($configuration);
      $block
        ->submitConfigurationForm($form, $block_state);

      // If the block is context aware then add context mapping to the block.
      if ($block instanceof ContextAwarePluginInterface) {
        $block
          ->setContextMapping($block_state
          ->getValue('context_mapping', []));
      }
      $this
        ->updateBlock($block_id, $block_state
        ->getValues());
    }
  }
}