summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-09-12 14:46:40 (GMT)
committerAlex Pott2014-09-12 14:46:40 (GMT)
commitc78a5c29d9a3f1f86d3ac8f2b5a3c0a849f3f328 (patch)
tree0fe496570e15fb43fa20015eb1dda12d24251d81
parent650bc9f803dc37754ce7032c3ac6c1fa7c753129 (diff)
Issue #1854284 by Berdir, mikeryan | Dave Reid: Fixed Path aliases are no longer arrays and cannot pass additional data to path hooks.
-rw-r--r--core/lib/Drupal/Core/Path/AliasStorage.php4
-rw-r--r--core/lib/Drupal/Core/Path/AliasStorageInterface.php2
-rw-r--r--core/modules/path/path.api.php14
-rw-r--r--core/modules/system/src/Tests/Path/AliasTest.php4
4 files changed, 17 insertions, 7 deletions
diff --git a/core/lib/Drupal/Core/Path/AliasStorage.php b/core/lib/Drupal/Core/Path/AliasStorage.php
index b405a25..153866b 100644
--- a/core/lib/Drupal/Core/Path/AliasStorage.php
+++ b/core/lib/Drupal/Core/Path/AliasStorage.php
@@ -63,11 +63,15 @@ class AliasStorage implements AliasStorageInterface {
$operation = 'insert';
}
else {
+ // Fetch the current values so that an update hook can identify what
+ // exactly changed.
+ $original = $this->connection->query('SELECT source, alias, langcode FROM {url_alias} WHERE pid = :pid', array(':pid' => $pid))->fetchAssoc();
$fields['pid'] = $pid;
$query = $this->connection->update('url_alias')
->fields($fields)
->condition('pid', $pid);
$pid = $query->execute();
+ $fields['original'] = $original;
$operation = 'update';
}
if ($pid) {
diff --git a/core/lib/Drupal/Core/Path/AliasStorageInterface.php b/core/lib/Drupal/Core/Path/AliasStorageInterface.php
index a98600f..30364fd 100644
--- a/core/lib/Drupal/Core/Path/AliasStorageInterface.php
+++ b/core/lib/Drupal/Core/Path/AliasStorageInterface.php
@@ -33,6 +33,8 @@ interface AliasStorageInterface {
* - alias (string): The URL alias.
* - pid (int): Unique path alias identifier.
* - langcode (string): The language code of the alias.
+ * - original: For updates, an array with source, alias and langcode with
+ * the previous values.
*/
public function save($source, $alias, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $pid = NULL);
diff --git a/core/modules/path/path.api.php b/core/modules/path/path.api.php
index 478fc6f..04e1fb3 100644
--- a/core/modules/path/path.api.php
+++ b/core/modules/path/path.api.php
@@ -31,23 +31,25 @@ function hook_path_insert($path) {
/**
* Respond to a path being updated.
*
- * @param $path
+ * @param array $path
* The array structure is identical to that of the return value of
* \Drupal\Core\Path\PathInterface::save().
*
* @see \Drupal\Core\Path\PathInterface::save()
*/
function hook_path_update($path) {
- db_update('mytable')
- ->fields(array('alias' => $path['alias']))
- ->condition('pid', $path['pid'])
- ->execute();
+ if ($path['alias'] != $path['original']['alias']) {
+ db_update('mytable')
+ ->fields(array('alias' => $path['alias']))
+ ->condition('pid', $path['pid'])
+ ->execute();
+ }
}
/**
* Respond to a path being deleted.
*
- * @param $path
+ * @param array $path
* The array structure is identical to that of the return value of
* \Drupal\Core\Path\PathInterface::save().
*
diff --git a/core/modules/system/src/Tests/Path/AliasTest.php b/core/modules/system/src/Tests/Path/AliasTest.php
index 0deddc8..d91c59f 100644
--- a/core/modules/system/src/Tests/Path/AliasTest.php
+++ b/core/modules/system/src/Tests/Path/AliasTest.php
@@ -52,7 +52,9 @@ class AliasTest extends PathUnitTestBase {
//Update a few aliases
foreach ($aliases as $alias) {
- $aliasStorage->save($alias['source'], $alias['alias'] . '_updated', $alias['langcode'], $alias['pid']);
+ $fields = $aliasStorage->save($alias['source'], $alias['alias'] . '_updated', $alias['langcode'], $alias['pid']);
+
+ $this->assertEqual($alias['alias'], $fields['original']['alias']);
$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();