Commit c78a5c29 authored by alexpott's avatar alexpott

Issue #1854284 by Berdir, mikeryan | Dave Reid: Fixed Path aliases are no...

Issue #1854284 by Berdir, mikeryan | Dave Reid: Fixed Path aliases are no longer arrays and cannot pass additional data to path hooks.
parent 650bc9f8
......@@ -63,11 +63,15 @@ public function save($source, $alias, $langcode = LanguageInterface::LANGCODE_NO
$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) {
......
......@@ -33,6 +33,8 @@
* - 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);
......
......@@ -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().
*
......
......@@ -52,7 +52,9 @@ function testCRUD() {
//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();
......
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