Created
October 23, 2014 01:13
-
-
Save larowlan/21de9632745fbe3128d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php | |
index 098ba2f..0442bf6 100644 | |
--- a/core/modules/contact/src/ContactFormEditForm.php | |
+++ b/core/modules/contact/src/ContactFormEditForm.php | |
@@ -68,10 +68,10 @@ public function form(array $form, FormStateInterface $form_state) { | |
if ($url = $contact_form->getRedirectUrl()) { | |
$path = $url->toString(); | |
} | |
- $form['route'] = array( | |
+ $form['url'] = array( | |
'#type' => 'path', | |
'#title' => $this->t('Redirect path'), | |
- '#convert_path' => PathElement::CONVERT_ROUTE, | |
+ '#convert_path' => PathElement::CONVERT_URL, | |
'#default_value' => $contact_form->isNew() ? '<front>' : $path, | |
'#description' => $this->t('The path you would like to redirect to after this form has been submitted. Enter <front> to direct to front | |
); | |
diff --git a/core/modules/contact/src/ContactFormInterface.php b/core/modules/contact/src/ContactFormInterface.php | |
index c3a190e..ca8baab 100644 | |
--- a/core/modules/contact/src/ContactFormInterface.php | |
+++ b/core/modules/contact/src/ContactFormInterface.php | |
@@ -43,8 +43,8 @@ public function getReply(); | |
/** | |
* Returns the route for redirect. | |
* | |
- * @return array | |
- * Route parameters. | |
+ * @return \Drupal\Core\Url | |
+ * The redirect URL | |
*/ | |
public function getRedirectUrl(); | |
@@ -89,7 +89,7 @@ public function setReply($reply); | |
/** | |
* Sets the redirect route. | |
* | |
- * @param array $route | |
+ * @param \Drupal\Core\Url $url | |
* The desired route. | |
* | |
* @return $this | |
diff --git a/core/modules/contact/src/Entity/ContactForm.php b/core/modules/contact/src/Entity/ContactForm.php | |
index 1a1ac07..f80b6e9 100644 | |
--- a/core/modules/contact/src/Entity/ContactForm.php | |
+++ b/core/modules/contact/src/Entity/ContactForm.php | |
@@ -75,11 +75,11 @@ class ContactForm extends ConfigEntityBundleBase implements ContactFormInterface | |
protected $recipients = array(); | |
/** | |
- * The route to redirect to. | |
+ * The URL to redirect to. | |
* | |
- * @var array | |
+ * @var \Drupal\Core\Url | |
*/ | |
- protected $route = array(); | |
+ protected $url; | |
/** | |
* An auto-reply message. | |
@@ -98,6 +98,19 @@ class ContactForm extends ConfigEntityBundleBase implements ContactFormInterface | |
/** | |
* {@inheritdoc} | |
*/ | |
+ public function __construct(array $values, $entity_type) { | |
+ parent::__construct($values, $entity_type); | |
+ if (!empty($values['route']['route_name'])) { | |
+ $this->url = new Url($values['route']['route_name']); | |
+ if (!empty($values['route']['route_parameters'])) { | |
+ $this->url->setRouteParameters($values['route']['route_parameters']); | |
+ } | |
+ } | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
public function getMessage() { | |
return $this->get('message'); | |
} | |
@@ -128,10 +141,7 @@ public function getReply() { | |
* {@inheritdoc} | |
*/ | |
public function getRedirectUrl() { | |
- $url = Url::fromRoute($this->route['route_name'], $this->route['route_parameters']); | |
- if ($url->getRouteName()) { | |
- return $url; | |
- } | |
+ return $this->url; | |
} | |
/** | |
@@ -154,10 +164,7 @@ public function setReply($reply) { | |
* {@inheritdoc} | |
*/ | |
public function setRedirectUrl(Url $url) { | |
- $this->route = array( | |
- 'route_name' => $url->getRouteName(), | |
- 'route_parameters' => $url->getRouteParameters(), | |
- ); | |
+ $this->url = $url; | |
return $this; | |
} | |
@@ -176,4 +183,16 @@ public function setWeight($weight) { | |
return $this; | |
} | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function toArray() { | |
+ $properties = parent::toArray(); | |
+ $properties['route'] = [ | |
+ 'route_name' => $this->url->getRouteName(), | |
+ 'route_parameters' => $this->url->getRouteParameters(), | |
+ ]; | |
+ return $properties; | |
+ } | |
+ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please confirm