diff -u b/src/Plugin/Linkit/Matcher/EntityMatcher.php b/src/Plugin/Linkit/Matcher/EntityMatcher.php --- b/src/Plugin/Linkit/Matcher/EntityMatcher.php +++ b/src/Plugin/Linkit/Matcher/EntityMatcher.php @@ -23,6 +23,7 @@ use Drupal\linkit\Utility\LinkitXss; use Exception; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; /** * Provides default linkit matchers for all entity types. @@ -99,9 +100,16 @@ protected $substitutionManager; /** + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $currentRequest; + + /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityRepositoryInterface $entity_repository, ModuleHandlerInterface $module_handler, AccountInterface $current_user, SubstitutionManagerInterface $substitution_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityRepositoryInterface $entity_repository, ModuleHandlerInterface $module_handler, AccountInterface $current_user, SubstitutionManagerInterface $substitution_manager, Request $current_request) { parent::__construct($configuration, $plugin_id, $plugin_definition); if (empty($plugin_definition['target_entity'])) { @@ -115,6 +123,7 @@ $this->currentUser = $current_user; $this->targetType = $plugin_definition['target_entity']; $this->substitutionManager = $substitution_manager; + $this->currentRequest = $current_request; } /** @@ -131,7 +140,8 @@ $container->get('entity.repository'), $container->get('module_handler'), $container->get('current_user'), - $container->get('plugin.manager.linkit.substitution') + $container->get('plugin.manager.linkit.substitution'), + $container->get('request_stack')->getCurrentRequest() ); } @@ -531,8 +541,8 @@ try { $params = Url::fromUserInput($user_input)->getRouteParameters(); - if (key($params) === $this->targetType) { - $result = [end($params)]; + if (!empty($params[$this->targetType])) { + $result = [$params[$this->targetType]]; } } catch (Exception $e) {