Commit 40fbf6b4 authored by alexpott's avatar alexpott

Issue #2072897 by jayeshanandani, marcingy, herom, er.pushpinderrana, inket:...

Issue #2072897 by jayeshanandani, marcingy, herom, er.pushpinderrana, inket: Modernize contact.module forms.
parent fc939d4e
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\contact\CategoryForm.
* Contains \Drupal\contact\CategoryForm.
*/
namespace Drupal\contact;
......@@ -16,20 +16,20 @@
class CategoryForm extends EntityForm {
/**
* Overrides Drupal\Core\Entity\EntityForm::form().
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
$form = parent::form($form, $form_state);
$category = $this->entity;
$default_category = \Drupal::config('contact.settings')->get('default_category');
$default_category = $this->config('contact.settings')->get('default_category');
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $category->label(),
'#description' => t("Example: 'website feedback' or 'product information'."),
'#description' => $this->t("Example: 'website feedback' or 'product information'."),
'#required' => TRUE,
);
$form['id'] = array(
......@@ -43,26 +43,26 @@ public function form(array $form, array &$form_state) {
);
$form['recipients'] = array(
'#type' => 'textarea',
'#title' => t('Recipients'),
'#title' => $this->t('Recipients'),
'#default_value' => implode(', ', $category->recipients),
'#description' => 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,
);
$form['reply'] = array(
'#type' => 'textarea',
'#title' => t('Auto-reply'),
'#title' => $this->t('Auto-reply'),
'#default_value' => $category->reply,
'#description' => 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(
'#type' => 'weight',
'#title' => t('Weight'),
'#title' => $this->t('Weight'),
'#default_value' => $category->weight,
'#description' => t('When listing categories, those with lighter (smaller) weights get listed before categories with heavier (larger) weights. Categories with equal weights are sorted alphabetically.'),
'#description' => $this->t('When listing categories, those with lighter (smaller) weights get listed before categories with heavier (larger) weights. Categories with equal weights are sorted alphabetically.'),
);
$form['selected'] = array(
'#type' => 'checkbox',
'#title' => t('Make this the default category.'),
'#title' => $this->t('Make this the default category.'),
'#default_value' => $default_category === $category->id(),
);
......@@ -70,7 +70,7 @@ public function form(array $form, array &$form_state) {
}
/**
* Overrides Drupal\Core\Entity\EntityForm::validate().
* {@inheritdoc}
*/
public function validate(array $form, array &$form_state) {
parent::validate($form, $form_state);
......@@ -88,33 +88,33 @@ public function validate(array $form, array &$form_state) {
}
/**
* Overrides Drupal\Core\Entity\EntityForm::save().
* {@inheritdoc}
*/
public function save(array $form, array &$form_state) {
$category = $this->entity;
$status = $category->save();
$contact_settings = $this->config('contact.settings');
$edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo());
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Category %label has been updated.', array('%label' => $category->label())));
drupal_set_message($this->t('Category %label has been updated.', array('%label' => $category->label())));
watchdog('contact', 'Category %label has been updated.', array('%label' => $category->label()), WATCHDOG_NOTICE, $edit_link);
}
else {
drupal_set_message(t('Category %label has been added.', array('%label' => $category->label())));
drupal_set_message($this->t('Category %label has been added.', array('%label' => $category->label())));
watchdog('contact', 'Category %label has been added.', array('%label' => $category->label()), WATCHDOG_NOTICE, $edit_link);
}
// Update the default category.
$contact_config = \Drupal::config('contact.settings');
if ($form_state['values']['selected']) {
$contact_config
$contact_settings
->set('default_category', $category->id())
->save();
}
// If it was the default category, empty out the setting.
elseif ($contact_config->get('default_category') == $category->id()) {
$contact_config
elseif ($contact_settings->get('default_category') == $category->id()) {
$contact_settings
->set('default_category', NULL)
->save();
}
......
......@@ -19,7 +19,7 @@ class CategoryDeleteForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete %name?', array('%name' => $this->entity->label()));
return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->label()));
}
/**
......@@ -33,7 +33,7 @@ public function getCancelRoute() {
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
return $this->t('Delete');
}
/**
......@@ -41,7 +41,7 @@ public function getConfirmText() {
*/
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(t('Category %label has been deleted.', array('%label' => $this->entity->label())));
drupal_set_message($this->t('Category %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('contact', 'Category %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect_route'] = $this->getCancelRoute();
}
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\contact\MessageForm.
* Contains \Drupal\contact\MessageForm.
*/
namespace Drupal\contact;
......@@ -70,7 +70,7 @@ public static function create(ContainerInterface $container) {
}
/**
* Overrides Drupal\Core\Entity\EntityForm::form().
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
$user = $this->currentUser();
......@@ -88,7 +88,7 @@ public function form(array $form, array &$form_state) {
$language_configuration = $this->moduleHandler->invoke('language', 'get_default_configuration', array('contact_message', $message->getCategory()->id()));
$form['langcode'] = array(
'#title' => t('Language'),
'#title' => $this->t('Language'),
'#type' => 'language_select',
'#default_value' => $message->getUntranslated()->language()->id,
'#languages' => Language::STATE_ALL,
......@@ -97,13 +97,13 @@ public function form(array $form, array &$form_state) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Your name'),
'#title' => $this->t('Your name'),
'#maxlength' => 255,
'#required' => TRUE,
);
$form['mail'] = array(
'#type' => 'email',
'#title' => t('Your email address'),
'#title' => $this->t('Your email address'),
'#required' => TRUE,
);
if ($user->isAnonymous()) {
......@@ -128,7 +128,7 @@ public function form(array $form, array &$form_state) {
if ($message->isPersonal()) {
$form['recipient'] = array(
'#type' => 'item',
'#title' => t('To'),
'#title' => $this->t('To'),
'#value' => $message->getPersonalRecipient()->id(),
'name' => array(
'#theme' => 'username',
......@@ -139,7 +139,7 @@ public function form(array $form, array &$form_state) {
$form['copy'] = array(
'#type' => 'checkbox',
'#title' => t('Send yourself a copy.'),
'#title' => $this->t('Send yourself a copy.'),
// Do not allow anonymous users to send themselves a copy, because it can
// be abused to spam people.
'#access' => $user->isAuthenticated(),
......@@ -148,13 +148,13 @@ public function form(array $form, array &$form_state) {
}
/**
* Overrides Drupal\Core\Entity\EntityForm::actions().
* {@inheritdoc}
*/
public function actions(array $form, array &$form_state) {
$elements = parent::actions($form, $form_state);
$elements['submit']['#value'] = t('Send message');
$elements['submit']['#value'] = $this->t('Send message');
$elements['preview'] = array(
'#value' => t('Preview'),
'#value' => $this->t('Preview'),
'#validate' => array(
array($this, 'validate'),
),
......@@ -176,7 +176,7 @@ public function preview(array $form, array &$form_state) {
}
/**
* Overrides Drupal\Core\Entity\EntityForm::save().
* {@inheritdoc}
*/
public function save(array $form, array &$form_state) {
$user = $this->currentUser();
......@@ -195,7 +195,7 @@ public function save(array $form, array &$form_state) {
user_cookie_save(array('name' => $message->getSenderName(), 'mail' => $message->getSenderMail()));
// For the email message, clarify that the sender name is not verified; it
// could potentially clash with a username on this site.
$sender->name = t('!name (not verified)', array('!name' => $message->getSenderName()));
$sender->name = $this->t('!name (not verified)', array('!name' => $message->getSenderName()));
}
// Build email parameters.
......@@ -217,7 +217,7 @@ public function save(array $form, array &$form_state) {
$params['recipient'] = $recipient;
}
else {
throw new \RuntimeException(t('Unable to determine message recipient.'));
throw new \RuntimeException($this->t('Unable to determine message recipient.'));
}
// Send email to the recipient(s).
......@@ -236,8 +236,7 @@ public function save(array $form, array &$form_state) {
drupal_mail('contact', 'page_autoreply', $sender->getEmail(), $language_interface->id, $params);
}
$config = $this->config('contact.settings');
$this->flood->register('contact', $config->get('flood.interval'));
$this->flood->register('contact', $this->config('contact.settings')->get('flood.interval'));
if (!$message->isPersonal()) {
watchdog('contact', '%sender-name (@sender-from) sent an email regarding %category.', array(
'%sender-name' => $sender->getUsername(),
......@@ -253,7 +252,7 @@ public function save(array $form, array &$form_state) {
));
}
drupal_set_message(t('Your message has been sent.'));
drupal_set_message($this->t('Your message has been sent.'));
// To avoid false error messages caused by flood control, redirect away from
// the contact form; either to the contacted user account or the front page.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment