X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fpathauto%2Fsrc%2FPathautoGenerator.php;fp=web%2Fmodules%2Fcontrib%2Fpathauto%2Fsrc%2FPathautoGenerator.php;h=d70ce3b6fab7e1bbb566aad81b3e0e4871630528;hp=6c56a5c348d61c05499b8d8e4a4b94f360628774;hb=059867c3f96750652c80f39e44c442a58c2549ee;hpb=f8fc16ae6b862bef59baaad5d051dd37b7ff11b2 diff --git a/web/modules/contrib/pathauto/src/PathautoGenerator.php b/web/modules/contrib/pathauto/src/PathautoGenerator.php index 6c56a5c34..d70ce3b6f 100644 --- a/web/modules/contrib/pathauto/src/PathautoGenerator.php +++ b/web/modules/contrib/pathauto/src/PathautoGenerator.php @@ -2,7 +2,6 @@ namespace Drupal\pathauto; -use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; @@ -87,12 +86,16 @@ class PathautoGenerator implements PathautoGeneratorInterface { protected $messenger; /** + * The token entity mapper. + * * @var \Drupal\token\TokenEntityMapperInterface */ protected $tokenEntityMapper; /** - * @var Drupal\Core\Entity\EntityTypeManagerInterface + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; @@ -115,10 +118,12 @@ class PathautoGenerator implements PathautoGeneratorInterface { * The messenger service. * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. - * @param Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager + * @param \Drupal\token\TokenEntityMapperInterface $token_entity_mapper + * The token entity mapper. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, Token $token, AliasCleanerInterface $alias_cleaner, AliasStorageHelperInterface $alias_storage_helper, AliasUniquifierInterface $alias_uniquifier, MessengerInterface $messenger, TranslationInterface $string_translation, TokenEntityMapperInterface $token_entity_mappper, EntityTypeManagerInterface $entity_type_manager) { + public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, Token $token, AliasCleanerInterface $alias_cleaner, AliasStorageHelperInterface $alias_storage_helper, AliasUniquifierInterface $alias_uniquifier, MessengerInterface $messenger, TranslationInterface $string_translation, TokenEntityMapperInterface $token_entity_mapper, EntityTypeManagerInterface $entity_type_manager) { $this->configFactory = $config_factory; $this->moduleHandler = $module_handler; $this->token = $token; @@ -127,7 +132,7 @@ class PathautoGenerator implements PathautoGeneratorInterface { $this->aliasUniquifier = $alias_uniquifier; $this->messenger = $messenger; $this->stringTranslation = $string_translation; - $this->tokenEntityMapper = $token_entity_mappper; + $this->tokenEntityMapper = $token_entity_mapper; $this->entityTypeManager = $entity_type_manager; } @@ -165,8 +170,9 @@ class PathautoGenerator implements PathautoGeneratorInterface { 'bundle' => $entity->bundle(), 'language' => &$langcode, ); - // @todo Is still hook still useful? + $pattern_original = $pattern->getPattern(); $this->moduleHandler->alter('pathauto_pattern', $pattern, $context); + $pattern_altered = $pattern->getPattern(); // Special handling when updating an item which is already aliased. $existing_alias = NULL; @@ -209,7 +215,7 @@ class PathautoGenerator implements PathautoGeneratorInterface { $this->moduleHandler->alter('pathauto_alias', $alias, $context); // If we have arrived at an empty string, discontinue. - if (!Unicode::strlen($alias)) { + if (!mb_strlen($alias)) { return NULL; } @@ -236,11 +242,19 @@ class PathautoGenerator implements PathautoGeneratorInterface { 'language' => $langcode, ); - return $this->aliasStorageHelper->save($path, $existing_alias, $op); + $return = $this->aliasStorageHelper->save($path, $existing_alias, $op); + + // Because there is no way to set an altered pattern to not be cached, + // change it back to the original value. + if ($pattern_altered !== $pattern_original) { + $pattern->setPattern($pattern_original); + } + + return $return; } /** - * Loads pathauto patterns for a given entity type ID + * Loads pathauto patterns for a given entity type ID. * * @param string $entity_type_id * An entity type ID. @@ -335,7 +349,7 @@ class PathautoGenerator implements PathautoGeneratorInterface { $result = $this->createEntityAlias($entity, $op); } catch (\InvalidArgumentException $e) { - drupal_set_message($e->getMessage(), 'error'); + $this->messenger->addError($e->getMessage()); return NULL; }