Call to a member function isPublished() on null when saving new content entity as draft

Created on 20 January 2023, about 2 years ago
Updated 30 April 2023, over 1 year ago

Problem/Motivation

When using Preview functionality, and Content Moderation, when a new content entity is created and not published, there is no `$entity-original` available in the insert hook. However, `$gatsbyPreview->gatsbyPrepareData` assumes there is, and an error is triggered.

Error: Call to a member function isPublished() on null in Drupal\gatsby\GatsbyPreview->gatsbyPrepareData() (line 104 of /var/www/web/modules/contrib/gatsby/src/GatsbyPreview.php)

Steps to reproduce

Configure Gatsby module with a preview URL, incremental build URL, entity type "Content", and do not check the box for "Only log entities for published content".
Configure a content moderation workflow with at least "draft" and "published" states and include content types.
Create a new node of a content type under content moderation, and save as "draft".

Proposed resolution

Update to `GatsbyPreview->gatsbyPrepareData()` to check for `$entity->original` instead of assuming it exists. Patch attached.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇺🇸United States lisagodare@gmail.com

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024