Commit 719b36a4 authored by alexpott's avatar alexpott

Issue #2208631 by slashrsm: Rename \Drupal\Core\Path\Path to \Drupal\Core\Path\AliasStorage.

parent ef256397
......@@ -149,7 +149,7 @@ services:
arguments: [path_alias_whitelist, '@cache.default', '@lock', '@state', '@database']
path.alias_manager:
class: Drupal\Core\Path\AliasManager
arguments: ['@path.crud', '@path.alias_whitelist', '@language_manager']
arguments: ['@path.alias_storage', '@path.alias_whitelist', '@language_manager']
http_client_simpletest_subscriber:
class: Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber
http_default_client:
......@@ -353,8 +353,8 @@ services:
path.alias_manager.cached:
class: Drupal\Core\CacheDecorator\AliasManagerCacheDecorator
arguments: ['@path.alias_manager', '@cache.data']
path.crud:
class: Drupal\Core\Path\Path
path.alias_storage:
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
......
......@@ -115,7 +115,7 @@ function path_load($conditions) {
elseif (!is_array($conditions)) {
return FALSE;
}
return \Drupal::service('path.crud')->load($conditions);
return \Drupal::service('path.alias_storage')->load($conditions);
}
/**
......
......@@ -13,11 +13,11 @@
class AliasManager implements AliasManagerInterface {
/**
* The Path CRUD service.
* The alias storage service.
*
* @var \Drupal\Core\Path\PathInterface
* @var \Drupal\Core\Path\AliasStorageInterface
*/
protected $path;
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\PathInterface $path
* The Path CRUD service.
* @param \Drupal\Core\Path\AliasStorageInterface $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(PathInterface $path, AliasWhitelistInterface $whitelist, LanguageManager $language_manager) {
$this->path = $path;
public function __construct(AliasStorageInterface $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->path->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->path->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->path->lookupPathSource($path, $langcode)) {
if ($source = $this->storage->lookupPathSource($path, $langcode)) {
$this->lookupMap[$langcode][$source] = $path;
}
else {
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Path\Path.
* Contains \Drupal\Core\Path\AliasStorage.
*/
namespace Drupal\Core\Path;
......@@ -14,8 +14,7 @@
/**
* Provides a class for CRUD operations on path aliases.
*/
class Path implements PathInterface {
class AliasStorage implements AliasStorageInterface {
/**
* The database connection.
*
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Path\PathInterface.
* Contains \Drupal\Core\Path\AliasStorageInterface.
*/
namespace Drupal\Core\Path;
......@@ -12,7 +12,7 @@
/**
* Provides a class for CRUD operations on path aliases.
*/
interface PathInterface {
interface AliasStorageInterface {
/**
* Saves a path alias to the database.
......
......@@ -83,7 +83,7 @@ public function submitForm(array &$form, array &$form_state) {
if (\Drupal::moduleHandler()->moduleExists('path')) {
$path = $this->entity->getSystemPath();
$conditions = array('source' => $path, 'langcode' => $this->language->id);
\Drupal::service('path.crud')->delete($conditions);
\Drupal::service('path.alias_storage')->delete($conditions);
}
$form_state['redirect_route'] = $this->getCancelRoute();
......
......@@ -108,13 +108,13 @@ function testPathLanguageConfiguration() {
'alias' => $custom_path,
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
);
$this->container->get('path.crud')->save($edit['source'], $edit['alias'], $edit['langcode']);
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
$lookup_path = $this->container->get('path.alias_manager')->getPathAlias('node/' . $node->id(), 'en');
$this->assertEqual($english_path, $lookup_path, 'English language alias has priority.');
// Same check for language 'xx'.
$lookup_path = $this->container->get('path.alias_manager')->getPathAlias('node/' . $node->id(), $prefix);
$this->assertEqual($custom_language_path, $lookup_path, 'Custom language alias has priority.');
$this->container->get('path.crud')->delete($edit);
$this->container->get('path.alias_storage')->delete($edit);
// Create language nodes to check priority of aliases.
$first_node = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1, 'langcode' => 'en'));
......@@ -126,7 +126,7 @@ function testPathLanguageConfiguration() {
'alias' => $custom_path,
'langcode' => $first_node->language()->id,
);
$this->container->get('path.crud')->save($edit['source'], $edit['alias'], $edit['langcode']);
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
// Assign a custom path alias to second node with Language::LANGCODE_NOT_SPECIFIED.
$edit = array(
......@@ -134,7 +134,7 @@ function testPathLanguageConfiguration() {
'alias' => $custom_path,
'langcode' => $second_node->language()->id,
);
$this->container->get('path.crud')->save($edit['source'], $edit['alias'], $edit['langcode']);
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
// Test that both node titles link to our path alias.
$this->drupalGet('<front>');
......
......@@ -7,7 +7,7 @@
namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\Core\Path\PathInterface;
use Drupal\Core\Path\AliasStorage;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -21,11 +21,11 @@
class UrlAlias extends DestinationBase implements ContainerFactoryPluginInterface {
/**
* The path crud service.
* The alias storage service.
*
* @var \Drupal\Core\Path\PathInterface $path
* @var \Drupal\Core\Path\AliasStorage $aliasStorage
*/
protected $path;
protected $aliasStorage;
/**
* Constructs an entity destination plugin.
......@@ -38,12 +38,12 @@ class UrlAlias extends DestinationBase implements ContainerFactoryPluginInterfac
* The plugin implementation definition.
* @param MigrationInterface $migration
* The migration.
* @param \Drupal\Core\Path\PathInterface $path
* @param \Drupal\Core\Path\AliasStorage $alias_storage
* The path crud service.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, PathInterface $path) {
public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, AliasStorage $alias_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
$this->path = $path;
$this->aliasStorage = $alias_storage;
}
/**
......@@ -55,7 +55,7 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$migration,
$container->get('path.crud')
$container->get('path.alias_storage')
);
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\path\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Path\PathInterface;
use Drupal\Core\Path\AliasStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -17,11 +17,11 @@
class DeleteForm extends ConfirmFormBase {
/**
* The path crud service.
* The alias storage service.
*
* @var PathInterface $path
* @var AliasStorageInterface $path
*/
protected $path;
protected $aliasStorage;
/**
* The path alias being deleted.
......@@ -33,11 +33,11 @@ class DeleteForm extends ConfirmFormBase {
/**
* Constructs a \Drupal\path\Form\DeleteForm object.
*
* @param \Drupal\Core\Path\PathInterface $path
* The path crud service.
* @param \Drupal\Core\Path\AliasStorageInterface $alias_storage
* The alias storage service.
*/
public function __construct(PathInterface $path) {
$this->path = $path;
public function __construct(AliasStorageInterface $alias_storage) {
$this->aliasStorage = $alias_storage;
}
/**
......@@ -45,7 +45,7 @@ public function __construct(PathInterface $path) {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('path.crud')
$container->get('path.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->path->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->path->delete(array('pid' => $this->pathAlias['pid']));
$this->aliasStorage->delete(array('pid' => $this->pathAlias['pid']));
$form_state['redirect'] = 'admin/config/search/path';
}
......
......@@ -58,7 +58,7 @@ public function insert() {
// Ensure fields for programmatic executions.
$langcode = $entity->language()->id;
if ($path = \Drupal::service('path.crud')->save($entity->getSystemPath(), $this->alias, $langcode)) {
if ($path = \Drupal::service('path.alias_storage')->save($entity->getSystemPath(), $this->alias, $langcode)) {
$this->pid = $path['pid'];
}
}
......@@ -70,7 +70,7 @@ public function insert() {
public function update() {
// Delete old alias if user erased it.
if ($this->pid && !$this->alias) {
\Drupal::service('path.crud')->delete(array('pid' => $this->pid));
\Drupal::service('path.alias_storage')->delete(array('pid' => $this->pid));
}
// Only save a non-empty alias.
elseif ($this->alias) {
......@@ -79,7 +79,7 @@ public function update() {
// Ensure fields for programmatic executions.
$langcode = $entity->language()->id;
\Drupal::service('path.crud')->save($entity->getSystemPath(), $this->alias, $langcode, $this->pid);
\Drupal::service('path.alias_storage')->save($entity->getSystemPath(), $this->alias, $langcode, $this->pid);
}
}
......@@ -89,7 +89,7 @@ public function update() {
public function delete() {
// Delete all aliases associated with this entity.
$entity = $this->getEntity();
\Drupal::service('path.crud')->delete(array('source' => $entity->getSystemPath()));
\Drupal::service('path.alias_storage')->delete(array('source' => $entity->getSystemPath()));
}
}
......@@ -268,7 +268,7 @@ function path_admin_form_submit($form, &$form_state) {
// languages.
$langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : Language::LANGCODE_NOT_SPECIFIED;
\Drupal::service('path.crud')->save($source, $alias, $langcode, $pid);
\Drupal::service('path.alias_storage')->save($source, $alias, $langcode, $pid);
drupal_set_message(t('The alias has been saved.'));
$form_state['redirect'] = 'admin/config/search/path';
......
......@@ -67,7 +67,7 @@ function path_form_node_form_alter(&$form, $form_state) {
if ($node->language()->id != Language::LANGCODE_NOT_SPECIFIED) {
$conditions['langcode'] = $node->language()->id;
}
$path = \Drupal::service('path.crud')->load($conditions);
$path = \Drupal::service('path.alias_storage')->load($conditions);
if ($path === FALSE) {
$path = array();
}
......@@ -153,7 +153,7 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) {
// Make sure this does not show up on the delete confirmation form.
if (empty($form_state['confirm_delete'])) {
$term = $form_state['controller']->getEntity();
$path = ($term->id() ? \Drupal::service('path.crud')->load(array('source' => 'taxonomy/term/' . $term->id())) : array());
$path = ($term->id() ? \Drupal::service('path.alias_storage')->load(array('source' => 'taxonomy/term/' . $term->id())) : array());
if ($path === FALSE) {
$path = array();
}
......
......@@ -38,7 +38,7 @@ public function testShortcutLinkAdd() {
'source' => 'node/' . $this->node->id(),
'alias' => $this->randomName(8),
);
$this->container->get('path.crud')->save($path['source'], $path['alias']);
$this->container->get('path.alias_storage')->save($path['source'], $path['alias']);
// Create some paths to test.
$test_cases = array(
......
......@@ -8,7 +8,7 @@
namespace Drupal\system\Tests\Path;
use Drupal\Core\Cache\MemoryCounterBackend;
use Drupal\Core\Path\Path;
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.
$path = new Path($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) {
$path->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 = $path->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) {
$path->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'];
$path->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');
$pathObject = new Path($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',
);
$pathObject->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',
);
$pathObject->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',
);
$pathObject->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',
);
$pathObject->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',
);
$pathObject->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'.
$pathObject->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.
$pathObject->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);
$path = new Path($connection, $this->container->get('module_handler'));
$aliasManager = new AliasManager($path, $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.
$path->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.
$path->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.
$path->delete(array('source' => 'user/1'));
$aliasStorage->delete(array('source' => 'user/1'));
$aliasManager->cacheClear();
$this->assertNull($whitelist->get('user'));
$this->assertTrue($whitelist->get('admin'));
......
......@@ -46,7 +46,7 @@ function testUrlAlter() {
// Test that a path always uses its alias.
$path = array('source' => "user/$uid/test1", 'alias' => 'alias/test1');
$this->container->get('path.crud')->save($path['source'], $path['alias']);
$this->container->get('path.alias_storage')->save($path['source'], $path['alias']);
$this->rebuildContainer();
$this->assertUrlInboundAlter('alias/test1', "user/$uid/test1");
$this->assertUrlOutboundAlter("user/$uid/test1", 'alias/test1');
......
......@@ -252,7 +252,7 @@
'alias' => "content/poll/$i/results",
'source' => "node/$node->nid/results",
);
\Drupal::service('path.crud')->save($path['source'], $path['alias']);
\Drupal::service('path.alias_storage')->save($path['source'], $path['alias']);
// Add some votes
$node = node_load($node->nid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment