class MessageViewBuilder
Same name and namespace in other branches
- 11.x core/modules/contact/src/MessageViewBuilder.php \Drupal\contact\MessageViewBuilder
Render controller for contact messages.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Entity\EntityViewBuilder extends \Drupal\Core\Entity\EntityHandlerInterface, \Drupal\Core\Entity\EntityViewBuilderInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Entity\EntityHandlerBase
- class \Drupal\contact\MessageViewBuilder implements \Drupal\Core\Entity\EntityViewBuilder
- class \Drupal\Core\Entity\EntityViewBuilder extends \Drupal\Core\Entity\EntityHandlerInterface, \Drupal\Core\Entity\EntityViewBuilderInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Entity\EntityHandlerBase
Expanded class hierarchy of MessageViewBuilder
File
-
core/
modules/ contact/ src/ MessageViewBuilder.php, line 12
Namespace
Drupal\contactView source
class MessageViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
$build = parent::getBuildDefaults($entity, $view_mode);
// The message fields are individually rendered into email templates, so
// the entity has no template itself.
unset($build['#theme']);
return $build;
}
/**
* {@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\Core\Mail\MailFormatHelper::htmlToText() to
// convert DIVs correctly.
foreach (Element::children($build) as $key) {
if (isset($build[$key]['#label_display']) && $build[$key]['#label_display'] == 'above') {
$build[$key] += [
'#prefix' => '',
];
$build[$key]['#prefix'] = $build[$key]['#title'] . ":\n";
$build[$key]['#label_display'] = 'hidden';
}
}
}
return $build;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.