Loading component_library.services.yml +4 −0 Original line number Diff line number Diff line Loading @@ -101,3 +101,7 @@ services: class: Drupal\component_library\EventSubscriber\VariablesPlaceholderConfigEntity tags: - { name: event_subscriber } component_library.variables_placeholder.url: class: Drupal\component_library\EventSubscriber\VariablesPlaceholderUrl tags: - { name: event_subscriber } src/EventSubscriber/VariablesPlaceholderUrl.php 0 → 100644 +56 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\component_library\EventSubscriber; use Drupal\component_library\Event\AddVariablesPlaceholderEvent; use Drupal\component_library\Event\ReplaceVariablesPlaceholderEvent; use Drupal\Core\Url; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Override mode config entity variable placeholders. */ final class VariablesPlaceholderUrl implements EventSubscriberInterface { /** * {@inheritdoc} */ public static function getSubscribedEvents(): array { $events = []; $events[AddVariablesPlaceholderEvent::class][] = ['onAddVariablesPlaceholder']; $events[ReplaceVariablesPlaceholderEvent::class][] = ['onReplaceVariablesPlaceholderEvent']; return $events; } public function onAddVariablesPlaceholder(AddVariablesPlaceholderEvent $event): void { $item = $event->getItem(); if ($item instanceof Url) { if ($item->isRouted()) { $event->setPlaceholder([ '#override_mode' => [ '#type' => 'override_url', '#url_parts' => [ 'route_name' => $item->getRouteName(), 'route_parameters' => $item->getRouteParameters(), 'options' => $item->getOptions(), ], ], ]); } } } public function onReplaceVariablesPlaceholderEvent(ReplaceVariablesPlaceholderEvent $event): void { $config = $event->getConfig(); if (isset($config['#url_parts']) && $config['#type'] == 'override_url') { $event->setReplacement(new Url( $config['#url_parts']['route_name'], $config['#url_parts']['route_parameters'], $config['#url_parts']['options'], )); } } } Loading
component_library.services.yml +4 −0 Original line number Diff line number Diff line Loading @@ -101,3 +101,7 @@ services: class: Drupal\component_library\EventSubscriber\VariablesPlaceholderConfigEntity tags: - { name: event_subscriber } component_library.variables_placeholder.url: class: Drupal\component_library\EventSubscriber\VariablesPlaceholderUrl tags: - { name: event_subscriber }
src/EventSubscriber/VariablesPlaceholderUrl.php 0 → 100644 +56 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\component_library\EventSubscriber; use Drupal\component_library\Event\AddVariablesPlaceholderEvent; use Drupal\component_library\Event\ReplaceVariablesPlaceholderEvent; use Drupal\Core\Url; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Override mode config entity variable placeholders. */ final class VariablesPlaceholderUrl implements EventSubscriberInterface { /** * {@inheritdoc} */ public static function getSubscribedEvents(): array { $events = []; $events[AddVariablesPlaceholderEvent::class][] = ['onAddVariablesPlaceholder']; $events[ReplaceVariablesPlaceholderEvent::class][] = ['onReplaceVariablesPlaceholderEvent']; return $events; } public function onAddVariablesPlaceholder(AddVariablesPlaceholderEvent $event): void { $item = $event->getItem(); if ($item instanceof Url) { if ($item->isRouted()) { $event->setPlaceholder([ '#override_mode' => [ '#type' => 'override_url', '#url_parts' => [ 'route_name' => $item->getRouteName(), 'route_parameters' => $item->getRouteParameters(), 'options' => $item->getOptions(), ], ], ]); } } } public function onReplaceVariablesPlaceholderEvent(ReplaceVariablesPlaceholderEvent $event): void { $config = $event->getConfig(); if (isset($config['#url_parts']) && $config['#type'] == 'override_url') { $event->setReplacement(new Url( $config['#url_parts']['route_name'], $config['#url_parts']['route_parameters'], $config['#url_parts']['options'], )); } } }