diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/lib/Drupal/config_translation/Tests/ConfigTranslationUiTest.php index ed4b1e2..61b7099 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Tests/ConfigTranslationUiTest.php @@ -304,8 +304,8 @@ public function testContactConfigEntityTranslation() { // Submit feedback. $edit = array( - 'subject' => 'Test subject', - 'message' => 'Test message', + 'subject[0][value]' => 'Test subject', + 'message[0][value]' => 'Test message', ); $this->drupalPostForm(NULL, $edit, t('Send message')); } diff --git a/core/modules/contact/contact.info.yml b/core/modules/contact/contact.info.yml index 647bc15..65c7151 100644 --- a/core/modules/contact/contact.info.yml +++ b/core/modules/contact/contact.info.yml @@ -4,4 +4,6 @@ description: 'Enables the use of both personal and site-wide contact forms.' package: Core version: VERSION core: 8.x +dependencies: + - text configure: contact.category_list diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index dc622ff..40af331 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -114,27 +114,11 @@ function contact_field_extra_fields() { 'weight' => -30, ); } - $fields['contact_message'][$bundle]['form']['subject'] = array( - 'label' => t('Subject'), - 'description' => t('Text'), - 'weight' => -10, - ); - $fields['contact_message'][$bundle]['form']['message'] = array( - 'label' => t('Message'), - 'description' => t('Long text'), - 'weight' => 0, - ); $fields['contact_message'][$bundle]['form']['copy'] = array( 'label' => t('Send copy to sender'), 'description' => t('Option'), 'weight' => 50, ); - - $fields['contact_message'][$bundle]['display']['message'] = array( - 'label' => t('Message'), - 'description' => t('The main contact message'), - 'weight' => 0, - ); } $fields['user']['user']['form']['contact'] = array( @@ -189,7 +173,7 @@ function contact_mail($key, &$message, $params) { $message['subject'] .= t('[!category] !subject', $variables, $options); $message['body'][] = t("!sender-name (!sender-url) sent a message using the contact form at !form-url.", $variables, $options); $build = entity_view($contact_message, 'mail', $language->id); - $message['body'][] = drupal_render($build); + $message['body'][] = drupal_html_to_text(drupal_render($build)); break; case 'page_autoreply': @@ -208,7 +192,7 @@ function contact_mail($key, &$message, $params) { $message['body'][] = t("!sender-name (!sender-url) has sent you a message via your contact form at !site-name.", $variables, $options); $message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !recipient-edit-url.", $variables, $options); $build = entity_view($contact_message, 'mail', $language->id); - $message['body'][] = drupal_render($build); + $message['body'][] = drupal_html_to_text(drupal_render($build)); break; } } diff --git a/core/modules/contact/lib/Drupal/contact/Entity/Message.php b/core/modules/contact/lib/Drupal/contact/Entity/Message.php index a3a62cb..0439ed5 100644 --- a/core/modules/contact/lib/Drupal/contact/Entity/Message.php +++ b/core/modules/contact/lib/Drupal/contact/Entity/Message.php @@ -20,7 +20,7 @@ * label = @Translation("Contact message"), * controllers = { * "storage" = "Drupal\Core\Entity\FieldableNullStorageController", - * "view_builder" = "Drupal\contact\MessageViewBuilder", + * "view_builder" = "Drupal\Core\Entity\EntityViewBuilder", * "form" = { * "default" = "Drupal\contact\MessageFormController" * } @@ -155,13 +155,40 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t("The sender's email")) ->setDescription(t('The email of the person that is sending the contact message.')); + // The subject of the contact message. $fields['subject'] = FieldDefinition::create('string') - ->setLabel(t('The message subject')) - ->setDescription(t('The subject of the contact message.')); - - $fields['message'] = FieldDefinition::create('string') - ->setLabel(t('The message text')) - ->setDescription(t('The text of the contact message.')); + ->setLabel(t('Subject')) + ->setRequired(TRUE) + ->setSettings(array( + 'max_length' => 100, + )) + ->setDisplayOptions('form', array( + 'type' => 'string', + 'weight' => -10, + )) + ->setDisplayConfigurable('form', TRUE); + + // The text of the contact message. + $fields['message'] = FieldDefinition::create('text_long') + ->setLabel(t('Message')) + ->setRequired(TRUE) + ->setSettings(array( + 'text_processing' => 0, + )) + ->setDisplayOptions('form', array( + 'type' => 'text_textarea', + 'weight' => 0, + 'settings' => array( + 'rows' => 12, + ), + )) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayOptions('view', array( + 'type' => 'string', + 'weight' => 0, + 'label' => 'hidden', + )) + ->setDisplayConfigurable('view', TRUE); $fields['copy'] = FieldDefinition::create('boolean') ->setLabel(t('Copy')) diff --git a/core/modules/contact/lib/Drupal/contact/MessageFormController.php b/core/modules/contact/lib/Drupal/contact/MessageFormController.php index 0678654..81c39b2 100644 --- a/core/modules/contact/lib/Drupal/contact/MessageFormController.php +++ b/core/modules/contact/lib/Drupal/contact/MessageFormController.php @@ -83,19 +83,6 @@ public function form(array $form, array &$form_state) { ); } - $form['subject'] = array( - '#type' => 'textfield', - '#title' => t('Subject'), - '#maxlength' => 100, - '#required' => TRUE, - ); - $form['message'] = array( - '#type' => 'textarea', - '#title' => t('Message'), - '#required' => TRUE, - '#rows' => 12, - ); - $form['copy'] = array( '#type' => 'checkbox', '#title' => t('Send yourself a copy.'), diff --git a/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php b/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php deleted file mode 100644 index 5e5b6dd..0000000 --- a/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php +++ /dev/null @@ -1,61 +0,0 @@ -bundle()]; - if ($entity->getMessage() && $display->getComponent('message')) { - $entity->content['message'] = array( - '#type' => 'item', - '#title' => t('Message'), - '#markup' => String::checkPlain($entity->getMessage()), - ); - } - } - } - - /** - * {@inheritdoc} - */ - public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) { - $build = parent::view($entity, $view_mode, $langcode); - - if ($view_mode == 'mail') { - // Convert field labels into headings. - // @todo Improve drupal_html_to_text() to convert DIVs correctly. - foreach (element_children($build) as $key) { - if (isset($build[$key]['#label_display']) && $build[$key]['#label_display'] == 'above') { - $build[$key] += array('#prefix' => ''); - $build[$key]['#prefix'] = $build[$key]['#title'] . ":\n"; - $build[$key]['#label_display'] = 'hidden'; - } - } - $build = array( - '#markup' => drupal_html_to_text(drupal_render($build)), - ); - } - return $build; - } - -} diff --git a/core/modules/contact/lib/Drupal/contact/Tests/ContactAuthenticatedUserTest.php b/core/modules/contact/lib/Drupal/contact/Tests/ContactAuthenticatedUserTest.php index 059923f..cd8e39d 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/ContactAuthenticatedUserTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/ContactAuthenticatedUserTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\contact\ContactAuthenticatedUserTest. + * Contains \Drupal\contact\ContactAuthenticatedUserTest. */ namespace Drupal\contact\Tests; diff --git a/core/modules/contact/lib/Drupal/contact/Tests/ContactPersonalTest.php b/core/modules/contact/lib/Drupal/contact/Tests/ContactPersonalTest.php index c7056a7..91aaace 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/ContactPersonalTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/ContactPersonalTest.php @@ -2,11 +2,12 @@ /** * @file - * Definition of Drupal\contact\Tests\ContactPersonalTest. + * Contains \Drupal\contact\Tests\ContactPersonalTest. */ namespace Drupal\contact\Tests; +use Drupal\Core\Session\AccountInterface; use Drupal\simpletest\WebTestBase; /** @@ -78,13 +79,13 @@ function testSendPersonalContactMessage() { $this->assertEqual($mail['key'], 'user_mail'); $variables = array( '!site-name' => \Drupal::config('system.site')->get('name'), - '!subject' => $message['subject'], + '!subject' => $message['subject[0][value]'], '!recipient-name' => $this->contact_user->getUsername(), ); $this->assertEqual($mail['subject'], t('[!site-name] !subject', $variables), 'Subject is in sent message.'); $this->assertTrue(strpos($mail['body'], t('Hello !recipient-name,', $variables)) !== FALSE, 'Recipient name is in sent message.'); $this->assertTrue(strpos($mail['body'], $this->web_user->getUsername()) !== FALSE, 'Sender name is in sent message.'); - $this->assertTrue(strpos($mail['body'], $message['message']) !== FALSE, 'Message body is in sent message.'); + $this->assertTrue(strpos($mail['body'], $message['message[0][value]']) !== FALSE, 'Message body is in sent message.'); } /** @@ -212,18 +213,22 @@ function testPersonalContactFlood() { /** * Fills out a user's personal contact form and submits it. * - * @param $account + * @param \Drupal\Core\Session\AccountInterface $account * A user object of the user being contacted. - * @param $message + * @param array $message * (optional) An array with the form fields being used. Defaults to an empty * array. + * + * @return array + * An array with the form fields being used. */ - protected function submitPersonalContact($account, array $message = array()) { + protected function submitPersonalContact(AccountInterface $account, array $message = array()) { $message += array( - 'subject' => $this->randomName(16), - 'message' => $this->randomName(64), + 'subject[0][value]' => $this->randomName(16), + 'message[0][value]' => $this->randomName(64), ); $this->drupalPostForm('user/' . $account->id() . '/contact', $message, t('Send message')); return $message; } + } diff --git a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php index 126fc75..3e74e8c 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\contact\Tests\ContactSitewideTest. + * Contains \Drupal\contact\Tests\ContactSitewideTest. */ namespace Drupal\contact\Tests; @@ -20,7 +20,7 @@ class ContactSitewideTest extends WebTestBase { * * @var array */ - public static $modules = array('text', 'contact', 'field_ui'); + public static $modules = array('contact', 'field_ui'); public static function getInfo() { return array( @@ -257,14 +257,14 @@ function testSiteWideContact() { // Submit the contact form and verify the content. $edit = array( - 'subject' => $this->randomName(), - 'message' => $this->randomName(), + 'subject[0][value]' => $this->randomName(), + 'message[0][value]' => $this->randomName(), $field_name . '[0][value]' => $this->randomName(), ); $this->drupalPostForm(NULL, $edit, t('Send message')); $mails = $this->drupalGetMails(); $mail = array_pop($mails); - $this->assertEqual($mail['subject'], t('[@label] @subject', array('@label' => $label, '@subject' => $edit['subject']))); + $this->assertEqual($mail['subject'], t('[@label] @subject', array('@label' => $label, '@subject' => $edit['subject[0][value]']))); $this->assertTrue(strpos($mail['body'], $field_label)); $this->assertTrue(strpos($mail['body'], $edit[$field_name . '[0][value]'])); } @@ -381,8 +381,8 @@ function submitContact($name, $mail, $subject, $id, $message) { $edit = array(); $edit['name'] = $name; $edit['mail'] = $mail; - $edit['subject'] = $subject; - $edit['message'] = $message; + $edit['subject[0][value]'] = $subject; + $edit['message[0][value]'] = $message; if ($id == \Drupal::config('contact.settings')->get('default_category')) { $this->drupalPostForm('contact', $edit, t('Send message')); } diff --git a/core/modules/contact/lib/Drupal/contact/Tests/MessageEntityTest.php b/core/modules/contact/lib/Drupal/contact/Tests/MessageEntityTest.php index fd5300b..afe6457 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/MessageEntityTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/MessageEntityTest.php @@ -21,7 +21,7 @@ class MessageEntityTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('system', 'contact', 'field', 'user'); + public static $modules = array('system', 'contact', 'field', 'user', 'text'); public static function getInfo() { return array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php index 907741e..cb47b46 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php @@ -128,7 +128,7 @@ function testModuleEnableOrder() { // - options depends on number // - ban depends on xmlrpc (via module_test) // The correct enable order is: - $expected_order = array('filter', 'xmlrpc', 'ban', 'text', 'node', 'datetime', 'comment', 'history', 'number', 'options', 'taxonomy', 'forum'); + $expected_order = array('filter', 'text', 'xmlrpc', 'ban', 'node', 'datetime', 'comment', 'history', 'number', 'options', 'taxonomy', 'forum'); // Enable the modules through the UI, verifying that the dependency chain // is correct.