diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php index 21ebeb0..6c3711d 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -284,7 +284,7 @@ public function testContactConfigEntityTranslation() { 'label' => $label, 'recipients' => 'sales@example.com,support@example.com', 'reply' => 'Thank you for your mail', - 'url' => '/user' + 'redirect' => '/user' ); $this->drupalPostForm('admin/structure/contact/manage/feedback', $edit, t('Save')); diff --git a/core/modules/contact/config/install/contact.form.personal.yml b/core/modules/contact/config/install/contact.form.personal.yml index 293610b..a161a3c 100644 --- a/core/modules/contact/config/install/contact.form.personal.yml +++ b/core/modules/contact/config/install/contact.form.personal.yml @@ -7,6 +7,4 @@ recipients: { } reply: '' weight: 0 message: 'Your message has been sent.' -url: - route_name: '' - route_params: { } +redirect: '/' diff --git a/core/modules/contact/config/schema/contact.schema.yml b/core/modules/contact/config/schema/contact.schema.yml index 2ccc203..77cfc18 100644 --- a/core/modules/contact/config/schema/contact.schema.yml +++ b/core/modules/contact/config/schema/contact.schema.yml @@ -25,9 +25,9 @@ contact.form.*: message: type: label label: 'Message' - url: - type: route - label: 'Redirect path' + redirect: + type: path + label: 'Redirect Path' contact.settings: type: config_object diff --git a/core/modules/contact/contact.install b/core/modules/contact/contact.install index 6e3ebd0..c1ecc15 100644 --- a/core/modules/contact/contact.install +++ b/core/modules/contact/contact.install @@ -5,8 +5,6 @@ * Update functions for the contact module. */ -use Drupal\Core\Url; - /** * Add 'message' and 'redirect' field values to 'contact_form' entities. */ @@ -15,6 +13,6 @@ function contact_update_8001() { $entities = \Drupal::entityTypeManager()->getStorage('contact_form')->loadMultiple(); foreach($entities as $contact) { $contact->setMessage('Your message has been sent.'); - $contact->setRedirectUrl(new Url('')); + $contact->setRedirectPath('/'); } } diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php index f5b5e02..86027c3 100644 --- a/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -94,15 +94,11 @@ public function form(array $form, FormStateInterface $form_state) { '#description' => $this->t("Example: 'webmaster@example.com' or 'sales@example.com,support@example.com' . To specify multiple recipients, separate each email address with a comma."), '#required' => TRUE, ); - $path = ''; - if ($url = $contact_form->getRedirectUrl()) { - $path = $url->toString(); - } - $form['url'] = array( + $form['redirect'] = array( '#type' => 'path', '#title' => $this->t('Redirect path'), - '#convert_path' => PathElement::CONVERT_URL, - '#default_value' => $contact_form->isNew() ? '' : $path, + '#convert_path' => PathElement::CONVERT_NONE, + '#default_value' => $contact_form->getRedirectPath(), '#description' => $this->t('The path you would like to redirect to after this form has been submitted. Enter to direct to front page.'), ); $form['reply'] = array( diff --git a/core/modules/contact/src/ContactFormInterface.php b/core/modules/contact/src/ContactFormInterface.php index 78d670d..063553b 100644 --- a/core/modules/contact/src/ContactFormInterface.php +++ b/core/modules/contact/src/ContactFormInterface.php @@ -40,7 +40,15 @@ public function getRecipients(); public function getReply(); /** - * Returns the route for redirect. + * Returns the path for redirect. + * + * @return string + * The redirect path + */ + public function getRedirectPath(); + + /** + * Returns the url for redirect. * * @return \Drupal\core\Url * The redirect URL @@ -86,14 +94,14 @@ public function setRecipients($recipients); public function setReply($reply); /** - * Sets the redirect route. + * Sets the redirect path. * - * @param \Drupal\core\Url $url - * The desired route. + * @param string $redirect + * The desired path. * * @return $this */ - public function setRedirectUrl(Url $url); + public function setRedirectPath($redirect); /** * Sets the weight. diff --git a/core/modules/contact/src/Entity/ContactForm.php b/core/modules/contact/src/Entity/ContactForm.php index 17140d2..4fbc1e3 100644 --- a/core/modules/contact/src/Entity/ContactForm.php +++ b/core/modules/contact/src/Entity/ContactForm.php @@ -46,7 +46,7 @@ * "reply", * "weight", * "message", - * "url", + * "redirect", * } * ) */ @@ -81,11 +81,11 @@ class ContactForm extends ConfigEntityBundleBase implements ContactFormInterface protected $recipients = array(); /** - * The URL to redirect to. + * The path to redirect to. * - * @var \Drupal\core\Url + * @var string */ - protected $url; + protected $redirect; /** * An auto-reply message. @@ -101,17 +101,6 @@ class ContactForm extends ConfigEntityBundleBase implements ContactFormInterface */ protected $weight = 0; - public function __construct(array $values, $entity_type) { - parent::__construct($values, $entity_type); - - if (!empty($values['url']['route_name'])) { - $this->url = new Url($values['url']['route_name']); - if (!empty($values['url']['route_params'])) { - $this->url->setRouteParameters($values['url']['route_params']); - } - } - } - /** * {@inheritdoc} */ @@ -144,8 +133,18 @@ public function getReply() { /** * {@inheritdoc} */ + public function getRedirectPath() { + return $this->redirect; + } + + /** + * {@inheritdoc} + */ public function getRedirectUrl() { - return $this->url; + $this->redirect = $this->redirect ? $this->redirect : '/'; + /** @var \Drupal\Core\Url $url */ + $url = Url::fromUserInput($this->redirect); + return $url; } /** @@ -174,8 +173,8 @@ public function getWeight() { /** * {@inheritdoc} */ - public function setRedirectUrl(Url $url) { - $this->url = $url; + public function setRedirectPath($redirect) { + $this->set('redirect', $redirect); return $this; } @@ -187,23 +186,4 @@ public function setWeight($weight) { return $this; } - /** - * {@inheritdoc} - */ - public function toArray() { - $properties = parent::toArray(); - if ($this->url) { - $properties['url'] = [ - 'route_name' => $this->url->getRouteName(), - 'route_params' => $this->url->getRouteParameters(), - ]; - } - else { - $properties['url'] = [ - 'route_name' => '', - 'route_params' => [], - ]; - } - return $properties; - } } diff --git a/core/modules/contact/src/Tests/ContactSitewideTest.php b/core/modules/contact/src/Tests/ContactSitewideTest.php index dfa1104..3d4008e 100644 --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -152,7 +152,7 @@ function testSiteWideContact() { $this->assertEscaped($recipients[0]); // Test update contact form. - $this->updateContactForm($id, $label = $this->randomMachineName(16), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomMachineName(30), FALSE, 'Your message has been sent.', '/user/' . $admin_user->id()); + $this->updateContactForm($id, $label = $this->randomMachineName(16), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomMachineName(30), FALSE, 'Your message has been sent.', '/user'); $config = $this->config('contact.form.' . $id)->get(); $this->assertEqual($config['label'], $label); $this->assertEqual($config['recipients'], array($recipients[0], $recipients[1])); @@ -305,9 +305,7 @@ function testSiteWideContact() { /** @var \Drupal\contact\ContactFormInterface $form */ $form = ContactForm::load($contact_form); $form->setMessage('Thanks for your submission'); - $form->setRedirectUrl(Url::fromRoute('entity.user.canonical', - ['user' => $admin_user->id(),] - )); + $form->setRedirectPath('/user/' . $admin_user->id()); $form->save(); // Check that the field is displayed. $this->drupalGet('contact/' . $contact_form); @@ -417,17 +415,17 @@ function addContactForm($id, $label, $recipients, $reply, $selected, $message = * @param string $message * The message that will be displayed to a user upon completing the contact * form. - * @param string $url + * @param string $redirect * The path where user will be redirect after this form has been submitted.. */ - function updateContactForm($id, $label, $recipients, $reply, $selected, $message = 'Your message has been sent.', $url = '/') { + function updateContactForm($id, $label, $recipients, $reply, $selected, $message = 'Your message has been sent.', $redirect = '/') { $edit = array(); $edit['label'] = $label; $edit['recipients'] = $recipients; $edit['reply'] = $reply; $edit['selected'] = ($selected ? TRUE : FALSE); $edit['message'] = $message; - $edit['url'] = $url; + $edit['redirect'] = $redirect; $this->drupalPostForm("admin/structure/contact/manage/$id", $edit, t('Save')); } diff --git a/core/modules/contact/tests/modules/contact_test/config/install/contact.form.feedback.yml b/core/modules/contact/tests/modules/contact_test/config/install/contact.form.feedback.yml index 648cf00..6496149 100644 --- a/core/modules/contact/tests/modules/contact_test/config/install/contact.form.feedback.yml +++ b/core/modules/contact/tests/modules/contact_test/config/install/contact.form.feedback.yml @@ -6,6 +6,4 @@ weight: 0 status: true langcode: en message: 'Your message has been sent.' -url: - route_name: '' - route_params: { } +redirect: '/' diff --git a/core/profiles/standard/config/install/contact.form.feedback.yml b/core/profiles/standard/config/install/contact.form.feedback.yml index 6cac5a3..94e2a9a 100644 --- a/core/profiles/standard/config/install/contact.form.feedback.yml +++ b/core/profiles/standard/config/install/contact.form.feedback.yml @@ -8,6 +8,4 @@ recipients: reply: '' weight: 0 message: 'Your message has been sent.' -url: - route_name: '' - route_params: { } +redirect: '/'