Issue #2030591 by jibran, Temoor, andypost, lokeoke, er.pushpinderrana, martin107, pcambra, piyuesh23, Sharique, kgoel | plopesc: Expand ContactForm with methods.
parent
2d3c7f1642
commit
da94c06e29
|
@ -137,7 +137,7 @@ function contact_mail($key, &$message, $params) {
|
||||||
|
|
||||||
case 'page_autoreply':
|
case 'page_autoreply':
|
||||||
$message['subject'] .= t('[!form] !subject', $variables, $options);
|
$message['subject'] .= t('[!form] !subject', $variables, $options);
|
||||||
$message['body'][] = $params['contact_form']->reply;
|
$message['body'][] = $params['contact_form']->getReply();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'user_mail':
|
case 'user_mail':
|
||||||
|
|
|
@ -45,20 +45,20 @@ class ContactFormEditForm extends EntityForm {
|
||||||
$form['recipients'] = array(
|
$form['recipients'] = array(
|
||||||
'#type' => 'textarea',
|
'#type' => 'textarea',
|
||||||
'#title' => $this->t('Recipients'),
|
'#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."),
|
'#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,
|
'#required' => TRUE,
|
||||||
);
|
);
|
||||||
$form['reply'] = array(
|
$form['reply'] = array(
|
||||||
'#type' => 'textarea',
|
'#type' => 'textarea',
|
||||||
'#title' => $this->t('Auto-reply'),
|
'#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.'),
|
'#description' => $this->t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
|
||||||
);
|
);
|
||||||
$form['weight'] = array(
|
$form['weight'] = array(
|
||||||
'#type' => 'weight',
|
'#type' => 'weight',
|
||||||
'#title' => $this->t('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.'),
|
'#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(
|
$form['selected'] = array(
|
||||||
|
|
|
@ -14,4 +14,58 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||||
*/
|
*/
|
||||||
interface ContactFormInterface extends 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class ContactFormListBuilder extends ConfigEntityListBuilder {
|
||||||
$row['selected'] = t('No');
|
$row['selected'] = t('No');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$row['recipients'] = String::checkPlain(implode(', ', $entity->recipients));
|
$row['recipients'] = String::checkPlain(implode(', ', $entity->getRecipients()));
|
||||||
$default_form = \Drupal::config('contact.settings')->get('default_form');
|
$default_form = \Drupal::config('contact.settings')->get('default_form');
|
||||||
$row['selected'] = ($default_form == $entity->id() ? t('Yes') : t('No'));
|
$row['selected'] = ($default_form == $entity->id() ? t('Yes') : t('No'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ namespace Drupal\contact\Entity;
|
||||||
|
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||||
use Drupal\contact\ContactFormInterface;
|
use Drupal\contact\ContactFormInterface;
|
||||||
|
use Drupal\Core\Entity\EntityStorageControllerInterface;
|
||||||
|
use Drupal\contact\CategoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the contact form entity.
|
* Defines the contact form entity.
|
||||||
|
@ -45,34 +47,79 @@ class ContactForm extends ConfigEntityBundleBase implements ContactFormInterface
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $id;
|
protected $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The form label.
|
* The human-readable label of the category.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $label;
|
protected $label;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of recipient email addresses.
|
* List of recipient email addresses.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $recipients = array();
|
protected $recipients = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An auto-reply message to send to the message author.
|
* An auto-reply message.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $reply = '';
|
protected $reply = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Weight of this form (used for sorting).
|
* The weight of the category.
|
||||||
*
|
*
|
||||||
* @var int
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,8 +200,7 @@ class MessageForm extends ContentEntityForm {
|
||||||
// Send to the form recipient(s), using the site's default language.
|
// Send to the form recipient(s), using the site's default language.
|
||||||
$contact_form = $message->getContactForm();
|
$contact_form = $message->getContactForm();
|
||||||
$params['contact_form'] = $contact_form;
|
$params['contact_form'] = $contact_form;
|
||||||
|
$to = implode(', ', $contact_form->getRecipients());
|
||||||
$to = implode(', ', $contact_form->recipients);
|
|
||||||
$recipient_langcode = $this->languageManager->getDefaultLanguage()->getId();
|
$recipient_langcode = $this->languageManager->getDefaultLanguage()->getId();
|
||||||
}
|
}
|
||||||
elseif ($recipient = $message->getPersonalRecipient()) {
|
elseif ($recipient = $message->getPersonalRecipient()) {
|
||||||
|
@ -224,7 +223,7 @@ class MessageForm extends ContentEntityForm {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If configured, send an auto-reply, using the current language.
|
// 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
|
// User contact forms do not support an auto-reply message, so this
|
||||||
// message always originates from the site.
|
// message always originates from the site.
|
||||||
drupal_mail('contact', 'page_autoreply', $sender->getEmail(), $language_interface->id, $params);
|
drupal_mail('contact', 'page_autoreply', $sender->getEmail(), $language_interface->id, $params);
|
||||||
|
|
|
@ -45,22 +45,22 @@ class MigrateContactCategoryTest extends MigrateDrupalTestBase {
|
||||||
public function testContactCategory() {
|
public function testContactCategory() {
|
||||||
/** @var \Drupal\contact\Entity\ContactForm $contact_form */
|
/** @var \Drupal\contact\Entity\ContactForm $contact_form */
|
||||||
$contact_form = entity_load('contact_form', 'website_feedback');
|
$contact_form = entity_load('contact_form', 'website_feedback');
|
||||||
$this->assertEqual($contact_form->label, 'Website feedback');
|
$this->assertEqual($contact_form->label(), 'Website feedback');
|
||||||
$this->assertEqual($contact_form->recipients, array('admin@example.com'));
|
$this->assertEqual($contact_form->getRecipients(), array('admin@example.com'));
|
||||||
$this->assertEqual($contact_form->reply, '');
|
$this->assertEqual($contact_form->getReply(), '');
|
||||||
$this->assertEqual($contact_form->weight, 0);
|
$this->assertEqual($contact_form->getWeight(), 0);
|
||||||
|
|
||||||
$contact_form = entity_load('contact_form', 'some_other_category');
|
$contact_form = entity_load('contact_form', 'some_other_category');
|
||||||
$this->assertEqual($contact_form->label, 'Some other category');
|
$this->assertEqual($contact_form->label(), 'Some other category');
|
||||||
$this->assertEqual($contact_form->recipients, array('test@example.com'));
|
$this->assertEqual($contact_form->getRecipients(), array('test@example.com'));
|
||||||
$this->assertEqual($contact_form->reply, 'Thanks for contacting us, we will reply ASAP!');
|
$this->assertEqual($contact_form->getReply(), 'Thanks for contacting us, we will reply ASAP!');
|
||||||
$this->assertEqual($contact_form->weight, 1);
|
$this->assertEqual($contact_form->getWeight(), 1);
|
||||||
|
|
||||||
$contact_form = entity_load('contact_form', 'a_category_much_longer_than_thir');
|
$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->label(), 'A category much longer than thirty two characters');
|
||||||
$this->assertEqual($contact_form->recipients, array('fortyninechars@example.com'));
|
$this->assertEqual($contact_form->getRecipients(), array('fortyninechars@example.com'));
|
||||||
$this->assertEqual($contact_form->reply, '');
|
$this->assertEqual($contact_form->getReply(), '');
|
||||||
$this->assertEqual($contact_form->weight, 2);
|
$this->assertEqual($contact_form->getWeight(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue