Having a problem theming or changing the looks of my outgoing contact form e-mails.
I have followed this topic on the subject: How can I theme the outgoing contact mail?
I have done all the points nicholas.alipaz mentions (except 7. since I don't need that). I also have Berdirs code in my .theme and custom module. (yourmodule is of course replaced with the real theme name [is it supposed to be the module name for the custom module or the theme name??])
In .theme file:
/**
* Implements hook_entity_type_alter().
* @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
*/
function yourmodule_entity_type_alter(array &$entity_types) {
$entity_types['contact_message']->setViewBuilderClass('Drupal\yourmoule\ContactMessageViewBuilder');
}
/**
* Implements hook_mail_alter().
*/
function yourmodule_mail_alter(&$message) {
if ($message['module'] == 'contact' && isset($message['params']['contact_message'])) {
// Enforce that we are sending mails as HTML.
$message['headers']['Content-Type'] = 'text/html';
}
}
In custom module:
namespace Drupal\yourmodule;
use Drupal\contact\MessageViewBuilder;
use Drupal\Core\Entity\EntityInterface;
/**
* Customized contact message view that does not do HTML to plain conversion.
*/
class ContactMessageViewBuilder extends MessageViewBuilder {
/**
* {@inheritdoc}
*/
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
$build = parent::view($entity, $view_mode, $langcode);
// Remove the post render callback that converts the HTML to plain text.
unset($build['#post_render']);
return $build;
}
}
I selected one column view via display suite but the only thing that happened was
< data-quickedit-entity-id="contact_message/" class="view-mode-mail ds-1col clearfix">
was added to the e-mail after the "user sent message using contact form at" text. The email itself was in plaintext, not HTML.
I really am at a loss here, what to do and I couldn't comment, so I had to make a new topic about the same thing.