Commit a77605d1 authored by alexpott's avatar alexpott

Issue #2377343 by tim.plunkett: Url alias system path cannot be edited without changing the alias

parent 640f5286
......@@ -150,14 +150,14 @@ public function buildForm(array $form, FormStateInterface $form_state, $pid = NU
public function validateForm(array &$form, FormStateInterface $form_state) {
$source = &$form_state->getValue('source');
$source = $this->aliasManager->getPathByAlias($source);
$alias = $form_state->getValue('alias');
$alias = &$form_state->getValue('alias');
// Trim the submitted value of whitespace and slashes.
$alias = trim(trim($alias), " \\/");
// Language is only set if language.module is enabled, otherwise save for all
// languages.
$langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED);
if ($this->aliasStorage->aliasExists($alias, $langcode, $source)) {
if ($this->aliasStorage->aliasExists($alias, $langcode, $this->path['source'])) {
$form_state->setErrorByName('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias)));
}
if (!$this->pathValidator->isValid($source)) {
......@@ -173,11 +173,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->cleanValues();
$pid = $form_state->getValue('pid', 0);
$source = &$form_state->getValue('source');
$source = $this->aliasManager->getPathByAlias($source);
$source = $form_state->getValue('source');
$alias = $form_state->getValue('alias');
// Trim the submitted value of whitespace and slashes.
$alias = trim(trim($alias), " \\/");
// Language is only set if language.module is enabled, otherwise save for all
// languages.
$langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED);
......
......@@ -137,7 +137,8 @@ function testAdminAlias() {
// Create absolute path alias.
$edit = array();
$edit['source'] = 'node/' . $node3->id();
$edit['alias'] = '/' . $this->randomMachineName(8);
$node3_alias = $this->randomMachineName(8);
$edit['alias'] = '/' . $node3_alias;
$this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
// Confirm that the alias was converted to a relative path.
......@@ -151,13 +152,35 @@ function testAdminAlias() {
// Create alias with trailing slash.
$edit = array();
$edit['source'] = 'node/' . $node4->id();
$edit['alias'] = $this->randomMachineName(8) . '/';
$node4_alias = $this->randomMachineName(8);
$edit['alias'] = $node4_alias . '/';
$this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
// Confirm that the alias with trailing slash is not found.
$this->assertNoText($edit['alias'], 'The absolute alias was not found.');
// The alias without trailing flash is found.
$this->assertText(trim($edit['alias'], '/'), 'The alias without trailing slash was found.');
// Update an existing alias to point to a different source.
$pid = $this->getPID($node4_alias);
$edit = [];
$edit['alias'] = $node4_alias;
$edit['source'] = 'node/' . $node2->id();
$this->drupalPostForm('admin/config/search/path/edit/' . $pid, $edit, t('Save'));
$this->assertText('The alias has been saved.');
$this->drupalGet($edit['alias']);
$this->assertNoText($node4->label(), 'Previous alias no longer works.');
$this->assertText($node2->label(), 'Alias works.');
$this->assertResponse(200);
// Update an existing alias to use a duplicate alias.
$pid = $this->getPID($node3_alias);
$edit = [];
$edit['alias'] = $node4_alias;
$edit['source'] = 'node/' . $node3->id();
$this->drupalPostForm('admin/config/search/path/edit/' . $pid, $edit, t('Save'));
$this->assertRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['alias'])));
}
/**
......
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