You are here

public function GroupDeleteForm::submitForm in Context groups 8

Same name and namespace in other branches
  1. 8.2 src/Form/GroupDeleteForm.php \Drupal\context_groups\Form\GroupDeleteForm::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/GroupDeleteForm.php, line 115

Class

GroupDeleteForm
Class GroupDeleteForm.

Namespace

Drupal\context_groups\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this->context
    ->unsetThirdPartySetting('context_groups', $this->contextGroup['name']);

  // If this group was parent of another group or block, update it's parent.
  // Check groups.
  $list_of_groups = $this->context
    ->getThirdPartySettings('context_groups');
  foreach ($list_of_groups as $group) {
    if ($group['parent'] == $this->contextGroup['name']) {
      $group['parent'] = '';
      $this->context
        ->setThirdPartySetting('context_groups', $group['name'], $group);
    }
  }

  // Check blocks in context.
  $blocks = $this->context
    ->getReactions()
    ->get('blocks');
  $list_of_blocks = $blocks
    ->getBlocks();
  foreach ($list_of_blocks as $uid => $block_plugin) {
    $configuration = $block_plugin
      ->getConfiguration();
    if (isset($configuration['parent_wrapper']['parent']) && $configuration['parent_wrapper']['parent'] == $this->contextGroup['name']) {
      $configuration['parent_wrapper']['parent'] = '';
      $blocks
        ->updateBlock($uid, $configuration);
    }
  }
  $this->context
    ->save();
}