You are here

public function ContextListBuilder::submitForm in Context 8

Same name and namespace in other branches
  1. 8.4 modules/context_ui/src/ContextListBuilder.php \Drupal\context_ui\ContextListBuilder::submitForm()
  2. 8.0 modules/context_ui/src/ContextListBuilder.php \Drupal\context_ui\ContextListBuilder::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

modules/context_ui/src/ContextListBuilder.php, line 240

Class

ContextListBuilder

Namespace

Drupal\context_ui

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $contexts = $this->storage
    ->loadMultiple(array_keys($form_state
    ->getValue('contexts')));

  /*** @var ContextInterface $context */
  foreach ($contexts as $context_id => $context) {
    $context_values = $form_state
      ->getValue([
      'contexts',
      $context_id,
    ]);
    $context
      ->setWeight($context_values['weight']);

    // Not grouped contexts needs a specific group value.
    if ($context_values['group'] === 'not_grouped') {
      $context
        ->setGroup(Context::CONTEXT_GROUP_NONE);
    }
    else {
      $context
        ->setGroup($context_values['group']);
    }
    $context
      ->save();
  }
  drupal_set_message($this
    ->t('The context settings have been updated.'));
}