summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2014-08-25 23:38:25 -0700
committerwebchick2014-08-25 23:38:25 -0700
commitda94c06e29397322bf0029c3e13bfd8ba49f508c (patch)
tree0f725c20f6f848eed9ed129739564d887ca4586a
parent2d3c7f1642b58dc30530503ece0c957ee20af366 (diff)
Issue #2030591 by jibran, Temoor, andypost, lokeoke, er.pushpinderrana, martin107, pcambra, piyuesh23, Sharique, kgoel | plopesc: Expand ContactForm with methods.
-rw-r--r--core/modules/contact/contact.module2
-rw-r--r--core/modules/contact/src/ContactFormEditForm.php6
-rw-r--r--core/modules/contact/src/ContactFormInterface.php54
-rw-r--r--core/modules/contact/src/ContactFormListBuilder.php2
-rw-r--r--core/modules/contact/src/Entity/ContactForm.php63
-rw-r--r--core/modules/contact/src/MessageForm.php5
-rw-r--r--core/modules/migrate_drupal/src/Tests/d6/MigrateContactCategoryTest.php24
7 files changed, 128 insertions, 28 deletions
diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module
index 368ad0f..afbbc8d 100644
--- a/core/modules/contact/contact.module
+++ b/core/modules/contact/contact.module
@@ -137,7 +137,7 @@ function contact_mail($key, &$message, $params) {
case 'page_autoreply':
$message['subject'] .= t('[!form] !subject', $variables, $options);
- $message['body'][] = $params['contact_form']->reply;
+ $message['body'][] = $params['contact_form']->getReply();
break;
case 'user_mail':
diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php
index a706671..7a11eea 100644
--- a/core/modules/contact/src/ContactFormEditForm.php
+++ b/core/modules/contact/src/ContactFormEditForm.php
@@ -45,20 +45,20 @@ class ContactFormEditForm extends EntityForm {
$form['recipients'] = array(
'#type' => 'textarea',
'#title' => $this->t('Recipients'),
- '#default_value' => implode(', ', $contact_form->recipients),
+ '#default_value' => implode(', ', $contact_form->getRecipients()),
'#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,
);
$form['reply'] = array(
'#type' => 'textarea',
'#title' => $this->t('Auto-reply'),
- '#default_value' => $contact_form->reply,
+ '#default_value' => $contact_form->getReply(),
'#description' => $this->t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
);
$form['weight'] = array(
'#type' => 'weight',
'#title' => $this->t('Weight'),
- '#default_value' => $contact_form->weight,
+ '#default_value' => $contact_form->getWeight(),
'#description' => $this->t('When listing forms, those with lighter (smaller) weights get listed before forms with heavier (larger) weights. Forms with equal weights are sorted alphabetically.'),
);
$form['selected'] = array(
diff --git a/core/modules/contact/src/ContactFormInterface.php b/core/modules/contact/src/ContactFormInterface.php
index cda8e27..abaea87 100644
--- a/core/modules/contact/src/ContactFormInterface.php
+++ b/core/modules/contact/src/ContactFormInterface.php
@@ -14,4 +14,58 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface;
*/
interface ContactFormInterface extends ConfigEntityInterface {
+ /**
+ * Returns list of recipient e-mail addresses.
+ *
+ * @return array
+ * List of recipient e-mail addresses.
+ */
+ public function getRecipients();
+
+ /**
+ * Returns an auto-reply message to send to the message author.
+ *
+ * @return string
+ * An auto-reply message
+ */
+ public function getReply();
+
+ /**
+ * Returns the weight of this category (used for sorting).
+ *
+ * @return int
+ * The weight of this category.
+ */
+ public function getWeight();
+
+ /**
+ * Sets list of recipient e-mail addresses.
+ *
+ * @param array $recipients
+ * The desired list of e-mail addresses of this category.
+ *
+ * @return $this
+ */
+ public function setRecipients($recipients);
+
+ /**
+ * Sets an auto-reply message to send to the message author.
+ *
+ * @param string $reply
+ * The desired reply.
+ *
+ * @return $this
+ */
+ public function setReply($reply);
+
+ /**
+ * Sets the weight.
+ *
+ * @param int $weight
+ * The desired weight.
+ *
+ * @return $this
+ */
+ public function setWeight($weight);
+
}
diff --git a/core/modules/contact/src/ContactFormListBuilder.php b/core/modules/contact/src/ContactFormListBuilder.php
index 0aeb10e..883ad9a 100644
--- a/core/modules/contact/src/ContactFormListBuilder.php
+++ b/core/modules/contact/src/ContactFormListBuilder.php
@@ -39,7 +39,7 @@ class ContactFormListBuilder extends ConfigEntityListBuilder {
$row['selected'] = t('No');
}
else {
- $row['recipients'] = String::checkPlain(implode(', ', $entity->recipients));
+ $row['recipients'] = String::checkPlain(implode(', ', $entity->getRecipients()));
$default_form = \Drupal::config('contact.settings')->get('default_form');
$row['selected'] = ($default_form == $entity->id() ? t('Yes') : t('No'));
}
diff --git a/core/modules/contact/src/Entity/ContactForm.php b/core/modules/contact/src/Entity/ContactForm.php
index 08075a1..53476f7 100644
--- a/core/modules/contact/src/Entity/ContactForm.php
+++ b/core/modules/contact/src/Entity/ContactForm.php
@@ -9,6 +9,8 @@ namespace Drupal\contact\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\contact\ContactFormInterface;
+use Drupal\Core\Entity\EntityStorageControllerInterface;
+use Drupal\contact\CategoryInterface;
/**
* Defines the contact form entity.
@@ -45,34 +47,79 @@ class ContactForm extends ConfigEntityBundleBase implements ContactFormInterface
*
* @var string
*/
- public $id;
+ protected $id;
/**
- * The form label.
+ * The human-readable label of the category.
*
* @var string
*/
- public $label;
+ protected $label;
/**
* List of recipient email addresses.
*
* @var array
*/
- public $recipients = array();
+ protected $recipients = array();
/**
- * An auto-reply message to send to the message author.
+ * An auto-reply message.
*
* @var string
*/
- public $reply = '';
+ protected $reply = '';
/**
- * Weight of this form (used for sorting).
+ * The weight of the category.
*
* @var int
*/
- public $weight = 0;
+ protected $weight = 0;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRecipients() {
+ return $this->get('recipients');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setRecipients($recipients) {
+ $this->set('recipients', $recipients);
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getReply() {
+ return $this->get('reply');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setReply($reply) {
+ $this->set('reply', $reply);
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getWeight() {
+ return $this->get('weight');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setWeight($weight) {
+ $this->set('weight', $weight);
+ return $this;
+ }
}
diff --git a/core/modules/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php
index ca7be75..ddadc15 100644
--- a/core/modules/contact/src/MessageForm.php
+++ b/core/modules/contact/src/MessageForm.php
@@ -200,8 +200,7 @@ class MessageForm extends ContentEntityForm {
// Send to the form recipient(s), using the site's default language.
$contact_form = $message->getContactForm();
$params['contact_form'] = $contact_form;
-
- $to = implode(', ', $contact_form->recipients);
+ $to = implode(', ', $contact_form->getRecipients());
$recipient_langcode = $this->languageManager->getDefaultLanguage()->getId();
}
elseif ($recipient = $message->getPersonalRecipient()) {
@@ -224,7 +223,7 @@ class MessageForm extends ContentEntityForm {
}
// If configured, send an auto-reply, using the current language.
- if (!$message->isPersonal() && $contact_form->reply) {
+ if (!$message->isPersonal() && $contact_form->getReply()) {
// User contact forms do not support an auto-reply message, so this
// message always originates from the site.
drupal_mail('contact', 'page_autoreply', $sender->getEmail(), $language_interface->id, $params);
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateContactCategoryTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateContactCategoryTest.php
index 98cc703..5cde764 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateContactCategoryTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateContactCategoryTest.php
@@ -45,22 +45,22 @@ class MigrateContactCategoryTest extends MigrateDrupalTestBase {
public function testContactCategory() {
/** @var \Drupal\contact\Entity\ContactForm $contact_form */
$contact_form = entity_load('contact_form', 'website_feedback');
- $this->assertEqual($contact_form->label, 'Website feedback');
- $this->assertEqual($contact_form->recipients, array('admin@example.com'));
- $this->assertEqual($contact_form->reply, '');
- $this->assertEqual($contact_form->weight, 0);
+ $this->assertEqual($contact_form->label(), 'Website feedback');
+ $this->assertEqual($contact_form->getRecipients(), array('admin@example.com'));
+ $this->assertEqual($contact_form->getReply(), '');
+ $this->assertEqual($contact_form->getWeight(), 0);
$contact_form = entity_load('contact_form', 'some_other_category');
- $this->assertEqual($contact_form->label, 'Some other category');
- $this->assertEqual($contact_form->recipients, array('test@example.com'));
- $this->assertEqual($contact_form->reply, 'Thanks for contacting us, we will reply ASAP!');
- $this->assertEqual($contact_form->weight, 1);
+ $this->assertEqual($contact_form->label(), 'Some other category');
+ $this->assertEqual($contact_form->getRecipients(), array('test@example.com'));
+ $this->assertEqual($contact_form->getReply(), 'Thanks for contacting us, we will reply ASAP!');
+ $this->assertEqual($contact_form->getWeight(), 1);
$contact_form = entity_load('contact_form', 'a_category_much_longer_than_thir');
- $this->assertEqual($contact_form->label, 'A category much longer than thirty two characters');
- $this->assertEqual($contact_form->recipients, array('fortyninechars@example.com'));
- $this->assertEqual($contact_form->reply, '');
- $this->assertEqual($contact_form->weight, 2);
+ $this->assertEqual($contact_form->label(), 'A category much longer than thirty two characters');
+ $this->assertEqual($contact_form->getRecipients(), array('fortyninechars@example.com'));
+ $this->assertEqual($contact_form->getReply(), '');
+ $this->assertEqual($contact_form->getWeight(), 2);
}
}