core/core.services.yml | 5 - .../EventSubscriber/LinkRelationshipSubscriber.php | 130 --------------------- 2 files changed, 135 deletions(-) diff --git a/core/core.services.yml b/core/core.services.yml index 12041a8..24c6cca 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1090,11 +1090,6 @@ services: class: Drupal\Core\Render\BareHtmlPageRenderer arguments: ['@renderer', '@html_response.attachments_processor'] lazy: true - link_relationship_subscriber: - class: Drupal\Core\EventSubscriber\LinkRelationshipSubscriber - tags: - - { name: event_subscriber } - arguments: ['@entity.manager'] private_key: class: Drupal\Core\PrivateKey arguments: ['@state'] diff --git a/core/lib/Drupal/Core/EventSubscriber/LinkRelationshipSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/LinkRelationshipSubscriber.php deleted file mode 100644 index 919a10a..0000000 --- a/core/lib/Drupal/Core/EventSubscriber/LinkRelationshipSubscriber.php +++ /dev/null @@ -1,130 +0,0 @@ -entityManager = $entityManager; - } - - public function onKernelViewAddLinks(GetResponseForControllerResultEvent $event) { - $page = $event->getControllerResult(); - if ($page instanceof HtmlPage) { - $request = $event->getRequest(); - $route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME); - $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT); - - if ($entity_type = $this->getCanonicalEntity($route_name)) { - if ($entity = $this->getPrimaryEntity($route, $entity_type, $request)) { - $this->addLinks($entity, $page); - } - } - } - } - - /** - * Extracts the entity for which this route is the canonical path. - * - * @param Route $route - * The currently active route object. - * @param ContentEntityTypeInterface $entity_type - * The entity type definition for the entity whose canonical route we - * are on. - * @param Request $request - * The current request object. - * @return EntityInterface|null - * The primary entity for this canonical route, or null if none. - */ - protected function getPrimaryEntity(Route $route, ContentEntityTypeInterface $entity_type, Request $request) { - $parameter_definitions = $route->getOption('parameters'); - $entity_name = $entity_type->id(); - if (!empty($parameter_definitions[$entity_name])) { - return $request->attributes->get($entity_name); - } - } - - /** - * Adds link relationships to a page based on the primary object. - * - * @param EntityInterface $entity - * The entity from which to extract link relationships. - * @param HtmlPage $page - * the page object to enhance with relevant links. - */ - protected function addLinks(EntityInterface $entity, HtmlPage $page) { - foreach ($entity->uriRelationships() as $rel) { - $page->addLinkElement(new LinkElement($entity->url($rel), $rel)); - if ($rel == 'canonical') { - // Set the non-aliased canonical path as a default shortlink. - $page->addLinkElement(new LinkElement($entity->url($rel, ['alias' => TRUE]), 'shortlink')); - } - } - } - - /** - * Returns the entity whose canonical path we're currently on. - * - * @todo This method gets rewritten to look at the route name directly once - * we have standardized the route names for auto-generation. - * See https://drupal.org/node/2278567. That approach will also be faster - * than what is implemented here as it will not require any iteration. - * - * @param $route_name - * The route name that is currently being handled. - * @return ConfigEntityType|null - * The entity type definition for the entity, or null if we're not on - * an entity canonical route. - */ - protected function getCanonicalEntity($route_name) { - /* @var $definitions ContentEntityTypeInterface[] */ - $definitions = $this->entityManager->getDefinitions(); - foreach ($definitions as $type => $definition) { - if ($route_name == $definition->getLinkTemplate('canonical')) { - return $definition; - } - } - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - // In order to change the maintenance status an event subscriber with a - // priority between 30 and 40 should be added. - $events[KernelEvents::VIEW][] = array('onKernelViewAddLinks', 60); - return $events; - } - -} \ No newline at end of file