Loading src/SystemTagFinder/SystemTagFinderInterface.php +6 −2 Original line number Diff line number Diff line Loading @@ -14,21 +14,25 @@ interface SystemTagFinderInterface { * * @param string $systemTagId * The ID of the System Tag. * @param string|null $langcode * Use a specific language code. * * @return \Drupal\Core\Entity\EntityInterface[] * An array of entities, tagged with the given ID. */ public function findByTag($systemTagId); public function findByTag($systemTagId, $langcode = NULL); /** * Find a single entity by System Tag ID. * * @param string $systemTagId * The ID of the System Tag. * @param string|null $langcode * Use a specific language code. * * @return \Drupal\Core\Entity\EntityInterface|null * An entity, tagged with the given ID or NULL if nothing is found. */ public function findOneByTag($systemTagId); public function findOneByTag($systemTagId, $langcode = NULL); } src/SystemTagFinder/SystemTagFinderPluginBase.php +4 −4 Original line number Diff line number Diff line Loading @@ -86,12 +86,12 @@ abstract class SystemTagFinderPluginBase extends PluginBase implements SystemTag /** * {@inheritdoc} */ public function findByTag($systemTagId) { public function findByTag($systemTagId, $langcode = NULL) { $entities = []; $entityTypeId = $this->pluginDefinition['entity_type']; if ($fields = $this->systemTagHelper->getReferenceFieldNames($entityTypeId)) { $langcode = $this->languageManager->getCurrentLanguage()->getId(); $langcode = $langcode ?: $this->languageManager->getCurrentLanguage()->getId(); $storage = $this->entityTypeManager->getStorage($entityTypeId); $query = $storage->getQuery() Loading Loading @@ -128,8 +128,8 @@ abstract class SystemTagFinderPluginBase extends PluginBase implements SystemTag /** * {@inheritdoc} */ public function findOneByTag($systemTagId) { $entities = $this->findByTag($systemTagId); public function findOneByTag($systemTagId, $langcode = NULL) { $entities = $this->findByTag($systemTagId, $langcode); return reset($entities) ?: NULL; } Loading system_tags.tokens.inc +1 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ function system_tags_tokens($type, array $tokens, array $data, array $options, B $system_tag_finder = Drupal::service('plugin.manager.system_tags.system_tag_finder_manager') ->getInstance(compact('entity_type')); if ($entity = $system_tag_finder->findOneByTag($tag_id)) { if ($entity = $system_tag_finder->findOneByTag($tag_id, $options['langcode'] ?? NULL)) { // Replace the original token with the translated alias. $replacements[$original] = $path_alias_manager->getAliasByPath( sprintf('/%s', $entity->toUrl()->getInternalPath()), Loading Loading
src/SystemTagFinder/SystemTagFinderInterface.php +6 −2 Original line number Diff line number Diff line Loading @@ -14,21 +14,25 @@ interface SystemTagFinderInterface { * * @param string $systemTagId * The ID of the System Tag. * @param string|null $langcode * Use a specific language code. * * @return \Drupal\Core\Entity\EntityInterface[] * An array of entities, tagged with the given ID. */ public function findByTag($systemTagId); public function findByTag($systemTagId, $langcode = NULL); /** * Find a single entity by System Tag ID. * * @param string $systemTagId * The ID of the System Tag. * @param string|null $langcode * Use a specific language code. * * @return \Drupal\Core\Entity\EntityInterface|null * An entity, tagged with the given ID or NULL if nothing is found. */ public function findOneByTag($systemTagId); public function findOneByTag($systemTagId, $langcode = NULL); }
src/SystemTagFinder/SystemTagFinderPluginBase.php +4 −4 Original line number Diff line number Diff line Loading @@ -86,12 +86,12 @@ abstract class SystemTagFinderPluginBase extends PluginBase implements SystemTag /** * {@inheritdoc} */ public function findByTag($systemTagId) { public function findByTag($systemTagId, $langcode = NULL) { $entities = []; $entityTypeId = $this->pluginDefinition['entity_type']; if ($fields = $this->systemTagHelper->getReferenceFieldNames($entityTypeId)) { $langcode = $this->languageManager->getCurrentLanguage()->getId(); $langcode = $langcode ?: $this->languageManager->getCurrentLanguage()->getId(); $storage = $this->entityTypeManager->getStorage($entityTypeId); $query = $storage->getQuery() Loading Loading @@ -128,8 +128,8 @@ abstract class SystemTagFinderPluginBase extends PluginBase implements SystemTag /** * {@inheritdoc} */ public function findOneByTag($systemTagId) { $entities = $this->findByTag($systemTagId); public function findOneByTag($systemTagId, $langcode = NULL) { $entities = $this->findByTag($systemTagId, $langcode); return reset($entities) ?: NULL; } Loading
system_tags.tokens.inc +1 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ function system_tags_tokens($type, array $tokens, array $data, array $options, B $system_tag_finder = Drupal::service('plugin.manager.system_tags.system_tag_finder_manager') ->getInstance(compact('entity_type')); if ($entity = $system_tag_finder->findOneByTag($tag_id)) { if ($entity = $system_tag_finder->findOneByTag($tag_id, $options['langcode'] ?? NULL)) { // Replace the original token with the translated alias. $replacements[$original] = $path_alias_manager->getAliasByPath( sprintf('/%s', $entity->toUrl()->getInternalPath()), Loading