You are here

public function ConfigForm::submitForm in Nodeaccess 8

Same name and namespace in other branches
  1. 8.2 src/Form/ConfigForm.php \Drupal\nodeaccess\Form\ConfigForm::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 ConfigFormBase::submitForm

File

src/Form/ConfigForm.php, line 203

Class

ConfigForm
Builds the configuration form.

Namespace

Drupal\nodeaccess\Form

Code

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

  // Update configuration.
  $values = $form_state
    ->getValues();
  $node_types = NodeType::loadMultiple();
  $allowed_types = [];
  $settings = $this
    ->config('nodeaccess.settings')
    ->set('priority', $values['priority'])
    ->set('preserve', $values['preserve'])
    ->set('grants', $values['grants']);
  foreach ($node_types as $type => $bundle) {
    $config = $values[$type]['user_permissions'];
    $allowed_types[$type] = $values[$type]['show'];
    $settings
      ->set($type, $config);
  }
  $settings
    ->set('allowed_types', $allowed_types);

  // Save allowed roles, role aliases and weights.
  $settings
    ->set('role_alias', $values['role']['alias']);
  $settings
    ->save();
  node_access_needs_rebuild(TRUE);
  parent::submitForm($form, $form_state);
}