diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 368ad0f9f0e3d525bfd4812027d2704da1edd9e1..afbbc8d62eae3e548e13edfbce216f70efe723e8 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 a706671497bd9f3c41578a78e3064a173a68748e..7a11eeaddb7fea1ab0645655efee8e5d2684fec2 100644 --- a/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -45,20 +45,20 @@ public function form(array $form, FormStateInterface $form_state) { $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 cda8e27efd0280b50c8789660be4b47ab58a73ee..abaea8780e80eb86eb0a44cbc3e1a348d242bfdb 100644 --- a/core/modules/contact/src/ContactFormInterface.php +++ b/core/modules/contact/src/ContactFormInterface.php @@ -14,4 +14,58 @@ */ 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 0aeb10e39433f3c04a21c1354d5a7fb43280ad59..883ad9a2de76c3febe72fe07744f999e290bfc04 100644 --- a/core/modules/contact/src/ContactFormListBuilder.php +++ b/core/modules/contact/src/ContactFormListBuilder.php @@ -39,7 +39,7 @@ public function buildRow(EntityInterface $entity) { $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 08075a1284751bd28fd5eed8b374912c6750c408..53476f720a8e346aea6cb935a8a3ab97332d0c18 100644 --- a/core/modules/contact/src/Entity/ContactForm.php +++ b/core/modules/contact/src/Entity/ContactForm.php @@ -9,6 +9,8 @@ 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 ca7be751bb274277c84a67a8820e8afaf9f97d8a..ddadc15faec832897e3bfb3117150eb1ee96df13 100644 --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -200,8 +200,7 @@ public function save(array $form, FormStateInterface $form_state) { // 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 @@ public function save(array $form, FormStateInterface $form_state) { } // 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 98cc703a0bc8be479e85dea83c440567490ff2c3..5cde7642fb1086713a92513972203f69bcd0cb55 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 @@ protected function setUp() { 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); } }