Loading context_stack.module +3 −2 Original line number Diff line number Diff line Loading @@ -16,8 +16,9 @@ use Drupal\Core\Entity\EntityInterface; function context_stack_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode) { $collection = ContextStackFactory::get()->createCollection(); $entity_type_id = $entity->getEntityTypeId(); $context = GenericEntityContext::fromEntity($entity, $entity->getEntityType()->getLabel()); $collection->addContext($context, $entity_type_id); $label = $entity->getEntityType()->getLabel(); $collection->addContext(GenericEntityContext::fromEntity($entity, $label), $entity_type_id); $collection->addContext(GenericEntityContext::fromEntity($entity, $label), 'entity'); $build['#context_stack']['view'] = $collection; // Add cacheability from the context stack to the render array. This is done // by temporarily adding the collection to the stack, fetch its calculated Loading src/EventSubscriber/ContextStackControllerWrapperSubscriber.php +13 −9 Original line number Diff line number Diff line Loading @@ -63,18 +63,22 @@ class ContextStackControllerWrapperSubscriber implements EventSubscriberInterfac */ public function onKernelController(ControllerEvent $event) { $arguments = $this->argumentResolver->getArguments($event->getRequest(), $event->getController()); if (!isset($this->contextCollections['view'])) { $collection = $this->contextStackFactory->createCollection(); foreach ($arguments as $argument) { if ($argument instanceof EntityInterface) { $id = $argument->getEntityTypeId(); $label = $argument->getEntityType()->getLabel(); foreach ([$argument->getEntityTypeId(), 'entity'] as $id) { if (!$collection->hasContext($id)) { $collection->addContext(GenericEntityContext::fromEntity($argument, $argument->getEntityType()->getLabel()), $id); $collection->addContext(GenericEntityContext::fromEntity($argument, $label), $id); } } } if (!isset($this->contextCollections['view']) && $collection->getScope()) { } if ($collection->getScope()) { $this->contextCollections['view'] = $collection; } } if (!isset($this->contextCollections['account']) && ($user = \Drupal::entityTypeManager()->getStorage('user')->load(\Drupal::currentUser()->id()))) { $collection = $this->contextStackFactory->createCollection(); Loading Loading
context_stack.module +3 −2 Original line number Diff line number Diff line Loading @@ -16,8 +16,9 @@ use Drupal\Core\Entity\EntityInterface; function context_stack_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode) { $collection = ContextStackFactory::get()->createCollection(); $entity_type_id = $entity->getEntityTypeId(); $context = GenericEntityContext::fromEntity($entity, $entity->getEntityType()->getLabel()); $collection->addContext($context, $entity_type_id); $label = $entity->getEntityType()->getLabel(); $collection->addContext(GenericEntityContext::fromEntity($entity, $label), $entity_type_id); $collection->addContext(GenericEntityContext::fromEntity($entity, $label), 'entity'); $build['#context_stack']['view'] = $collection; // Add cacheability from the context stack to the render array. This is done // by temporarily adding the collection to the stack, fetch its calculated Loading
src/EventSubscriber/ContextStackControllerWrapperSubscriber.php +13 −9 Original line number Diff line number Diff line Loading @@ -63,18 +63,22 @@ class ContextStackControllerWrapperSubscriber implements EventSubscriberInterfac */ public function onKernelController(ControllerEvent $event) { $arguments = $this->argumentResolver->getArguments($event->getRequest(), $event->getController()); if (!isset($this->contextCollections['view'])) { $collection = $this->contextStackFactory->createCollection(); foreach ($arguments as $argument) { if ($argument instanceof EntityInterface) { $id = $argument->getEntityTypeId(); $label = $argument->getEntityType()->getLabel(); foreach ([$argument->getEntityTypeId(), 'entity'] as $id) { if (!$collection->hasContext($id)) { $collection->addContext(GenericEntityContext::fromEntity($argument, $argument->getEntityType()->getLabel()), $id); $collection->addContext(GenericEntityContext::fromEntity($argument, $label), $id); } } } if (!isset($this->contextCollections['view']) && $collection->getScope()) { } if ($collection->getScope()) { $this->contextCollections['view'] = $collection; } } if (!isset($this->contextCollections['account']) && ($user = \Drupal::entityTypeManager()->getStorage('user')->load(\Drupal::currentUser()->id()))) { $collection = $this->contextStackFactory->createCollection(); Loading