You are here

public function RadioactivityEmitter::view in Radioactivity 8.3

Same name and namespace in other branches
  1. 4.0.x src/Plugin/Field/FieldFormatter/RadioactivityEmitter.php \Drupal\radioactivity\Plugin\Field\FieldFormatter\RadioactivityEmitter::view()

Builds a renderable array for a fully themed field.

Parameters

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

string $langcode: (optional) The language that should be used to render the field. Defaults to the current content language.

Return value

array A renderable array for a themed field with its label and all its values.

Overrides FormatterBase::view

File

src/Plugin/Field/FieldFormatter/RadioactivityEmitter.php, line 127

Class

RadioactivityEmitter
Plugin implementation of the 'radioactivity_emitter' formatter.

Namespace

Drupal\radioactivity\Plugin\Field\FieldFormatter

Code

public function view(FieldItemListInterface $items, $langcode = NULL) {
  $build = parent::view($items, $langcode);

  // If 'none' is chosen (No value - only emit), we do not want this formatter
  // to be rendered as field (it would be rendered in an empty wrapper diff).
  // We only use the children which contain the energy emitter in "#attached".
  if ($this
    ->getSetting('display') == 'none') {
    $children = Element::children($build);
    $build = array_intersect_key($build, $children);
  }
  return $build;
}