diff --git a/core/core.services.yml b/core/core.services.yml index 317af02..e84c43e 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -333,7 +333,7 @@ services: class: Drupal\Core\CacheDecorator\AliasManagerCacheDecorator arguments: ['@path.alias_manager', '@cache.path'] path.crud: - class: Drupal\Core\Path\Path + class: Drupal\Core\Path\AliasStorage arguments: ['@database', '@module_handler'] # The argument to the hashing service defined in services.yml, to the # constructor of PhpassHashedPassword is the log2 number of iterations for diff --git a/core/lib/Drupal/Core/Path/AliasManager.php b/core/lib/Drupal/Core/Path/AliasManager.php index ac025ef..eeac9e6 100644 --- a/core/lib/Drupal/Core/Path/AliasManager.php +++ b/core/lib/Drupal/Core/Path/AliasManager.php @@ -13,11 +13,11 @@ class AliasManager implements AliasManagerInterface { /** - * The alias storage controller service. + * The alias storage service. * - * @var \Drupal\Core\Path\AliasStorageController + * @var \Drupal\Core\Path\AliasStorage */ - protected $storageController; + protected $storage; /** * Language manager for retrieving the default langcode when none is specified. @@ -74,15 +74,15 @@ class AliasManager implements AliasManagerInterface { /** * Constructs an AliasManager. * - * @param \Drupal\Core\Path\AliasStorageController $storage_controller - * The alias storage controller service. + * @param \Drupal\Core\Path\AliasStorage $storage + * The alias storage service. * @param \Drupal\Core\Path\AliasWhitelistInterface $whitelist * The whitelist implementation to use. * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. */ - public function __construct(AliasStorageController $storage_controller, AliasWhitelistInterface $whitelist, LanguageManager $language_manager) { - $this->storageController = $storage_controller; + public function __construct(AliasStorage $storage, AliasWhitelistInterface $whitelist, LanguageManager $language_manager) { + $this->storage = $storage; $this->languageManager = $language_manager; $this->whitelist = $whitelist; } @@ -180,7 +180,7 @@ protected function lookupPathAlias($path, $langcode) { // Load system paths from cache. if (!empty($this->preloadedPathLookups)) { // Now fetch the aliases corresponding to these system paths. - $this->lookupMap[$langcode] = $this->storageController->preloadPathAlias($this->preloadedPathLookups, $langcode); + $this->lookupMap[$langcode] = $this->storage->preloadPathAlias($this->preloadedPathLookups, $langcode); // Keep a record of paths with no alias to avoid querying twice. $this->noAliases[$langcode] = array_flip(array_diff_key($this->preloadedPathLookups, array_keys($this->lookupMap[$langcode]))); } @@ -197,7 +197,7 @@ protected function lookupPathAlias($path, $langcode) { } // For system paths which were not cached, query aliases individually. elseif (!isset($this->noAliases[$langcode][$path])) { - $this->lookupMap[$langcode][$path] = $this->storageController->lookupPathAlias($path, $langcode); + $this->lookupMap[$langcode][$path] = $this->storage->lookupPathAlias($path, $langcode); return $this->lookupMap[$langcode][$path]; } return FALSE; @@ -222,7 +222,7 @@ protected function lookupPathSource($path, $langcode) { // Look for the value $path within the cached $map $source = isset($this->lookupMap[$langcode]) ? array_search($path, $this->lookupMap[$langcode]) : FALSE; if (!$source) { - if ($source = $this->storageController->lookupPathSource($path, $langcode)) { + if ($source = $this->storage->lookupPathSource($path, $langcode)) { $this->lookupMap[$langcode][$source] = $path; } else { diff --git a/core/lib/Drupal/Core/Path/AliasStorageController.php b/core/lib/Drupal/Core/Path/AliasStorage.php similarity index 99% rename from core/lib/Drupal/Core/Path/AliasStorageController.php rename to core/lib/Drupal/Core/Path/AliasStorage.php index f032049..70fd0e3 100644 --- a/core/lib/Drupal/Core/Path/AliasStorageController.php +++ b/core/lib/Drupal/Core/Path/AliasStorage.php @@ -14,7 +14,7 @@ /** * Defines a class for CRUD operations on path aliases. */ -class AliasStorageController { +class AliasStorage { /** * The database connection. diff --git a/core/modules/path/lib/Drupal/path/Form/DeleteForm.php b/core/modules/path/lib/Drupal/path/Form/DeleteForm.php index 3ae06da..b92c97c 100644 --- a/core/modules/path/lib/Drupal/path/Form/DeleteForm.php +++ b/core/modules/path/lib/Drupal/path/Form/DeleteForm.php @@ -8,7 +8,7 @@ namespace Drupal\path\Form; use Drupal\Core\Form\ConfirmFormBase; -use Drupal\Core\Path\AliasStorageController; +use Drupal\Core\Path\AliasStorage; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -17,11 +17,11 @@ class DeleteForm extends ConfirmFormBase { /** - * The alias storage controller service. + * The alias storage service. * - * @var AliasStorageController $path + * @var AliasStorage $path */ - protected $aliasStorageController; + protected $aliasStorage; /** * The path alias being deleted. @@ -33,11 +33,11 @@ class DeleteForm extends ConfirmFormBase { /** * Constructs a \Drupal\Core\Path\Path object. * - * @param \Drupal\Core\Path\AliasStorageController $alias_storage_controller - * The alias storage controller service. + * @param \Drupal\Core\Path\AliasStorage $alias_storage + * The alias storage service. */ - public function __construct(AliasStorageController $alias_storage_controller) { - $this->aliasStorageController = $alias_storage_controller; + public function __construct(AliasStorage $alias_storage) { + $this->aliasStorage = $alias_storage; } /** @@ -73,7 +73,7 @@ public function getCancelRoute() { * Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm(). */ public function buildForm(array $form, array &$form_state, $pid = NULL) { - $this->pathAlias = $this->aliasStorageController->load(array('pid' => $pid)); + $this->pathAlias = $this->aliasStorage->load(array('pid' => $pid)); $form = parent::buildForm($form, $form_state); @@ -86,7 +86,7 @@ public function buildForm(array $form, array &$form_state, $pid = NULL) { * Implements \Drupal\Core\Form\FormInterface::submitForm(). */ public function submitForm(array &$form, array &$form_state) { - $this->aliasStorageController->delete(array('pid' => $this->pathAlias['pid'])); + $this->aliasStorage->delete(array('pid' => $this->pathAlias['pid'])); $form_state['redirect'] = 'admin/config/search/path'; } diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php b/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php index b0c33a8..6fd6743 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php @@ -8,7 +8,7 @@ namespace Drupal\system\Tests\Path; use Drupal\Core\Cache\MemoryCounterBackend; -use Drupal\Core\Path\AliasStorageController; +use Drupal\Core\Path\AliasStorage; use Drupal\Core\Database\Database; use Drupal\Core\Path\AliasManager; use Drupal\Core\Path\AliasWhitelist; @@ -32,13 +32,13 @@ function testCRUD() { $this->fixtures->createTables($connection); //Create Path object. - $aliasStorageController = new AliasStorageController($connection, $this->container->get('module_handler')); + $aliasStorage = new AliasStorage($connection, $this->container->get('module_handler')); $aliases = $this->fixtures->sampleUrlAliases(); //Create a few aliases foreach ($aliases as $idx => $alias) { - $aliasStorageController->save($alias['source'], $alias['alias'], $alias['langcode']); + $aliasStorage->save($alias['source'], $alias['alias'], $alias['langcode']); $result = $connection->query('SELECT * FROM {url_alias} WHERE source = :source AND alias= :alias AND langcode = :langcode', array(':source' => $alias['source'], ':alias' => $alias['alias'], ':langcode' => $alias['langcode'])); $rows = $result->fetchAll(); @@ -52,13 +52,13 @@ function testCRUD() { //Load a few aliases foreach ($aliases as $alias) { $pid = $alias['pid']; - $loadedAlias = $aliasStorageController->load(array('pid' => $pid)); + $loadedAlias = $aliasStorage->load(array('pid' => $pid)); $this->assertEqual($loadedAlias, $alias, format_string('Loaded the expected path with pid %pid.', array('%pid' => $pid))); } //Update a few aliases foreach ($aliases as $alias) { - $aliasStorageController->save($alias['source'], $alias['alias'] . '_updated', $alias['langcode'], $alias['pid']); + $aliasStorage->save($alias['source'], $alias['alias'] . '_updated', $alias['langcode'], $alias['pid']); $result = $connection->query('SELECT pid FROM {url_alias} WHERE source = :source AND alias= :alias AND langcode = :langcode', array(':source' => $alias['source'], ':alias' => $alias['alias'] . '_updated', ':langcode' => $alias['langcode'])); $pid = $result->fetchField(); @@ -69,7 +69,7 @@ function testCRUD() { //Delete a few aliases foreach ($aliases as $alias) { $pid = $alias['pid']; - $aliasStorageController->delete(array('pid' => $pid)); + $aliasStorage->delete(array('pid' => $pid)); $result = $connection->query('SELECT * FROM {url_alias} WHERE pid = :pid', array(':pid' => $pid)); $rows = $result->fetchAll(); @@ -85,7 +85,7 @@ function testLookupPath() { //Create AliasManager and Path object. $aliasManager = $this->container->get('path.alias_manager.cached'); - $aliasStorageController = new AliasStorageController($connection, $this->container->get('module_handler')); + $aliasStorage = new AliasStorage($connection, $this->container->get('module_handler')); // Test the situation where the source is the same for multiple aliases. // Start with a language-neutral alias, which we will override. @@ -94,7 +94,7 @@ function testLookupPath() { 'alias' => 'foo', ); - $aliasStorageController->save($path['source'], $path['alias']); + $aliasStorage->save($path['source'], $path['alias']); $this->assertEqual($aliasManager->getPathAlias($path['source']), $path['alias'], 'Basic alias lookup works.'); $this->assertEqual($aliasManager->getSystemPath($path['alias']), $path['source'], 'Basic source lookup works.'); @@ -104,7 +104,7 @@ function testLookupPath() { 'alias' => "users/Dries", 'langcode' => 'en', ); - $aliasStorageController->save($path['source'], $path['alias'], $path['langcode']); + $aliasStorage->save($path['source'], $path['alias'], $path['langcode']); // Hook that clears cache is not executed with unit tests. \Drupal::service('path.alias_manager.cached')->cacheClear(); $this->assertEqual($aliasManager->getPathAlias($path['source']), $path['alias'], 'English alias overrides language-neutral alias.'); @@ -115,7 +115,7 @@ function testLookupPath() { 'source' => "user/1", 'alias' => 'bar', ); - $aliasStorageController->save($path['source'], $path['alias']); + $aliasStorage->save($path['source'], $path['alias']); $this->assertEqual($aliasManager->getPathAlias($path['source']), "users/Dries", 'English alias still returned after entering a language-neutral alias.'); // Create a language-specific (xx-lolspeak) alias for the same path. @@ -124,7 +124,7 @@ function testLookupPath() { 'alias' => 'LOL', 'langcode' => 'xx-lolspeak', ); - $aliasStorageController->save($path['source'], $path['alias'], $path['langcode']); + $aliasStorage->save($path['source'], $path['alias'], $path['langcode']); $this->assertEqual($aliasManager->getPathAlias($path['source']), "users/Dries", 'English alias still returned after entering a LOLspeak alias.'); // The LOLspeak alias should be returned if we really want LOLspeak. $this->assertEqual($aliasManager->getPathAlias($path['source'], 'xx-lolspeak'), 'LOL', 'LOLspeak alias returned if we specify xx-lolspeak to the alias manager.'); @@ -136,7 +136,7 @@ function testLookupPath() { 'alias' => 'users/my-new-path', 'langcode' => 'en', ); - $aliasStorageController->save($path['source'], $path['alias'], $path['langcode']); + $aliasStorage->save($path['source'], $path['alias'], $path['langcode']); // Hook that clears cache is not executed with unit tests. $aliasManager->cacheClear(); $this->assertEqual($aliasManager->getPathAlias($path['source']), $path['alias'], 'Recently created English alias returned.'); @@ -144,14 +144,14 @@ function testLookupPath() { // Remove the English aliases, which should cause a fallback to the most // recently created language-neutral alias, 'bar'. - $aliasStorageController->delete(array('langcode' => 'en')); + $aliasStorage->delete(array('langcode' => 'en')); // Hook that clears cache is not executed with unit tests. $aliasManager->cacheClear(); $this->assertEqual($aliasManager->getPathAlias($path['source']), 'bar', 'Path lookup falls back to recently created language-neutral alias.'); // Test the situation where the alias and language are the same, but // the source differs. The newer alias record should be returned. - $aliasStorageController->save('user/2', 'bar'); + $aliasStorage->save('user/2', 'bar'); // Hook that clears cache is not executed with unit tests. $aliasManager->cacheClear(); $this->assertEqual($aliasManager->getSystemPath('bar'), 'user/2', 'Newer alias record is returned when comparing two Language::LANGCODE_NOT_SPECIFIED paths with the same alias.'); @@ -169,8 +169,8 @@ function testWhitelist() { // Create AliasManager and Path object. $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $connection); - $aliasStorageController = new AliasStorageController($connection, $this->container->get('module_handler')); - $aliasManager = new AliasManager($aliasStorageController, $whitelist, $this->container->get('language_manager')); + $aliasStorage = new AliasStorage($connection, $this->container->get('module_handler')); + $aliasManager = new AliasManager($aliasStorage, $whitelist, $this->container->get('language_manager')); // No alias for user and admin yet, so should be NULL. $this->assertNull($whitelist->get('user')); @@ -181,21 +181,21 @@ function testWhitelist() { $this->assertNull($whitelist->get($this->randomName())); // Add an alias for user/1, user should get whitelisted now. - $aliasStorageController->save('user/1', $this->randomName()); + $aliasStorage->save('user/1', $this->randomName()); $aliasManager->cacheClear(); $this->assertTrue($whitelist->get('user')); $this->assertNull($whitelist->get('admin')); $this->assertNull($whitelist->get($this->randomName())); // Add an alias for admin, both should get whitelisted now. - $aliasStorageController->save('admin/something', $this->randomName()); + $aliasStorage->save('admin/something', $this->randomName()); $aliasManager->cacheClear(); $this->assertTrue($whitelist->get('user')); $this->assertTrue($whitelist->get('admin')); $this->assertNull($whitelist->get($this->randomName())); // Remove the user alias again, whitelist entry should be removed. - $aliasStorageController->delete(array('source' => 'user/1')); + $aliasStorage->delete(array('source' => 'user/1')); $aliasManager->cacheClear(); $this->assertNull($whitelist->get('user')); $this->assertTrue($whitelist->get('admin'));