You are here

public function ContentAccessPageForm::submitForm in Content Access 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 FormInterface::submitForm

File

src/Form/ContentAccessPageForm.php, line 159

Class

ContentAccessPageForm
Node Access settings form.

Namespace

Drupal\content_access\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $settings = [];
  $storage = $form_state
    ->getStorage();
  $values = $form_state
    ->getValues();
  $node = $storage['node'];
  foreach (_content_access_get_operations() as $op => $label) {

    // Set the settings so that further calls will return this settings.
    $filtered_values = array_filter($values[$op]);
    $settings[$op] = array_keys($filtered_values);
  }

  // Save per-node settings.
  content_access_save_per_node_settings($node, $settings);
  if ($this->moduleHandler
    ->moduleExists('acl')) {
    foreach ([
      'view',
      'update',
      'delete',
    ] as $op) {
      $values = $form_state
        ->getValues();
      acl_save_form($values['acl'][$op]);
      $this->moduleHandler
        ->invokeAll('user_acl', $settings);
    }
  }

  // Apply new settings.
  $grants = $this->entityTypeManager
    ->getAccessControlHandler('node')
    ->acquireGrants($node);
  $this->grantStorage
    ->write($node, $grants);
  $this->moduleHandler
    ->invokeAll('per_node', $settings);
  foreach (Cache::getBins() as $cache_backend) {
    $cache_backend
      ->deleteAll();
  }

  // xxxx
  // route: node.configure_rebuild_confirm:
  // path:  '/admin/reports/status/rebuild'.
  $this
    ->messenger()
    ->addMessage($this
    ->t('Your changes have been saved. You may have to <a href=":rebuild">rebuild permissions</a> for your changes to take effect.', [
    ':rebuild' => Url::fromRoute('node.configure_rebuild_confirm')
      ->toString(),
  ]));
}