function ContentModerationStateFormatter::viewElements

Same name in other branches
  1. 9 core/modules/content_moderation/src/Plugin/Field/FieldFormatter/ContentModerationStateFormatter.php \Drupal\content_moderation\Plugin\Field\FieldFormatter\ContentModerationStateFormatter::viewElements()
  2. 8.9.x core/modules/content_moderation/src/Plugin/Field/FieldFormatter/ContentModerationStateFormatter.php \Drupal\content_moderation\Plugin\Field\FieldFormatter\ContentModerationStateFormatter::viewElements()
  3. 10 core/modules/content_moderation/src/Plugin/Field/FieldFormatter/ContentModerationStateFormatter.php \Drupal\content_moderation\Plugin\Field\FieldFormatter\ContentModerationStateFormatter::viewElements()

Overrides FormatterInterface::viewElements

File

core/modules/content_moderation/src/Plugin/Field/FieldFormatter/ContentModerationStateFormatter.php, line 59

Class

ContentModerationStateFormatter
Plugin implementation of the 'content_moderation_state' formatter.

Namespace

Drupal\content_moderation\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    $workflow = $this->moderationInformation
        ->getWorkflowForEntity($items->getEntity());
    foreach ($items as $delta => $item) {
        $elements[$delta] = [
            '#markup' => $workflow->getTypePlugin()
                ->getState($item->value)
                ->label(),
        ];
    }
    return $elements;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.