Loading src/Controller/CustomElementsController.php +22 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\custom_elements\CustomElement; use Drupal\custom_elements\CustomElementGeneratorTrait; use Drupal\node\NodeInterface; use Symfony\Component\Routing\Exception\InvalidParameterException; /** Loading Loading @@ -72,6 +73,27 @@ class CustomElementsController { return $custom_element; } /** * Renders entity revision into custom elements. * * @param \Drupal\node\NodeInterface $node_revision * The node revision. * @param string $view_mode * (optional) The view mode to use. Defaults to 'full'. * * @return \Drupal\custom_elements\CustomElement * * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function nodeViewRevision(NodeInterface $node_revision, $view_mode = 'full') { // Generate custom elements and let the custom elements renderer into the // right serialization. $custom_element = $this->getCustomElementGenerator()->generate($node_revision, $view_mode); // Make sure the cache tag is set. $custom_element->addCacheTags(['node_view']); return $custom_element; } /** * Controller for the '/node' route. */ Loading src/CustomElementsMetatagsGenerator.php +1 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ class CustomElementsMetatagsGenerator { foreach ($metatag_values['#attributes'] as $value) { if (in_array($value, $blacklisted_metatags[$metatag_values['#tag']])) { $blacklisted = TRUE; break; } } } Loading src/CustomElementsMetatagsGeneratorTrait.php +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ trait CustomElementsMetatagsGeneratorTrait { * * @return $this */ public function setCeMetagasGenerator(CustomElementsMetatagsGenerator $ceMetatagsGenerator): static { public function setCeMetagasGenerator(CustomElementsMetatagsGenerator $ceMetatagsGenerator) : self { $this->ceMetatagsGenerator = $ceMetatagsGenerator; return $this; } Loading src/CustomElementsRenderer.php +1 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Cache\CacheableJsonResponse; use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\Controller\TitleResolverInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\PageCache\ResponsePolicy\KillSwitch; Loading src/EventSubscriber/CustomElementsRouteSubscriber.php +20 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,26 @@ class CustomElementsRouteSubscriber extends RouteSubscriberBase { $ce_route = clone $route; $ce_route->setRequirement('_format', 'custom_elements'); $ce_route->setDefault('_controller', '\Drupal\lupus_ce_renderer\Controller\CustomElementsController::entityPreview'); $collection->add('custom_elements.entity.node.preview.', $ce_route); $collection->add('custom_elements.entity.node.preview', $ce_route); // Provide a CE variant of the node revision route. $route = $collection->get('entity.node.revision'); $ce_route = clone $route; $ce_route->setRequirement('_format', 'custom_elements'); $ce_route->setDefault('_controller', '\Drupal\lupus_ce_renderer\Controller\CustomElementsController::nodeViewRevision'); $collection->add('custom_elements.entity.node.revision', $ce_route); // Provide a CE variant of the node latest version route. // @see \Drupal\content_moderation\Entity\Routing\EntityModerationRouteProvider if ($route = $collection->get('entity.node.latest_version')) { $ce_route = clone $route; $ce_route->setRequirement('_format', 'custom_elements'); // Replace '_entity_view' with a custom elements controller. $ce_route_defaults = $ce_route->getDefaults(); unset($ce_route_defaults['_entity_view']); $ce_route->setDefaults($ce_route_defaults); // Re-use the entity.node.canonical route with latest node as parameter. $ce_route->setDefault('_controller', '\Drupal\lupus_ce_renderer\Controller\CustomElementsController::entityView'); $collection->add('custom_elements.entity.node.latest_version', $ce_route); } } /** Loading Loading
src/Controller/CustomElementsController.php +22 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\custom_elements\CustomElement; use Drupal\custom_elements\CustomElementGeneratorTrait; use Drupal\node\NodeInterface; use Symfony\Component\Routing\Exception\InvalidParameterException; /** Loading Loading @@ -72,6 +73,27 @@ class CustomElementsController { return $custom_element; } /** * Renders entity revision into custom elements. * * @param \Drupal\node\NodeInterface $node_revision * The node revision. * @param string $view_mode * (optional) The view mode to use. Defaults to 'full'. * * @return \Drupal\custom_elements\CustomElement * * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function nodeViewRevision(NodeInterface $node_revision, $view_mode = 'full') { // Generate custom elements and let the custom elements renderer into the // right serialization. $custom_element = $this->getCustomElementGenerator()->generate($node_revision, $view_mode); // Make sure the cache tag is set. $custom_element->addCacheTags(['node_view']); return $custom_element; } /** * Controller for the '/node' route. */ Loading
src/CustomElementsMetatagsGenerator.php +1 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ class CustomElementsMetatagsGenerator { foreach ($metatag_values['#attributes'] as $value) { if (in_array($value, $blacklisted_metatags[$metatag_values['#tag']])) { $blacklisted = TRUE; break; } } } Loading
src/CustomElementsMetatagsGeneratorTrait.php +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ trait CustomElementsMetatagsGeneratorTrait { * * @return $this */ public function setCeMetagasGenerator(CustomElementsMetatagsGenerator $ceMetatagsGenerator): static { public function setCeMetagasGenerator(CustomElementsMetatagsGenerator $ceMetatagsGenerator) : self { $this->ceMetatagsGenerator = $ceMetatagsGenerator; return $this; } Loading
src/CustomElementsRenderer.php +1 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Cache\CacheableJsonResponse; use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\Controller\TitleResolverInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\PageCache\ResponsePolicy\KillSwitch; Loading
src/EventSubscriber/CustomElementsRouteSubscriber.php +20 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,26 @@ class CustomElementsRouteSubscriber extends RouteSubscriberBase { $ce_route = clone $route; $ce_route->setRequirement('_format', 'custom_elements'); $ce_route->setDefault('_controller', '\Drupal\lupus_ce_renderer\Controller\CustomElementsController::entityPreview'); $collection->add('custom_elements.entity.node.preview.', $ce_route); $collection->add('custom_elements.entity.node.preview', $ce_route); // Provide a CE variant of the node revision route. $route = $collection->get('entity.node.revision'); $ce_route = clone $route; $ce_route->setRequirement('_format', 'custom_elements'); $ce_route->setDefault('_controller', '\Drupal\lupus_ce_renderer\Controller\CustomElementsController::nodeViewRevision'); $collection->add('custom_elements.entity.node.revision', $ce_route); // Provide a CE variant of the node latest version route. // @see \Drupal\content_moderation\Entity\Routing\EntityModerationRouteProvider if ($route = $collection->get('entity.node.latest_version')) { $ce_route = clone $route; $ce_route->setRequirement('_format', 'custom_elements'); // Replace '_entity_view' with a custom elements controller. $ce_route_defaults = $ce_route->getDefaults(); unset($ce_route_defaults['_entity_view']); $ce_route->setDefaults($ce_route_defaults); // Re-use the entity.node.canonical route with latest node as parameter. $ce_route->setDefault('_controller', '\Drupal\lupus_ce_renderer\Controller\CustomElementsController::entityView'); $collection->add('custom_elements.entity.node.latest_version', $ce_route); } } /** Loading