Jsonapi module serialises nodes and outputs them as JSON, however the "moderation_state" property is null, even though I have saved a page in the "published" state.

After hunting for the reason why, I've discovered that ModerationStateFieldItemList is not running computeModerationFieldItemList() on an isEmpty() check, so it returns true (empty) and the serialiser sets the field value to null.

Adding this method to ModerationStateFieldItemList resolves the problem:

  public function isEmpty() {
    $this->computeModerationFieldItemList();
    return parent::isEmpty();
  }
CommentFileSizeAuthor
#2 2927144-2.patch1.5 KBChris Gillis

Comments

Chris Gillis created an issue. See original summary.

Chris Gillis’s picture

StatusFileSize
new1.5 KB

Initial patch attached.

cilefen’s picture

Status: Active » Needs review
timmillwood’s picture

Status: Needs review » Closed (duplicate)

I'm closing this as a duplicate of #2915398: The moderation_state field is not computed during the creation of a new entity translation. which will implement \Drupal\Core\TypedData\ComputedItemListTrait in ModerationStateFieldItemList, this includes:

  public function isEmpty() {
    $this->ensureComputedValue();
    return parent::isEmpty();
  }
Chris Gillis’s picture

Thanks Tim.