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
- Check on a site with content_moderation, scheduler and scheduler_content_moderation_integration enabled
- Add a workflow to the site
- Do not apply this workflow to any content type
- Configure a content type to have scheduling added, and add the fields publish on and unpublish on to the node form
- Create an unpublished node and schedule to publish in the past
- See that the error is thrown
- Apply workflow to any content type, not necessarily the one you are tesing
- Repeate the above steps
- 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.
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
Comment #3
msteurs commentedComment #4
nginex commentedComment #5
nginex commentedComment #6
nginex commentedUpdated patch a bit, the patch does the job, RTBC
Comment #7
jonathan1055 commentedThanks 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.
Comment #8
nginex commentedI 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
Comment #9
nginex commented@jonathan1055,
Let's see if it works now for php 7.3 test
Comment #11
smustgrave commentedRebased for 2.x since 8.x-1.x is no longer supported.
Comment #13
smustgrave commentedGoing to merge as it does solve the issue. 2.x branch is currently broken so that's not showing correct info.
Comment #14
jonathan1055 commentedThe fix added
but immediately after the new conditional check, we already had
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.
Comment #15
smustgrave commentedComment #17
smustgrave commentedNice catch!