diff core/modules/taxonomy/src/TermAccessControlHandler.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
line wrap: on
line diff
--- a/core/modules/taxonomy/src/TermAccessControlHandler.php	Tue Jul 10 15:07:59 2018 +0100
+++ b/core/modules/taxonomy/src/TermAccessControlHandler.php	Thu Feb 28 13:21:36 2019 +0000
@@ -18,19 +18,37 @@
    * {@inheritdoc}
    */
   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
+    if ($account->hasPermission('administer taxonomy')) {
+      return AccessResult::allowed()->cachePerPermissions();
+    }
+
     switch ($operation) {
       case 'view':
-        return AccessResult::allowedIfHasPermission($account, 'access content');
+        $access_result = AccessResult::allowedIf($account->hasPermission('access content') && $entity->isPublished())
+          ->cachePerPermissions()
+          ->addCacheableDependency($entity);
+        if (!$access_result->isAllowed()) {
+          $access_result->setReason("The 'access content' permission is required and the taxonomy term must be published.");
+        }
+        return $access_result;
 
       case 'update':
-        return AccessResult::allowedIfHasPermissions($account, ["edit terms in {$entity->bundle()}", 'administer taxonomy'], 'OR');
+        if ($account->hasPermission("edit terms in {$entity->bundle()}")) {
+          return AccessResult::allowed()->cachePerPermissions();
+        }
+
+        return AccessResult::neutral()->setReason("The following permissions are required: 'edit terms in {$entity->bundle()}' OR 'administer taxonomy'.");
 
       case 'delete':
-        return AccessResult::allowedIfHasPermissions($account, ["delete terms in {$entity->bundle()}", 'administer taxonomy'], 'OR');
+        if ($account->hasPermission("delete terms in {$entity->bundle()}")) {
+          return AccessResult::allowed()->cachePerPermissions();
+        }
+
+        return AccessResult::neutral()->setReason("The following permissions are required: 'delete terms in {$entity->bundle()}' OR 'administer taxonomy'.");
 
       default:
         // No opinion.
-        return AccessResult::neutral();
+        return AccessResult::neutral()->cachePerPermissions();
     }
   }