You are here

public function CaseStatusFormatter::viewElements in Case Tracker 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 FormatterInterface::viewElements

File

src/Plugin/Field/FieldFormatter/CaseStateFormatter.php, line 30
Contains Drupal\field_example\Plugin\Field\FieldFormatter\SimpleTextFormatter.

Class

CaseStatusFormatter
Plugin implementation of the 'casetracker_status_formatter' formatter.

Namespace

Drupal\casetracker\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items) {
  $elements = array();
  foreach ($items as $delta => $item) {
    $elements[$delta] = array(
      // We create a render array to produce the desired markup,
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#attributes' => array(
        'style' => 'color: ' . $item->value,
      ),
      '#value' => print_r($item, 1),
    );
  }
  return $elements;
}