You are here

public function ConfigForm::submitForm in Taxonomy Access Control Lite 8

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 ConfigFormBase::submitForm

File

src/Form/ConfigForm.php, line 82

Class

ConfigForm
Builds the configuration form.

Namespace

Drupal\tac_lite\Form

Code

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

  // Clear the cache if new schemes are created/deleted, so that tabs are correctly displayed/removed.
  if ($this
    ->config('tac_lite.settings')
    ->get('tac_lite_schemes') != $form_state
    ->getValue('tac_lite_schemes')) {
    \Drupal::cache('render')
      ->deleteAll();
  }

  // Change configuration.
  $this
    ->config('tac_lite.settings')
    ->set('tac_lite_categories', $form_state
    ->getValue('tac_lite_categories'))
    ->set('tac_lite_schemes', $form_state
    ->getValue('tac_lite_schemes'))
    ->save();

  // Rebuild the node_access table.
  $rebuild = $form_state
    ->getValue('tac_lite_rebuild');
  if ($rebuild) {
    node_access_rebuild(TRUE);
  }
  else {
    $this
      ->messenger()
      ->addWarning($this
      ->t('Do not forget to <a href=:url>rebuild node access permissions </a> after you have configured taxonomy-based access.', [
      ':url' => Url::fromRoute('node.configure_rebuild_confirm')
        ->toString(),
    ]));
  }

  // And rebuild menus, in case the number of schemes has changed.
  \Drupal::service('router.builder')
    ->rebuild();
  parent::submitForm($form, $form_state);
}