You are here

function permissions_by_term_submit in Permissions by Term 8

Same name and namespace in other branches
  1. 8.2 permissions_by_term.module \permissions_by_term_submit()
  2. 7 permissions_by_term.module \permissions_by_term_submit()

Submit handler for permissions_by_term_form_alter().

1 string reference to 'permissions_by_term_submit'
permissions_by_term_form_taxonomy_term_form_alter in ./permissions_by_term.module
Implements hook_form_alter().

File

./permissions_by_term.module, line 85
Allows access to terms in a vocabulary to be limited by user or role.

Code

function permissions_by_term_submit($form, FormState $formState) {
  $termId = $formState
    ->getFormObject()
    ->getEntity()
    ->id();

  /* @var \Drupal\permissions_by_term\Service\AccessStorage $access_storage */
  $access_storage = \Drupal::service('permissions_by_term.access_storage');
  $access_update = $access_storage
    ->saveTermPermissions($formState, $termId);

  // Check if we need to rebuild cache and node_access
  $rebuild_cache_and_node_access = false;

  // Has anything has changed?
  foreach ($access_update as $values) {
    if (!empty($values)) {
      $rebuild_cache_and_node_access = true;
      break;
    }
  }

  // Do we need to flush the cache and the node access records?
  if ($rebuild_cache_and_node_access === true) {
    node_access_rebuild(TRUE);
    Cache::invalidateTags([
      'search_index:node_search',
    ]);
  }
}