Пример отключения библиотеки core/drupal.active-link
на страницах нод:
modulename.services.yml
:
services:
modulename.subscriber:
class: Drupal\modulename\EventSubscriber\ModulenameSubscriber
tags:
- { name: event_subscriber }
src/EventSubscriber/ModulenameSubscriber.php
:
<?php
namespace Drupal\modulename\EventSubscriber;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ModulenameSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = ['onResponse', 10];
return $events;
}
public function onResponse(FilterResponseEvent $event) {
// @TODO Use DI without static class
if (\Drupal::routeMatch()->getRouteName() == 'entity.node.canonical') {
$response = $event->getResponse();
if (method_exists($response, 'getAttachments')) {
$attachments = $response->getAttachments();
$attachments['library'] = array_diff($attachments['library'], ['core/drupal.active-link']);
$response->setAttachments($attachments);
}
}
}
}
Написанное актуально для
Drupal 8
Комментарии
И еще добавить dependency injection в сервис:
modulename.services.yml
:src/EventSubscriber/ModulenameSubscriber.php
:Добавить комментарий