X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fmodules%2Fcontrib%2Fpermissions_by_term%2Fmodules%2Fpermissions_by_entity%2Fsrc%2FEventSubscriber%2FPermissionsByEntityKernelEventSubscriber.php;fp=web%2Fmodules%2Fcontrib%2Fpermissions_by_term%2Fmodules%2Fpermissions_by_entity%2Fsrc%2FEventSubscriber%2FPermissionsByEntityKernelEventSubscriber.php;h=5d643ac366ba40ff95529b7f109ab1e905893afb;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=49dacf515861625f92330513351647897327042c;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/web/modules/contrib/permissions_by_term/modules/permissions_by_entity/src/EventSubscriber/PermissionsByEntityKernelEventSubscriber.php b/web/modules/contrib/permissions_by_term/modules/permissions_by_entity/src/EventSubscriber/PermissionsByEntityKernelEventSubscriber.php index 49dacf515..5d643ac36 100644 --- a/web/modules/contrib/permissions_by_term/modules/permissions_by_entity/src/EventSubscriber/PermissionsByEntityKernelEventSubscriber.php +++ b/web/modules/contrib/permissions_by_term/modules/permissions_by_entity/src/EventSubscriber/PermissionsByEntityKernelEventSubscriber.php @@ -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) ) {