You are here

protected function ModerationStateFieldItemList::computeValue in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php \Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList::computeValue()

Computes the values for an item list.

Overrides ComputedItemListTrait::computeValue

File

core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php, line 25

Class

ModerationStateFieldItemList
A computed field that provides a content entity's moderation state.

Namespace

Drupal\content_moderation\Plugin\Field

Code

protected function computeValue() {
  $moderation_state = $this
    ->getModerationStateId();

  // Do not store NULL values, in the case where an entity does not have a
  // moderation workflow associated with it, we do not create list items for
  // the computed field.
  if ($moderation_state) {

    // An entity can only have a single moderation state.
    $this->list[0] = $this
      ->createItem(0, $moderation_state);
  }
}