function permissions_by_term_submit in Permissions by Term 8.2
Same name and namespace in other branches
- 8 permissions_by_term.module \permissions_by_term_submit()
- 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'
File
- ./
permissions_by_term.module, line 90 - 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;
}
}
if (\Drupal::configFactory()
->getEditable('permissions_by_term.settings')
->get('disable_node_access_records')) {
$rebuild_cache_and_node_access = false;
}
// Do we need to flush the cache and the node access records?
if ($rebuild_cache_and_node_access === true) {
/**
* @var \Drupal\permissions_by_term\Service\NodeAccess $nodeAccess
*/
$nodeAccess = \Drupal::service('permissions_by_term.node_access');
$nodeAccess
->rebuildAccess();
/**
* @var \Drupal\permissions_by_term\Cache\CacheInvalidator $cacheInvalidator
*/
$cacheInvalidator = \Drupal::service('permissions_by_term.cache_invalidator');
$cacheInvalidator
->invalidate();
}
}