You are here

public function GroupEditForm::submitForm in Context groups 8.2

Same name and namespace in other branches
  1. 8 src/Form/GroupEditForm.php \Drupal\context_groups\Form\GroupEditForm::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

src/Form/GroupEditForm.php, line 145

Class

GroupEditForm
Class GroupEditForm.

Namespace

Drupal\context_groups\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Load current context.
  $cid = $form_state
    ->getValue('context_id');
  $context = $this->entityTypeManager
    ->getStorage('context')
    ->load($cid);
  $context_groups = $context
    ->getThirdPartySettings('context_groups');
  $data = $context_groups[$form_state
    ->getValue('name')];

  // Update context group settings.
  $data['label'] = $form_state
    ->getValue('group_name');
  $data['class'] = $form_state
    ->getValue('class');

  // Save group to context.
  $context
    ->setThirdPartySetting('context_groups', $form_state
    ->getValue('name'), $data);

  // Save context.
  $context
    ->save();
}