|
@@ -1,24 +1,31 @@
|
|
|
<?php
|
|
|
|
|
|
-/**
|
|
|
- * @file
|
|
|
- * Contains \Drupal\linkit\Plugin\Linkit\Matcher\EntityMatcher.
|
|
|
- */
|
|
|
-
|
|
|
namespace Drupal\linkit\Plugin\Linkit\Matcher;
|
|
|
|
|
|
use Drupal\Component\Utility\Html;
|
|
|
+use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
|
|
|
use Drupal\Core\Database\Connection;
|
|
|
-use Drupal\Core\Entity\EntityManagerInterface;
|
|
|
+use Drupal\Core\Entity\EntityInterface;
|
|
|
+use Drupal\Core\Entity\EntityRepositoryInterface;
|
|
|
+use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
|
|
+use Drupal\Core\Entity\EntityTypeManagerInterface;
|
|
|
+use Drupal\Core\Entity\Query\QueryInterface;
|
|
|
use Drupal\Core\Extension\ModuleHandlerInterface;
|
|
|
use Drupal\Core\Form\FormStateInterface;
|
|
|
use Drupal\Core\Session\AccountInterface;
|
|
|
+use Drupal\Core\Url;
|
|
|
use Drupal\linkit\ConfigurableMatcherBase;
|
|
|
use Drupal\linkit\MatcherTokensTrait;
|
|
|
+use Drupal\linkit\SubstitutionManagerInterface;
|
|
|
+use Drupal\linkit\Suggestion\EntitySuggestion;
|
|
|
+use Drupal\linkit\Suggestion\SuggestionCollection;
|
|
|
use Drupal\linkit\Utility\LinkitXss;
|
|
|
+use Exception;
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
|
|
/**
|
|
|
+ * Provides default linkit matchers for all entity types.
|
|
|
+ *
|
|
|
* @Matcher(
|
|
|
* id = "entity",
|
|
|
* label = @Translation("Entity"),
|
|
@@ -37,11 +44,25 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
protected $database;
|
|
|
|
|
|
/**
|
|
|
- * The entity manager.
|
|
|
+ * The entity type manager.
|
|
|
+ *
|
|
|
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
|
|
+ */
|
|
|
+ protected $entityTypeManager;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The entity type bundle info.
|
|
|
+ *
|
|
|
+ * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
|
|
+ */
|
|
|
+ protected $entityTypeBundleInfo;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The entity repository.
|
|
|
*
|
|
|
- * @var \Drupal\Core\Entity\EntityManagerInterface
|
|
|
+ * @var \Drupal\Core\Entity\EntityRepositoryInterface
|
|
|
*/
|
|
|
- protected $entityManager;
|
|
|
+ protected $entityRepository;
|
|
|
|
|
|
/**
|
|
|
* The module handler service.
|
|
@@ -58,26 +79,36 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
protected $currentUser;
|
|
|
|
|
|
/**
|
|
|
- * The target entity type id
|
|
|
+ * The target entity type ID.
|
|
|
*
|
|
|
* @var string
|
|
|
*/
|
|
|
- protected $target_type;
|
|
|
+ protected $targetType;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The substitution manager.
|
|
|
+ *
|
|
|
+ * @var \Drupal\linkit\SubstitutionManagerInterface
|
|
|
+ */
|
|
|
+ protected $substitutionManager;
|
|
|
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
- public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
|
|
|
+ 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) {
|
|
|
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
|
|
|
|
|
if (empty($plugin_definition['target_entity'])) {
|
|
|
throw new \InvalidArgumentException("Missing required 'target_entity' property for a matcher.");
|
|
|
}
|
|
|
$this->database = $database;
|
|
|
- $this->entityManager = $entity_manager;
|
|
|
+ $this->entityTypeManager = $entity_type_manager;
|
|
|
+ $this->entityTypeBundleInfo = $entity_type_bundle_info;
|
|
|
+ $this->entityRepository = $entity_repository;
|
|
|
$this->moduleHandler = $module_handler;
|
|
|
$this->currentUser = $current_user;
|
|
|
- $this->target_type = $plugin_definition['target_entity'];
|
|
|
+ $this->targetType = $plugin_definition['target_entity'];
|
|
|
+ $this->substitutionManager = $substitution_manager;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -89,9 +120,12 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
$plugin_id,
|
|
|
$plugin_definition,
|
|
|
$container->get('database'),
|
|
|
- $container->get('entity.manager'),
|
|
|
+ $container->get('entity_type.manager'),
|
|
|
+ $container->get('entity_type.bundle.info'),
|
|
|
+ $container->get('entity.repository'),
|
|
|
$container->get('module_handler'),
|
|
|
- $container->get('current_user')
|
|
|
+ $container->get('current_user'),
|
|
|
+ $container->get('plugin.manager.linkit.substitution')
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -100,12 +134,12 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
*/
|
|
|
public function getSummary() {
|
|
|
$summery = parent::getSummary();
|
|
|
- $entity_type = $this->entityManager->getDefinition($this->target_type);
|
|
|
+ $entity_type = $this->entityTypeManager->getDefinition($this->targetType);
|
|
|
|
|
|
- $result_description = $this->configuration['result_description'];
|
|
|
- if (!empty($result_description)) {
|
|
|
- $summery[] = $this->t('Result description: @result_description', [
|
|
|
- '@result_description' => $result_description
|
|
|
+ $metadata = $this->configuration['metadata'];
|
|
|
+ if (!empty($metadata)) {
|
|
|
+ $summery[] = $this->t('Metadata: @metadata', [
|
|
|
+ '@metadata' => $metadata,
|
|
|
]);
|
|
|
}
|
|
|
|
|
@@ -114,7 +148,7 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
$bundles = [];
|
|
|
|
|
|
if ($has_bundle_filter) {
|
|
|
- $bundles_info = $this->entityManager->getBundleInfo($this->target_type);
|
|
|
+ $bundles_info = $this->entityTypeBundleInfo->getBundleInfo($this->targetType);
|
|
|
foreach ($this->configuration['bundles'] as $bundle) {
|
|
|
$bundles[] = $bundles_info[$bundle]['label'];
|
|
|
}
|
|
@@ -136,55 +170,93 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
public function defaultConfiguration() {
|
|
|
- return parent::defaultConfiguration() + [
|
|
|
- 'result_description' => '',
|
|
|
+ return [
|
|
|
+ 'metadata' => '',
|
|
|
'bundles' => [],
|
|
|
'group_by_bundle' => FALSE,
|
|
|
- ];
|
|
|
+ 'substitution_type' => SubstitutionManagerInterface::DEFAULT_SUBSTITUTION,
|
|
|
+ ] + parent::defaultConfiguration();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
|
|
- $entity_type = $this->entityManager->getDefinition($this->target_type);
|
|
|
- $form['result_description'] = [
|
|
|
- '#title' => $this->t('Result description'),
|
|
|
+ $entity_type = $this->entityTypeManager->getDefinition($this->targetType);
|
|
|
+
|
|
|
+ $form['metadata'] = [
|
|
|
+ '#type' => 'details',
|
|
|
+ '#title' => $this->t('Suggestion metadata'),
|
|
|
+ '#open' => TRUE,
|
|
|
+ '#weight' => -100,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $form['metadata']['metadata'] = [
|
|
|
+ '#title' => $this->t('Metadata'),
|
|
|
'#type' => 'textfield',
|
|
|
- '#default_value' => $this->configuration['result_description'],
|
|
|
+ '#default_value' => $this->configuration['metadata'],
|
|
|
+ '#description' => $this->t('Metadata is shown together with each suggestion in the suggestion list.'),
|
|
|
'#size' => 120,
|
|
|
'#maxlength' => 255,
|
|
|
- '#weight' => -100,
|
|
|
+ '#weight' => 0,
|
|
|
];
|
|
|
|
|
|
- $this->insertTokenList($form, [$this->target_type]);
|
|
|
+ $this->insertTokenList($form, [$this->targetType]);
|
|
|
|
|
|
// Filter the possible bundles to use if the entity has bundles.
|
|
|
if ($entity_type->hasKey('bundle')) {
|
|
|
$bundle_options = [];
|
|
|
- foreach ($this->entityManager->getBundleInfo($this->target_type) as $bundle_name => $bundle_info) {
|
|
|
+ foreach ($this->entityTypeBundleInfo->getBundleInfo($this->targetType) as $bundle_name => $bundle_info) {
|
|
|
$bundle_options[$bundle_name] = $bundle_info['label'];
|
|
|
}
|
|
|
|
|
|
- $form['bundles'] = [
|
|
|
+ $form['bundle_restrictions'] = [
|
|
|
+ '#type' => 'details',
|
|
|
+ '#title' => $this->t('Bundle restrictions'),
|
|
|
+ '#open' => TRUE,
|
|
|
+ '#weight' => -90,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $form['bundle_restrictions']['bundles'] = [
|
|
|
'#type' => 'checkboxes',
|
|
|
- '#title' => $this->t('Restrict to the selected bundles'),
|
|
|
+ '#title' => $this->t('Restrict suggestions to the selected bundles'),
|
|
|
'#options' => $bundle_options,
|
|
|
'#default_value' => $this->configuration['bundles'],
|
|
|
- '#description' => $this->t('If none of the checkboxes is checked, allow all bundles.'),
|
|
|
+ '#description' => $this->t('If none of the checkboxes is checked, all bundles are allowed.'),
|
|
|
'#element_validate' => [[get_class($this), 'elementValidateFilter']],
|
|
|
- '#weight' => -50,
|
|
|
];
|
|
|
|
|
|
- // Group the results by bundle.
|
|
|
- $form['group_by_bundle'] = [
|
|
|
+ $form['bundle_grouping'] = [
|
|
|
+ '#type' => 'details',
|
|
|
+ '#title' => $this->t('Bundle grouping'),
|
|
|
+ '#open' => TRUE,
|
|
|
+ ];
|
|
|
+
|
|
|
+ // Group the suggestions by bundle.
|
|
|
+ $form['bundle_grouping']['group_by_bundle'] = [
|
|
|
'#type' => 'checkbox',
|
|
|
'#title' => $this->t('Group by bundle'),
|
|
|
'#default_value' => $this->configuration['group_by_bundle'],
|
|
|
- '#weight' => -50,
|
|
|
+ '#description' => $this->t('Group suggestions by their bundle.'),
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ $substitution_options = $this->substitutionManager->getApplicablePluginsOptionList($this->targetType);
|
|
|
+ $form['substitution'] = [
|
|
|
+ '#type' => 'details',
|
|
|
+ '#title' => $this->t('URL substitution'),
|
|
|
+ '#open' => TRUE,
|
|
|
+ '#weight' => 100,
|
|
|
+ '#access' => count($substitution_options) !== 1,
|
|
|
+ ];
|
|
|
+ $form['substitution']['substitution_type'] = [
|
|
|
+ '#title' => $this->t('Substitution Type'),
|
|
|
+ '#type' => 'select',
|
|
|
+ '#default_value' => $this->configuration['substitution_type'],
|
|
|
+ '#options' => $substitution_options,
|
|
|
+ '#description' => $this->t('Configure how the selected entity should be transformed into a URL for insertion.'),
|
|
|
+ ];
|
|
|
+
|
|
|
return $form;
|
|
|
}
|
|
|
|
|
@@ -198,9 +270,10 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
|
|
- $this->configuration['result_description'] = $form_state->getValue('result_description');
|
|
|
+ $this->configuration['metadata'] = $form_state->getValue('metadata');
|
|
|
$this->configuration['bundles'] = $form_state->getValue('bundles');
|
|
|
$this->configuration['group_by_bundle'] = $form_state->getValue('group_by_bundle');
|
|
|
+ $this->configuration['substitution_type'] = $form_state->getValue('substitution_type');
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -214,55 +287,64 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
- public function getMatches($string) {
|
|
|
+ public function execute($string) {
|
|
|
+ $suggestions = new SuggestionCollection();
|
|
|
$query = $this->buildEntityQuery($string);
|
|
|
- $result = $query->execute();
|
|
|
+ $query_result = $query->execute();
|
|
|
+ $url_results = $this->findEntityIdByUrl($string);
|
|
|
+ $result = array_merge($query_result, $url_results);
|
|
|
|
|
|
+ // If no results, return an empty suggestion collection.
|
|
|
if (empty($result)) {
|
|
|
- return [];
|
|
|
+ return $suggestions;
|
|
|
}
|
|
|
|
|
|
- $matches = [];
|
|
|
- $entities = $this->entityManager->getStorage($this->target_type)->loadMultiple($result);
|
|
|
+ $entities = $this->entityTypeManager->getStorage($this->targetType)->loadMultiple($result);
|
|
|
|
|
|
- foreach ($entities as $entity_id => $entity) {
|
|
|
+ foreach ($entities as $entity) {
|
|
|
// Check the access against the defined entity access handler.
|
|
|
/** @var \Drupal\Core\Access\AccessResultInterface $access */
|
|
|
$access = $entity->access('view', $this->currentUser, TRUE);
|
|
|
+
|
|
|
if (!$access->isAllowed()) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- $matches[] = [
|
|
|
- 'title' => $this->buildLabel($entity),
|
|
|
- 'description' => $this->buildDescription($entity),
|
|
|
- 'path' => $this->buildPath($entity),
|
|
|
- 'group' => $this->buildGroup($entity),
|
|
|
- ];
|
|
|
+ $entity = $this->entityRepository->getTranslationFromContext($entity);
|
|
|
+ $suggestion = $this->createSuggestion($entity);
|
|
|
+ $suggestions->addSuggestion($suggestion);
|
|
|
}
|
|
|
|
|
|
- return $matches;
|
|
|
+ return $suggestions;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Builds an EntityQuery to get entities.
|
|
|
*
|
|
|
- * @param $match
|
|
|
+ * @param string $search_string
|
|
|
* Text to match the label against.
|
|
|
*
|
|
|
* @return \Drupal\Core\Entity\Query\QueryInterface
|
|
|
* The EntityQuery object with the basic conditions and sorting applied to
|
|
|
* it.
|
|
|
*/
|
|
|
- protected function buildEntityQuery($match) {
|
|
|
- $match = $this->database->escapeLike($match);
|
|
|
+ protected function buildEntityQuery($search_string) {
|
|
|
+ $search_string = $this->database->escapeLike($search_string);
|
|
|
|
|
|
- $entity_type = $this->entityManager->getDefinition($this->target_type);
|
|
|
- $query = $this->entityManager->getStorage($this->target_type)->getQuery();
|
|
|
+ $entity_type = $this->entityTypeManager->getDefinition($this->targetType);
|
|
|
+ $query = $this->entityTypeManager->getStorage($this->targetType)->getQuery();
|
|
|
$label_key = $entity_type->getKey('label');
|
|
|
|
|
|
if ($label_key) {
|
|
|
- $query->condition($label_key, '%' . $match . '%', 'LIKE');
|
|
|
+ // For configuration entities, the condition needs to be CONTAINS as
|
|
|
+ // the matcher does not support LIKE.
|
|
|
+ if ($entity_type instanceof ConfigEntityTypeInterface) {
|
|
|
+ $query->condition($label_key, $search_string, 'CONTAINS');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $query->condition($label_key, '%' . $search_string . '%', 'LIKE');
|
|
|
+ }
|
|
|
+
|
|
|
$query->sort($label_key, 'ASC');
|
|
|
}
|
|
|
|
|
@@ -271,59 +353,78 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
$query->condition($bundle_key, $this->configuration['bundles'], 'IN');
|
|
|
}
|
|
|
|
|
|
+ $this->addQueryTags($query);
|
|
|
+
|
|
|
+ return $query;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds query tags to the query.
|
|
|
+ *
|
|
|
+ * @param \Drupal\Core\Entity\Query\QueryInterface $query
|
|
|
+ * A query to add tags to.
|
|
|
+ */
|
|
|
+ protected function addQueryTags(QueryInterface $query) {
|
|
|
// Add tags to let other modules alter the query.
|
|
|
$query->addTag('linkit_entity_autocomplete');
|
|
|
- $query->addTag('linkit_entity_' . $this->target_type . '_autocomplete');
|
|
|
+ $query->addTag('linkit_entity_' . $this->targetType . '_autocomplete');
|
|
|
|
|
|
// Add access tag for the query.
|
|
|
$query->addTag('entity_access');
|
|
|
- $query->addTag($this->target_type . '_access');
|
|
|
-
|
|
|
- return $query;
|
|
|
+ $query->addTag($this->targetType . '_access');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Builds the label string used in the match array.
|
|
|
+ * Creates a suggestion.
|
|
|
*
|
|
|
* @param \Drupal\Core\Entity\EntityInterface $entity
|
|
|
* The matched entity.
|
|
|
*
|
|
|
- * @return string
|
|
|
- * The label for this entity.
|
|
|
+ * @return \Drupal\linkit\Suggestion\EntitySuggestion
|
|
|
+ * A suggestion object with populated entity data.
|
|
|
*/
|
|
|
- protected function buildLabel($entity) {
|
|
|
- return Html::escape($entity->label());
|
|
|
+ protected function createSuggestion(EntityInterface $entity) {
|
|
|
+ $suggestion = new EntitySuggestion();
|
|
|
+ $suggestion->setLabel($this->buildLabel($entity))
|
|
|
+ ->setGroup($this->buildGroup($entity))
|
|
|
+ ->setDescription($this->buildDescription($entity))
|
|
|
+ ->setEntityUuid($entity->uuid())
|
|
|
+ ->setEntityTypeId($entity->getEntityTypeId())
|
|
|
+ ->setSubstitutionId($this->configuration['substitution_type'])
|
|
|
+ ->setPath($this->buildPath($entity));
|
|
|
+
|
|
|
+ return $suggestion;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Builds the description string used in the match array.
|
|
|
+ * Builds the label string used in the suggestion.
|
|
|
*
|
|
|
* @param \Drupal\Core\Entity\EntityInterface $entity
|
|
|
* The matched entity.
|
|
|
*
|
|
|
* @return string
|
|
|
- * The description for this entity.
|
|
|
+ * The label for this entity.
|
|
|
*/
|
|
|
- protected function buildDescription($entity) {
|
|
|
- $description = \Drupal::token()->replace($this->configuration['result_description'], [$this->target_type => $entity], []);
|
|
|
- return LinkitXss::descriptionFilter($description);
|
|
|
+ protected function buildLabel(EntityInterface $entity) {
|
|
|
+ return Html::escape($entity->label());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Builds the path string used in the match array.
|
|
|
+ * Builds the metadata string used in the suggestion.
|
|
|
*
|
|
|
* @param \Drupal\Core\Entity\EntityInterface $entity
|
|
|
- * The matched entity.
|
|
|
+ * The matched entity.
|
|
|
*
|
|
|
* @return string
|
|
|
- * The URL for this entity.
|
|
|
+ * The metadata for this entity.
|
|
|
*/
|
|
|
- protected function buildPath($entity) {
|
|
|
- return $entity->toUrl()->toString();
|
|
|
+ protected function buildDescription(EntityInterface $entity) {
|
|
|
+ $description = \Drupal::token()->replace($this->configuration['metadata'], [$this->targetType => $entity], ['clear' => TRUE]);
|
|
|
+ return LinkitXss::descriptionFilter($description);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Builds the group string used in the match array.
|
|
|
+ * Builds the group string used in the suggestion.
|
|
|
*
|
|
|
* @param \Drupal\Core\Entity\EntityInterface $entity
|
|
|
* The matched entity.
|
|
@@ -331,13 +432,13 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
* @return string
|
|
|
* The match group for this entity.
|
|
|
*/
|
|
|
- protected function buildGroup($entity) {
|
|
|
+ protected function buildGroup(EntityInterface $entity) {
|
|
|
$group = $entity->getEntityType()->getLabel();
|
|
|
|
|
|
// If the entities by this entity should be grouped by bundle, get the
|
|
|
// name and append it to the group.
|
|
|
if ($this->configuration['group_by_bundle']) {
|
|
|
- $bundles = $this->entityManager->getBundleInfo($entity->getEntityTypeId());
|
|
|
+ $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity->getEntityTypeId());
|
|
|
$bundle_label = $bundles[$entity->bundle()]['label'];
|
|
|
$group .= ' - ' . $bundle_label;
|
|
|
}
|
|
@@ -345,4 +446,43 @@ class EntityMatcher extends ConfigurableMatcherBase {
|
|
|
return $group;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Builds the path string used in the suggestion.
|
|
|
+ *
|
|
|
+ * @param \Drupal\Core\Entity\EntityInterface $entity
|
|
|
+ * The matched entity.
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ * The path for this entity.
|
|
|
+ */
|
|
|
+ protected function buildPath(EntityInterface $entity) {
|
|
|
+ return $entity->toUrl('canonical', ['path_processing' => FALSE])->toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Finds entity id from the given input.
|
|
|
+ *
|
|
|
+ * @param string $user_input
|
|
|
+ * The string to url parse.
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * An array with an entity id if the input can be parsed as an internal url
|
|
|
+ * and a match is found, otherwise an empty array.
|
|
|
+ */
|
|
|
+ protected function findEntityIdByUrl($user_input) {
|
|
|
+ $result = [];
|
|
|
+
|
|
|
+ try {
|
|
|
+ $params = Url::fromUserInput($user_input)->getRouteParameters();
|
|
|
+ if (key($params) === $this->targetType) {
|
|
|
+ $result = [end($params)];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception $e) {
|
|
|
+ // Do nothing.
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|