Loading src/Entity/Redirect.php +5 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,11 @@ class Redirect extends ContentEntityBase { * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage_controller) { // Strip any trailing slashes as these are removed when looking for matching // redirects. // @see \Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirect() $this->redirect_source->path = rtrim($this->redirect_source->path, '/'); // Get the language code directly from the field as language() might not // be up to date if the language was just changed. $this->set('hash', Redirect::generateHash($this->redirect_source->path, (array) $this->redirect_source->query, $this->get('language')->value)); Loading tests/src/Kernel/RedirectAPITest.php +2 −1 Original line number Diff line number Diff line Loading @@ -167,7 +167,8 @@ class RedirectAPITest extends KernelTestBase { */ public function testDuplicateRedirectEntry() { $redirect = $this->storage->create(); $redirect->setSource('/foo/foo', []); // The trailing slash should be removed on pre-save. $redirect->setSource('/foo/foo/', []); $redirect->setRedirect('foo'); $redirect->save(); Loading Loading
src/Entity/Redirect.php +5 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,11 @@ class Redirect extends ContentEntityBase { * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage_controller) { // Strip any trailing slashes as these are removed when looking for matching // redirects. // @see \Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirect() $this->redirect_source->path = rtrim($this->redirect_source->path, '/'); // Get the language code directly from the field as language() might not // be up to date if the language was just changed. $this->set('hash', Redirect::generateHash($this->redirect_source->path, (array) $this->redirect_source->query, $this->get('language')->value)); Loading
tests/src/Kernel/RedirectAPITest.php +2 −1 Original line number Diff line number Diff line Loading @@ -167,7 +167,8 @@ class RedirectAPITest extends KernelTestBase { */ public function testDuplicateRedirectEntry() { $redirect = $this->storage->create(); $redirect->setSource('/foo/foo', []); // The trailing slash should be removed on pre-save. $redirect->setSource('/foo/foo/', []); $redirect->setRedirect('foo'); $redirect->save(); Loading