diff --git a/src/Hook/InputPatternHook.php b/src/Hook/InputPatternHook.php index d5673a6e98aaa52514f984fcd28d17f46b8c1d3f..02a358766495a696e14c98ab32698d965706f284 100644 --- a/src/Hook/InputPatternHook.php +++ b/src/Hook/InputPatternHook.php @@ -3,9 +3,12 @@ namespace Drupal\input_pattern\Hook; use Drupal\Component\Utility\Html; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Hook\Attribute\Hook; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\filter\FilterPluginManager; /** * Hook implementations for Input Pattern Hook. @@ -14,6 +17,34 @@ class InputPatternHook { use StringTranslationTrait; + /** + * Constructs a new PostlightParserService object. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler + * The module handler service. + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory + * The config factory service. + * @param \Drupal\filter\FilterPluginManager|null $filterPluginManager + * Filter plugin manager. + */ + public function __construct( + protected ModuleHandlerInterface $moduleHandler, + protected ConfigFactoryInterface $configFactory, + protected ?FilterPluginManager $filterPluginManager = NULL + ) { + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('module_handler'), + $container->get('config.factory'), + $container->get('plugin.manager.filter'), + ); + } + /** * Implements hook_help(). */ @@ -22,15 +53,14 @@ class InputPatternHook { switch ($route_name) { case 'help.page.input_pattern': $text = file_get_contents(__DIR__ . '/../../README.md'); - if (!\Drupal::moduleHandler()->moduleExists('markdown')) { + if (!$this->moduleHandler->moduleExists('markdown')) { return '<pre>' . Html::escape($text) . '</pre>'; } else { // Use the Markdown filter to render the README. - $filter_manager = \Drupal::service('plugin.manager.filter'); - $settings = \Drupal::configFactory()->get('markdown.settings')->getRawData(); + $settings = $this->configFactory->get('markdown.settings')->getRawData(); $config = ['settings' => $settings]; - $filter = $filter_manager->createInstance('markdown', $config); + $filter = $this->filterPluginManager->createInstance('markdown', $config); return $filter->process($text, 'en'); } diff --git a/src/Plugin/Field/FieldFormatter/ListAttributesFormatter.php b/src/Plugin/Field/FieldFormatter/ListAttributesFormatter.php index 177cca921d682c2bd477bc0730134613b6844159..95eca5786a7e4900f245dd90780536c34931dcc4 100644 --- a/src/Plugin/Field/FieldFormatter/ListAttributesFormatter.php +++ b/src/Plugin/Field/FieldFormatter/ListAttributesFormatter.php @@ -144,7 +144,8 @@ class ListAttributesFormatter extends FormatterBase { $render_as_link = FALSE; if ($this->getSetting('link_to_entity') && !$entity->isNew() && $entity_type->hasLinkTemplate('canonical')) { - $url = $this->getEntityUrl($entity); + $rel = $entity->getEntityType()->hasLinkTemplate('revision') ? 'revision' : 'canonical'; + $url = $entity->toUrl($rel); $access = $url->access(return_as_object: TRUE); (new CacheableMetadata())->addCacheableDependency($access)->applyTo($elements); $render_as_link = $access->isAllowed();