Problem/Motivation

On sites with content_moderation, scheduler and scheduler_content_moderation_integration modules enabled, but no content type with workflow applied to, the immediately publishing of a scheduled node fails with the error:
Drupal\Core\Entity\EntityStorageException: Field moderation_state is unknown. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 815 of /var/www/pilootsites/staging/application/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Our use case is a default setup of content moderation + scheduler, for a shared configuration for many sites, where by default workflow is not applied. The application of workflow to a content type is done on a config split for each particular site.

Steps to reproduce

  1. Check on a site with content_moderation, scheduler and scheduler_content_moderation_integration enabled
  2. Add a workflow to the site
  3. Do not apply this workflow to any content type
  4. Configure a content type to have scheduling added, and add the fields publish on and unpublish on to the node form
  5. Create an unpublished node and schedule to publish in the past
  6. See that the error is thrown
  7. Apply workflow to any content type, not necessarily the one you are tesing
  8. Repeate the above steps
  9. And observe no error is thrown

Proposed resolution

Add a simple condition to https://git.drupalcode.org/project/scheduler_content_moderation_integrat... to check for the existence of the field.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

webfordreams created an issue. See original summary.

msteurs’s picture

Title: Immediately publishing a node fails when no content type have content moderation enabled » Immediately publishing a node fails when no content type have content moderation applied
nginex’s picture

Assigned: msteurs » nginex
Status: Active » Needs work
nginex’s picture

Status: Needs work » Needs review
nginex’s picture

Assigned: nginex » Unassigned
Status: Needs review » Reviewed & tested by the community

Updated patch a bit, the patch does the job, RTBC

jonathan1055’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for reporting this. Can you fix it for coding standards/linting, the test result of "PHPLint Failed" needs to be sorted before we can consider the change.

nginex’s picture

Assigned: Unassigned » nginex

I see, I used some features that are available since php 7.4, but this module should still support php 7.3 based on tests, ok, I will change it

nginex’s picture

Assigned: nginex » Unassigned
Status: Needs work » Needs review

@jonathan1055,

Let's see if it works now for php 7.3 test

smustgrave made their first commit to this issue’s fork.

smustgrave’s picture

Version: 8.x-1.x-dev » 2.x-dev

Rebased for 2.x since 8.x-1.x is no longer supported.

smustgrave’s picture

Status: Needs review » Fixed

Going to merge as it does solve the issue. 2.x branch is currently broken so that's not showing correct info.

jonathan1055’s picture

Status: Fixed » Active

The fix added

$entity = $event->getNode();

but immediately after the new conditional check, we already had

$entity = $event->getEntity();

Is there a reason why we have to use getNode()? It seems wrong (a) to have both calls, and (b) it should be content-type generic, not just for nodes.

Putting this back to 'active' to that it does not get 'closed (fixed)' after two weeks.

smustgrave’s picture

Version: 2.x-dev » 3.0.x-dev

  • smustgrave committed 190cc43b on 3.0.x
    feat: #3375080 Immediately publishing a node fails when no content type...
smustgrave’s picture

Status: Active » Fixed

Nice catch!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.