diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 40af331..4fb8759 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -173,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_html_to_text(drupal_render($build)); + $message['body'][] = drupal_render($build); break; case 'page_autoreply': @@ -192,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_html_to_text(drupal_render($build)); + $message['body'][] = 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 7a7fbd5..20942e1 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\Core\Entity\EntityViewBuilder", + * "view_builder" = "Drupal\contact\MessageViewBuilder", * "form" = { * "default" = "Drupal\contact\MessageFormController" * } diff --git a/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php b/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php new file mode 100644 index 0000000..5e5b6dd --- /dev/null +++ b/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php @@ -0,0 +1,61 @@ +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; + } + +}