Skip to content
Snippets Groups Projects

Grants should be the default ones

Closed federico prato requested to merge issue/permissions_by_term-3308318:3308318-dev into 3.1.x-dev
1 file
+ 34
2
Compare changes
  • Side-by-side
  • Inline
+ 34
2
@@ -414,7 +414,8 @@ function permissions_by_term_node_access_records(NodeInterface $node) {
return NULL;
}
if (!$accessCheckService->isAnyTaxonomyTermFieldDefinedInNodeType($node->getType())) {
return NULL;
$grants = defaultGrants($node);
return $grants;
}
/**
@@ -423,7 +424,8 @@ function permissions_by_term_node_access_records(NodeInterface $node) {
$termHandler = \Drupal::service('permissions_by_term.term_handler');
if (!\Drupal::config('permissions_by_term.settings')->get('permission_mode') && empty($termHandler->getTidsByNid($node->id(), $node))) {
return NULL;
$grants = defaultGrants($node);
return $grants;
}
$isAnyPermissionSetForTerm = FALSE;
@@ -565,3 +567,33 @@ function permissions_by_term_taxonomy_term_delete(EntityInterface $entity) {
$cacheInvalidator = \Drupal::service('permissions_by_term.cache_invalidator');
$cacheInvalidator->invalidate();
}
/**
* Helper function to return default grants for a node.
*/
function defaultGrants($node) {
/**
* @var \Drupal\permissions_by_term\Service\NodeAccess $nodeAccess
*/
$nodeAccess = \Drupal::service('permissions_by_term.node_access');
$grantObject = $nodeAccess->createGrant($node->id(), $node->id());
$translations = $node->getTranslationLanguages(1);
$grants = [];
foreach ($translations as $id => $language) {
$translation = $node->getTranslation($id);
if ($translation->isPublished()) {
$grants[] = [
'langcode' => $id,
'realm' => 'all',
'gid' => 0,
'grant_view' => $grantObject->grant_view,
'grant_update' => $grantObject->grant_update,
'grant_delete' => $grantObject->grant_delete,
'nid' => $node->id(),
];
}
}
return $grants;
}
Loading