Conditionally use system actions to publish/unpublish nodes

Created on 26 June 2020, about 5 years ago
Updated 13 July 2025, 14 days ago

Problem/Motivation

The Scheduler uses the following snippet to publish nodes:

        // Use the standard actions system to publish and save the node.
        $node = $event->getNode();
        $action_id = 'node_publish_action';
        if ($this->moduleHandler->moduleExists('workbench_moderation_actions')) {
          // workbench_moderation_actions module uses a custom action instead.
          $action_id = 'state_change__node__published';
        }
        $this->entityTypeManager->getStorage('action')->load($action_id)->getPlugin()->execute($node);

As you can see, it always assumes the node_publish_action configuration action entity is present in the system (except when there is a workbench_moderation_actions module). IMHO, we should not hardcode this assumption since those actions can easily be removed if not needed. In our project, the custom scheduler tests failed since we don't have node_publish_action and node_unpublish_action actions installed.

Proposed resolution

Conditionally use node publish/unpublish action if present.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

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

Merge Requests

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