Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / permissions_by_term / modules / permissions_by_entity / src / EventSubscriber / PermissionsByEntityKernelEventSubscriber.php
index 49dacf515861625f92330513351647897327042c..5d643ac366ba40ff95529b7f109ab1e905893afb 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace Drupal\permissions_by_entity\EventSubscriber;
 
-use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\Core\Entity\FieldableEntityInterface;
 use Drupal\Core\StringTranslation\TranslationInterface;
 use Drupal\permissions_by_entity\Service\AccessCheckerInterface;
 use Drupal\permissions_by_entity\Service\CheckedEntityCache;
@@ -61,10 +61,15 @@ class PermissionsByEntityKernelEventSubscriber implements EventSubscriberInterfa
 
   /**
    * {@inheritdoc}
+   *
+   * @see DynamicPageCacheSubscriber
+   *
+   * This is required to run before the DynamicPageCacheSubscriber as otherwise
+   * the response would be cached which can lead to false access.
    */
   public static function getSubscribedEvents() {
     return [
-      KernelEvents::REQUEST => ['onKernelRequest', 5],
+      KernelEvents::REQUEST => ['onKernelRequest', 28],
     ];
   }
 
@@ -79,7 +84,7 @@ class PermissionsByEntityKernelEventSubscriber implements EventSubscriberInterfa
     $request = $event->getRequest();
 
     // Get the entity.
-    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
+    /** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
     $entity = NULL;
     if ($request->attributes->has('node')) {
       $entity = $request->attributes->get('node');
@@ -89,7 +94,7 @@ class PermissionsByEntityKernelEventSubscriber implements EventSubscriberInterfa
     }
 
     // If there is no entity abort here.
-    if (!$entity) {
+    if (!$entity instanceof FieldableEntityInterface) {
       return;
     }
 
@@ -97,14 +102,13 @@ class PermissionsByEntityKernelEventSubscriber implements EventSubscriberInterfa
     if ($this->checkedEntityCache->isChecked($entity)) {
       return;
     }
-    else {
-      // Add this entity to the cache.
-      $this->checkedEntityCache->add($entity);
-    }
+
+    // Add this entity to the cache.
+    $this->checkedEntityCache->add($entity);
 
     // Check if the current user is allowed to access this entity.
     if (
-      $entity && $entity instanceof ContentEntityInterface &&
+      $entity && $entity instanceof FieldableEntityInterface &&
       !$this->accessChecker->isAccessAllowed($entity)
     ) {