diff --git a/core/modules/link/src/Tests/LinkFieldTest.php b/core/modules/link/src/Tests/LinkFieldTest.php index c596c53..0986546 100644 --- a/core/modules/link/src/Tests/LinkFieldTest.php +++ b/core/modules/link/src/Tests/LinkFieldTest.php @@ -98,7 +98,12 @@ function testURLValidation() { $this->assertRaw('placeholder="http://example.com"'); // Create a path alias. - \Drupal::service('path.alias_storage')->save('admin', 'a/path/alias'); + \Drupal::service('entity.manager')->getStorage('alias')->create( + array( + 'path' => 'admin', + 'alias' => 'a/path/alias', + ) + )->save(); // Define some valid URLs. $valid_external_entries = array( 'http://www.example.com/', diff --git a/core/modules/migrate/src/Plugin/migrate/destination/UrlAlias.php b/core/modules/migrate/src/Plugin/migrate/destination/UrlAlias.php index 6312198..b386d99 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/UrlAlias.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/UrlAlias.php @@ -7,7 +7,7 @@ namespace Drupal\migrate\Plugin\migrate\destination; -use Drupal\Core\Path\AliasStorage; +use Drupal\Core\Entity\EntityManagerInterface; 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 alias storage service. + * The entity manager service. * - * @var \Drupal\Core\Path\AliasStorage $aliasStorage + * @var \Drupal\Core\Entity\EntityManagerInterface */ - protected $aliasStorage; + protected $entityManager; /** * 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\AliasStorage $alias_storage - * The alias storage service. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, AliasStorage $alias_storage) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); - $this->aliasStorage = $alias_storage; + $this->entityManager = $entity_manager; } /** @@ -55,7 +55,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_id, $plugin_definition, $migration, - $container->get('path.alias_storage') + $container->get('entity.manager') ); } @@ -63,22 +63,39 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { + if ($old_destination_id_values) { + /** @var \Drupal\Core\Path\AliasInterface $alias */ + $alias = $this->entityManager + ->getStorage('alias') + ->load($old_destination_id_values[0]); - $path = $this->aliasStorage->save( - $row->getDestinationProperty('source'), - $row->getDestinationProperty('alias'), - $row->getDestinationProperty('langcode'), - $old_destination_id_values ? $old_destination_id_values[0] : NULL - ); + $alias->alias = $row->getDestinationProperty('alias'); + $alias->path = $row->getDestinationProperty('path'); + $alias->langcode = $row->getDestinationProperty('langcode'); + $alias->save(); + } + else { + /** @var \Drupal\Core\Path\AliasInterface $alias */ + $alias = $this->entityManager + ->getStorage('alias') + ->create( + array( + 'path' => $row->getDestinationProperty('path'), + 'alias' => $row->getDestinationProperty('alias'), + 'langcode' => $row->getDestinationProperty('langcode'), + ) + ); + $alias->save(); + } - return array($path['pid']); + return array($alias->id()); } /** * {@inheritdoc} */ public function getIds() { - $ids['pid']['type'] = 'integer'; + $ids['aid']['type'] = 'integer'; return $ids; } @@ -87,8 +104,8 @@ public function getIds() { */ public function fields(MigrationInterface $migration = NULL) { return [ - 'pid' => 'The path id', - 'source' => 'The source path.', + 'aid' => 'The alias id', + 'path' => 'The source path.', 'alias' => 'The url alias.', 'langcode' => 'The language code for the url.', ]; diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_url_alias.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_url_alias.yml index 39d3234..871170b 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_url_alias.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_url_alias.yml @@ -6,7 +6,7 @@ source: plugin: d6_url_alias process: - source: src + path: src alias: dst langcode: language diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUrlAliasTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUrlAliasTest.php index 8449cba..4905c8c 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUrlAliasTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUrlAliasTest.php @@ -39,21 +39,22 @@ protected function setUp() { public function testUrlAlias() { $migration = entity_load('migration', 'd6_url_alias'); // Test that the field exists. - $conditions = array( - 'source' => 'node/1', - 'alias' => 'alias-one', - 'langcode' => 'en', - ); - $path = \Drupal::service('path.alias_storage')->load($conditions); - $this->assertNotNull($path, "Path alias for node/1 successfully loaded."); - $this->assertEqual(array(1), $migration->getIdMap()->lookupDestinationID(array($path['pid'])), "Test IdMap"); - $conditions = array( - 'source' => 'node/2', - 'alias' => 'alias-two', - 'langcode' => 'en', - ); - $path = \Drupal::service('path.alias_storage')->load($conditions); - $this->assertNotNull($path, "Path alias for node/2 successfully loaded."); + $aids = \Drupal::entityQuery('alias') + ->condition('alias', 'alias-one') + ->condition('path', 'node/1') + ->condition('langcode', 'en') + ->execute(); + + $this->assertTrue((bool) $aids, "Path alias for node/1 successfully loaded."); + $alias = \Drupal::entityManager()->getStorage('alias')->load(reset($aids)); + $this->assertEqual(array(1), $migration->getIdMap()->lookupDestinationID(array($alias->id())), "Test IdMap"); + $aids = \Drupal::entityQuery('alias') + ->condition('alias', 'alias-two') + ->condition('path', 'node/2') + ->condition('langcode', 'en') + ->execute(); + $this->assertTrue((bool) $aids, "Path alias for node/2 successfully loaded."); + $alias = \Drupal::entityManager()->getStorage('alias')->load(reset($aids)); // Test that we can re-import using the UrlAlias destination. Database::getConnection('default', 'migrate') @@ -69,8 +70,8 @@ public function testUrlAlias() { $executable = new MigrateExecutable($migration, $this); $executable->import(); - $path = \Drupal::service('path.alias_storage')->load(array('pid' => $path['pid'])); - $this->assertEqual($path['alias'], 'new-url-alias'); + $alias = \Drupal::entityManager()->getStorage('alias')->load($alias->id()); + $this->assertEqual($alias->get('alias')->value, 'new-url-alias'); } } diff --git a/core/modules/path/path.routing.yml b/core/modules/path/path.routing.yml index d3e44c3..0635704 100644 --- a/core/modules/path/path.routing.yml +++ b/core/modules/path/path.routing.yml @@ -1,5 +1,5 @@ path.delete: - path: '/admin/config/search/path/delete/{pid}' + path: '/admin/config/search/path/delete/{aid}' defaults: _form: '\Drupal\path\Form\DeleteForm' _title: 'Delete alias' @@ -32,7 +32,7 @@ path.admin_add: _permission: 'administer url aliases' path.admin_edit: - path: '/admin/config/search/path/edit/{pid}' + path: '/admin/config/search/path/edit/{aid}' defaults: _title: 'Edit alias' _form: '\Drupal\path\Form\EditForm' diff --git a/core/modules/path/src/Controller/PathController.php b/core/modules/path/src/Controller/PathController.php index 7b404a2..5556012 100644 --- a/core/modules/path/src/Controller/PathController.php +++ b/core/modules/path/src/Controller/PathController.php @@ -80,7 +80,7 @@ public function adminOverview($keys) { 'title' => $this->t('Edit'), 'route_name' => 'path.admin_edit', 'route_parameters' => array( - 'pid' => $data->aid, + 'aid' => $data->aid, ), 'query' => $destination, ); @@ -88,7 +88,7 @@ public function adminOverview($keys) { 'title' => $this->t('Delete'), 'route_name' => 'path.delete', 'route_parameters' => array( - 'pid' => $data->aid, + 'aid' => $data->aid, ), 'query' => $destination, ); diff --git a/core/modules/path/src/Form/DeleteForm.php b/core/modules/path/src/Form/DeleteForm.php index eda690e..3eb5e44 100644 --- a/core/modules/path/src/Form/DeleteForm.php +++ b/core/modules/path/src/Form/DeleteForm.php @@ -28,7 +28,7 @@ class DeleteForm extends ConfirmFormBase { /** * The path alias being deleted. * - * @var array $pathAlias + * @var \Drupal\Core\Path\AliasInterface $pathAlias */ protected $pathAlias; @@ -62,7 +62,7 @@ public function getFormId() { * Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion(). */ public function getQuestion() { - return t('Are you sure you want to delete path alias %title?', array('%title' => $this->pathAlias['alias'])); + return t('Are you sure you want to delete path alias %title?', array('%title' => $this->pathAlias->get('alias')->value)); } /** @@ -87,9 +87,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $aid = NU * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - - $this->entityManager->getStorage('alias')->delete(array($this->pathAlias['aid'])); - + $this->pathAlias->delete(); $form_state->setRedirect('path.admin_overview'); } diff --git a/core/modules/path/src/Form/EditForm.php b/core/modules/path/src/Form/EditForm.php index f4d647e..412f1c0 100644 --- a/core/modules/path/src/Form/EditForm.php +++ b/core/modules/path/src/Form/EditForm.php @@ -36,7 +36,7 @@ protected function buildPath($aid) { public function buildForm(array $form, FormStateInterface $form_state, $aid = NULL) { $form = parent::buildForm($form, $form_state, $aid); - $form['#title'] = String::checkPlain($this->alias->get('alias')); + $form['#title'] = String::checkPlain($this->alias->get('alias')->value); $form['aid'] = array( '#type' => 'hidden', '#value' => $this->alias->id(), diff --git a/core/modules/path/src/Form/PathFormBase.php b/core/modules/path/src/Form/PathFormBase.php index 4f0836a..cdb783d 100644 --- a/core/modules/path/src/Form/PathFormBase.php +++ b/core/modules/path/src/Form/PathFormBase.php @@ -174,7 +174,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $aid = $form_state->getValue('aid', 0); $path = &$form_state->getValue('path'); $path = $this->aliasManager->getPathByAlias($path); - $alias = $form_state->getValue('alias'); + $alias_value = $form_state->getValue('alias'); // Language is only set if language.module is enabled, otherwise save for all // languages. $langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED); @@ -182,7 +182,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { if (empty($aid)) { $alias = $this->entityManager->getStorage('alias')->create( array( - 'alias' => $alias, + 'alias' => $alias_value, 'path' => $path, 'langcode' => $langcode, ) @@ -192,7 +192,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { else { $alias = $this->entityManager->getStorage('alias')->load($aid); $alias->path = $path; - $alias->alias = $alias; + $alias->alias = $alias_value; $alias->langcode = $langcode; $alias->save(); } diff --git a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php index 1eab340..bf18cb3 100644 --- a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php +++ b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php @@ -79,12 +79,22 @@ public function insert() { public function update() { // Delete old alias if user erased it. if ($this->aid && !$this->alias) { - \Drupal::entityManager()->getStorage('alias')->delete(array($this->aid)); + $alias = \Drupal::entityManager()->getStorage('alias')->load($this->aid); + $alias->delete(); } // Only save a non-empty alias. elseif ($this->alias) { $entity = $this->getEntity(); - $alias = \Drupal::entityManager()->getStorage('alias')->load($this->aid); + if ($this->aid) { + $alias = \Drupal::entityManager() + ->getStorage('alias') + ->load($this->aid); + } + else { + $alias = \Drupal::entityManager() + ->getStorage('alias') + ->create(); + } $alias->path = $entity->getSystemPath(); $alias->alias = $this->alias; $alias->langcode = $this->getLangcode(); diff --git a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php index 0971839..f432b31 100644 --- a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php +++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php @@ -38,8 +38,13 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen if ($items->getLangcode() != LanguageInterface::LANGCODE_NOT_SPECIFIED) { $query->condition('langcode', $items->getLangcode()); } - $alias = reset($query->execute()); - $alias = \Drupal::entityManager()->getStorage('alias')->load($alias); + $aids = $query->execute(); + + if ($aids) { + $alias = reset($aids); + /** @var $alias \Drupal\Core\Path\AliasInterface */ + $alias = \Drupal::entityManager()->getStorage('alias')->load($alias); + } } $element += array( @@ -48,7 +53,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element['alias'] = array( '#type' => 'textfield', '#title' => $element['#title'], - '#default_value' => empty($alias) ? '' : $alias->alias, + '#default_value' => empty($alias) ? '' : $alias->get('alias')->value, '#required' => $element['#required'], '#maxlength' => 255, '#description' => $this->t('The alternative URL for this content. Use a relative path without a trailing slash. For example, enter "about" for the about page.'), @@ -59,11 +64,11 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ); $element['path'] = array( '#type' => 'value', - '#value' => empty($alias) ? (!$entity->isNew() ? $entity->getSystemPath() : NULL) : $alias->path, + '#value' => empty($alias) ? (!$entity->isNew() ? $entity->getSystemPath() : NULL) : $alias->path->value, ); $element['langcode'] = array( '#type' => 'value', - '#value' => empty($alias) ? $items->getLangcode() : $alias->langcode, + '#value' => empty($alias) ? $items->getLangcode() : $alias->langcode->value, ); return $element; } @@ -83,7 +88,7 @@ public static function validateFormElement(array &$element, FormStateInterface $ $form_state->setValueForElement($element['alias'], $alias); // Validate that the submitted alias does not exist yet. - $is_exists = \Drupal::entityManager()->getStorage('alias')->aliasExists($alias, $element['langcode']['#value'], $element['source']['#value']); + $is_exists = \Drupal::entityManager()->getStorage('alias')->aliasExists($alias, $element['langcode']['#value'], $element['path']['#value']); if ($is_exists) { $form_state->setError($element, t('The alias is already in use.')); } diff --git a/core/modules/path/src/Tests/PathAdminTest.php b/core/modules/path/src/Tests/PathAdminTest.php index ef1d3e7..f081271 100644 --- a/core/modules/path/src/Tests/PathAdminTest.php +++ b/core/modules/path/src/Tests/PathAdminTest.php @@ -40,14 +40,14 @@ public function testPathFiltering() { // Create aliases. $alias1 = $this->randomMachineName(8); $edit = array( - 'source' => 'node/' . $node1->id(), + 'path' => 'node/' . $node1->id(), 'alias' => $alias1, ); $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); $alias2 = $this->randomMachineName(8); $edit = array( - 'source' => 'node/' . $node2->id(), + 'path' => 'node/' . $node2->id(), 'alias' => $alias2, ); $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); diff --git a/core/modules/path/src/Tests/PathAliasTest.php b/core/modules/path/src/Tests/PathAliasTest.php index 134f9d7..839cb3fd 100644 --- a/core/modules/path/src/Tests/PathAliasTest.php +++ b/core/modules/path/src/Tests/PathAliasTest.php @@ -39,7 +39,7 @@ function testPathCache() { // Create alias. $edit = array(); - $edit['source'] = 'node/' . $node1->id(); + $edit['path'] = 'node/' . $node1->id(); $edit['alias'] = $this->randomMachineName(8); $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); @@ -52,13 +52,13 @@ function testPathCache() { // created. \Drupal::cache('data')->deleteAll(); // Make sure the path is not converted to the alias. - $this->drupalGet($edit['source'], array('alias' => TRUE)); - $this->assertTrue(\Drupal::cache('data')->get('preload-paths:' . $edit['source']), 'Cache entry was created.'); + $this->drupalGet($edit['path'], array('alias' => TRUE)); + $this->assertTrue(\Drupal::cache('data')->get('preload-paths:' . $edit['path']), 'Cache entry was created.'); // Visit the alias for the node and confirm a cache entry is created. \Drupal::cache('data')->deleteAll(); $this->drupalGet($edit['alias']); - $this->assertTrue(\Drupal::cache('data')->get('preload-paths:' . $edit['source']), 'Cache entry was created.'); + $this->assertTrue(\Drupal::cache('data')->get('preload-paths:' . $edit['path']), 'Cache entry was created.'); } /** @@ -70,7 +70,7 @@ function testAdminAlias() { // Create alias. $edit = array(); - $edit['source'] = 'node/' . $node1->id(); + $edit['path'] = 'node/' . $node1->id(); $edit['alias'] = $this->randomMachineName(8); $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); @@ -80,13 +80,13 @@ function testAdminAlias() { $this->assertResponse(200); // Change alias to one containing "exotic" characters. - $pid = $this->getPID($edit['alias']); + $aid = $this->getAID($edit['alias']); $previous = $edit['alias']; $edit['alias'] = "- ._~!$'\"()*@[]?&+%#,;=:" . // "Special" ASCII characters. "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string. "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets. - $this->drupalPostForm('admin/config/search/path/edit/' . $pid, $edit, t('Save')); + $this->drupalPostForm('admin/config/search/path/edit/' . $aid, $edit, t('Save')); // Confirm that the alias works. $this->drupalGet($edit['alias']); @@ -103,7 +103,7 @@ function testAdminAlias() { $node2 = $this->drupalCreateNode(); // Set alias to second test node. - $edit['source'] = 'node/' . $node2->id(); + $edit['path'] = 'node/' . $node2->id(); // leave $edit['alias'] the same $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); @@ -111,7 +111,7 @@ function testAdminAlias() { $this->assertRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['alias'])), 'Attempt to move alias was rejected.'); // Delete alias. - $this->drupalPostForm('admin/config/search/path/edit/' . $pid, array(), t('Delete')); + $this->drupalPostForm('admin/config/search/path/edit/' . $aid, array(), t('Delete')); $this->drupalPostForm(NULL, array(), t('Confirm')); // Confirm that the alias no longer works. @@ -121,7 +121,7 @@ function testAdminAlias() { // Create a really long alias. $edit = array(); - $edit['source'] = 'node/' . $node1->id(); + $edit['path'] = 'node/' . $node1->id(); $alias = $this->randomMachineName(128); $edit['alias'] = $alias; // The alias is shortened to 50 characters counting the elipsis. @@ -192,16 +192,16 @@ function testNodeAlias() { } /** - * Returns the path ID. + * Returns the alias ID. * * @param $alias * A string containing an aliased path. * * @return int - * Integer representing the path ID. + * Integer representing the alias ID. */ - function getPID($alias) { - return db_query("SELECT pid FROM {url_alias} WHERE alias = :alias", array(':alias' => $alias))->fetchField(); + function getAID($alias) { + return db_query("SELECT aid FROM {alias_field_data} WHERE alias = :alias", array(':alias' => $alias))->fetchField(); } /**