You are here

function content_access_user_admin_perm_submit in Content Access 8

Same name and namespace in other branches
  1. 6 content_access.admin.inc \content_access_user_admin_perm_submit()
  2. 7 content_access.admin.inc \content_access_user_admin_perm_submit()

Submit callback for the user permissions form.

Trigger changes to node permissions to rebuild our grants.

1 string reference to 'content_access_user_admin_perm_submit'
content_access_form_alter in ./content_access.module
Implements hook_form_alter().

File

./content_access.module, line 799
Content access module file.

Code

function content_access_user_admin_perm_submit($form, FormStateInterface $form_state) {

  // Check for each content type, which has per node access activated
  // whether permissions have been changed.
  $types = [];
  foreach (array_filter(content_access_get_settings('per_node', 'all')) as $type => $value) {
    foreach (_content_access_get_node_permissions($type) as $perm) {
      foreach (user_roles() as $rid => $role) {
        $values = $form_state
          ->getValues();
        if (isset($values[$rid]) && in_array($perm, $form['checkboxes'][$rid]['#default_value']) != in_array($perm, $values[$rid])) {

          // Permission changed.
          $types[$type] = node_type_get_names();
          continue 2;
        }
      }
    }
  }
  if ($types && content_access_mass_update(array_keys($types))) {
    \Drupal::messenger()
      ->addMessage(\Drupal::translation()
      ->formatPlural(count($types), 'Permissions have been successfully rebuilt for the content type @types.', 'Permissions have been successfully rebuilt for the content types @types.', [
      '@types' => implode(', ', $types),
    ]));
  }
}