You are here

public function SubmittedFormatter::viewElements in Manage display 8

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides AuthorFormatter::viewElements

File

src/Plugin/Field/FieldFormatter/SubmittedFormatter.php, line 120

Class

SubmittedFormatter
A field formatter for entity titles.

Namespace

Drupal\manage_display\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = parent::viewElements($items, $langcode);
  foreach ($elements as &$element) {
    $element['#theme'] = 'submitted';
    $element['#date'] = $items
      ->getEntity()
      ->get('created')->value ?? NULL;
    if ($view_mode = $this
      ->getSetting('user_picture')) {
      $element['#user_picture'] = \Drupal::entityTypeManager()
        ->getViewBuilder('user')
        ->view($element['#account'], $view_mode, $langcode);
    }
  }
  return $elements;
}