diff --git a/core/lib/Drupal/Core/CacheDecorator/AliasManagerCacheDecorator.php b/core/lib/Drupal/Core/CacheDecorator/AliasManagerCacheDecorator.php index f86b2ff..cf46231 100644 --- a/core/lib/Drupal/Core/CacheDecorator/AliasManagerCacheDecorator.php +++ b/core/lib/Drupal/Core/CacheDecorator/AliasManagerCacheDecorator.php @@ -55,14 +55,14 @@ public function __construct(AliasManagerInterface $alias_manager, CacheBackendIn } /** - * Implements \Drupal\Core\CacheDecorator\CacheDecoratorInterface::setCacheKey(). + * {@inheritdoc} */ public function setCacheKey($key) { $this->cacheKey = $key; } /** - * Implements \Drupal\Core\CacheDecorator\CacheDecoratorInterface::writeCache(). + * {@inheritdoc} * * Cache an array of the system paths available on each page. We assume * that aliases will be needed for the majority of these paths during @@ -81,7 +81,7 @@ public function writeCache() { } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::getSystemPath(). + * {@inheritdoc} */ public function getSystemPath($path, $path_language = NULL) { $system_path = $this->aliasManager->getSystemPath($path, $path_language); @@ -98,28 +98,28 @@ public function getSystemPath($path, $path_language = NULL) { } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::getPathAlias(). + * {@inheritdoc} */ public function getPathAlias($path, $path_language = NULL) { return $this->aliasManager->getPathAlias($path, $path_language); } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::getPathLookups(). + * {@inheritdoc} */ public function getPathLookups() { return $this->aliasManager->getPathLookups(); } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::preloadPathLookups(). + * {@inheritdoc} */ public function preloadPathLookups(array $path_list) { $this->aliasManager->preloadPathLookups($path_list); } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::cacheClear(). + * {@inheritdoc} */ public function cacheClear() { $this->cache->delete($this->cacheKey); diff --git a/core/lib/Drupal/Core/Path/Path.php b/core/lib/Drupal/Core/Path/Path.php index 0ac13d7..024b297 100644 --- a/core/lib/Drupal/Core/Path/Path.php +++ b/core/lib/Drupal/Core/Path/Path.php @@ -18,6 +18,27 @@ class Path { /** + * The INSERT event occurs when a new path alias is inserted. + * + * @var string + */ + const INSERT = 'path.insert'; + + /** + * The UPDATE event occurs when an existing path alias is updated. + * + * @var string + */ + const UPDATE = 'path.update'; + + /** + * The DELETE event occurs when a path alias is deleted. + * + * @var string + */ + const DELETE = 'path.delete'; + + /** * The database connection. * * @var \Drupal\Core\Database\Connection @@ -82,7 +103,7 @@ public function save($source, $alias, $langcode = Language::LANGCODE_NOT_SPECIFI ->fields($fields); $pid = $query->execute(); $fields['pid'] = $pid; - $hook = 'insert'; + $operation = 'insert'; } else { $fields['pid'] = $pid; @@ -90,10 +111,11 @@ public function save($source, $alias, $langcode = Language::LANGCODE_NOT_SPECIFI ->fields($fields) ->condition('pid', $pid); $pid = $query->execute(); - $hook = 'update'; + $operation = 'update'; } if ($pid) { - $this->event_dispatcher->dispatch('path.' . $hook, new PathInsertUpdateEvent($fields)); + $event = $operation == 'update' ? PATH::UPDATE : Path::INSERT; + $this->event_dispatcher->dispatch($event, new PathInsertUpdateEvent($fields)); return $fields; } return FALSE; @@ -137,7 +159,7 @@ public function delete($conditions) { $query->condition($field, $value); } $deleted = $query->execute(); - $this->event_dispatcher->dispatch('path.delete', new PathDeleteEvent($path)); + $this->event_dispatcher->dispatch(Path::DELETE, new PathDeleteEvent($path)); return $deleted; } } diff --git a/core/lib/Drupal/Core/Path/PathCRUDSubscriber.php b/core/lib/Drupal/Core/Path/PathCRUDSubscriber.php index a25347c..454c764 100644 --- a/core/lib/Drupal/Core/Path/PathCRUDSubscriber.php +++ b/core/lib/Drupal/Core/Path/PathCRUDSubscriber.php @@ -42,39 +42,15 @@ public function clearAliasManagerCaches() { } /** - * Invokes hook_path_update(). - */ - public function hookPathUpdate(PathInsertUpdateEvent $event) { - $this->moduleHandler->invokeAll('path_update', $event->getFields()); - } - - /** - * Invokes hook_path_insert(). - */ - public function hookPathInsert(PathInsertUpdateEvent $event) { - $this->moduleHandler->invokeAll('path_insert', $event->getFields()); - } - - /** - * Invokes hook_path_delete(). - */ - public function hookPathDelete(PathDeleteEvent $event) { - $this->moduleHandler->invokeAll('path_delete', $event->getPath()); - } - - /** * Registers the methods in this class that should be listeners. * * @return array * An array of event listener definitions. */ static function getSubscribedEvents() { - $events['path.update'][] = array('hookPathUpdate'); - $events['path.insert'][] = array('hookPathInsert'); - $events['path.delete'][] = array('hookPathDelete'); - $events['path.update'][] = array('clearAliasManagerCaches'); - $events['path.insert'][] = array('clearAliasManagerCaches'); - $events['path.delete'][] = array('clearAliasManagerCaches'); + $events[Path::UPDATE][] = array('clearAliasManagerCaches'); + $events[Path::INSERT][] = array('clearAliasManagerCaches'); + $events[Path::DELETE][] = array('clearAliasManagerCaches'); return $events; } } diff --git a/core/modules/path/path.api.php b/core/modules/path/path.api.php deleted file mode 100644 index c69b97d..0000000 --- a/core/modules/path/path.api.php +++ /dev/null @@ -1,73 +0,0 @@ -fields(array( - 'alias' => $path['alias'], - 'pid' => $path['pid'], - )) - ->execute(); -} - -/** - * Respond to a path being updated. - * - * @param $path - * An associative array containing the following keys: - * - source: The internal system path. - * - alias: The URL alias. - * - pid: Unique path alias identifier. - * - langcode: The language code of the alias. - * - * @see \Drupal\Core\Path\Path::save() - */ -function hook_path_update($path) { - db_update('mytable') - ->fields(array('alias' => $path['alias'])) - ->condition('pid', $path['pid']) - ->execute(); -} - -/** - * Respond to a path being deleted. - * - * @param $path - * An associative array containing the following keys: - * - source: The internal system path. - * - alias: The URL alias. - * - pid: Unique path alias identifier. - * - langcode: The language code of the alias. - * - * @see \Drupal\Core\Path\Path::delete() - */ -function hook_path_delete($path) { - db_delete('mytable') - ->condition('pid', $path['pid']) - ->execute(); -} - -/** - * @} End of "addtogroup hooks". - */ diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/MockAliasManager.php b/core/modules/system/lib/Drupal/system/Tests/Routing/MockAliasManager.php index 8625942..4523d70 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Routing/MockAliasManager.php +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/MockAliasManager.php @@ -60,7 +60,7 @@ public function addAlias($path, $alias, $path_language = NULL) { } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::getSystemPath(). + * {@inheritdoc} */ public function getSystemPath($path, $path_language = NULL) { $language = $path_language ?: $this->defaultLanguage; @@ -68,7 +68,7 @@ public function getSystemPath($path, $path_language = NULL) { } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::getPathAlias(). + * {@inheritdoc} */ public function getPathAlias($path, $path_language = NULL) { $language = $path_language ?: $this->defaultLanguage; @@ -77,21 +77,21 @@ public function getPathAlias($path, $path_language = NULL) { } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::getPathLookups(). + * {@inheritdoc} */ public function getPathLookups() { return array_keys($this->lookedUp); } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::preloadPathLookups(). + * {@inheritdoc} */ public function preloadPathLookups(array $path_list) { // Not needed. } /** - * Implements \Drupal\Core\Path\AliasManagerInterface::cacheClear(). + * {@inheritdoc} */ public function cacheClear() { // Not needed. diff --git a/core/modules/system/tests/modules/path_test/path_test.info.yml b/core/modules/system/tests/modules/path_test/path_test.info.yml deleted file mode 100644 index 57a5893..0000000 --- a/core/modules/system/tests/modules/path_test/path_test.info.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: 'Hook path tests' -type: module -description: 'Support module for path hook testing.' -package: Testing -version: VERSION -core: 8.x -hidden: true diff --git a/core/modules/system/tests/modules/path_test/path_test.module b/core/modules/system/tests/modules/path_test/path_test.module deleted file mode 100644 index df03931..0000000 --- a/core/modules/system/tests/modules/path_test/path_test.module +++ /dev/null @@ -1,22 +0,0 @@ -set('path_test.results', array()); -} - -/** - * Implements hook_path_update(). - */ -function path_test_path_update($path) { - $results = \Drupal::state()->get('path_test.results') ?: array(); - $results['hook_path_update'] = $path; - \Drupal::state()->set('path_test.results', $results); -}