function MessageViewBuilder::view

Same name in other branches
  1. 9 core/modules/contact/src/MessageViewBuilder.php \Drupal\contact\MessageViewBuilder::view()
  2. 8.9.x core/modules/contact/src/MessageViewBuilder.php \Drupal\contact\MessageViewBuilder::view()
  3. 10 core/modules/contact/src/MessageViewBuilder.php \Drupal\contact\MessageViewBuilder::view()

Overrides EntityViewBuilder::view

File

core/modules/contact/src/MessageViewBuilder.php, line 28

Class

MessageViewBuilder
Render controller for contact messages.

Namespace

Drupal\contact

Code

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.