- 🇬🇧United Kingdom aimai
Updated the patch to use
$workflow_type_plugin
in the else statement as well. Attached a reroll of #7 which works with the #3027690-16: Do not send notification if moderation state has not changed → patch.
Probably the best way to describe this is with an example. Suppose you have a really basic moderation workflow with only two states: "Draft" and "Published", and the default moderation state is Draft. Now imagine you have a notification set up for the transition from draft->published that sends some kind of notification to the user like "Your post was successfully published! See it here... etc.".
Right now, if the user creates a new post, and immediately sets the state to Published, no notification will be sent. But I believe that it should. The idea being that if the default state is Draft, then the draft->published transition should still happen here even though it wasn't technically saved as a draft first.
I think the issue really stems from the getInitialState()
method. getInitialState()
was designed to figure out the initial state based on the content's current publish status so that it picked the right value on existing entities that didn't already have a state. Ref:
#2817835: When enabling moderation apply a relative state →
. And here's what getInitialState() look like on the ContentModeration WorkflowType plugin:
/**
* {@inheritdoc}
*/
public function getInitialState($entity = NULL) {
// Workflows are not tied to entities, but Content Moderation adds the
// relationship between Workflows and entities. Content Moderation needs the
// entity object to be able to determine the initial state based on
// publishing status.
if (!($entity instanceof ContentEntityInterface)) {
throw new \InvalidArgumentException('A content entity object must be supplied.');
}
if ($entity instanceof EntityPublishedInterface && !$entity->isNew()) {
return $this->getState($entity->isPublished() ? 'published' : 'draft');
}
return $this->getState(!empty($this->configuration['default_moderation_state']) ? $this->configuration['default_moderation_state'] : 'draft');
}
Since we're sending notifications on an insert hook, the entity is already saved by the time we call getInitialState()
. Using our example above, the entity will be not new, and published so it will just return the hardcoded 'published' state (instead of draft as we had configured).
Instead of using getInitialState()
, we should just use the default_moderation_state setting to determine the previous state in the case that there is no "last_revision" (i.e. when new entities are created).
Review Patch
One thing to consider with this one is whether or not people were relying previously on notifications not being sent in this type of case.
Needs work
3.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Updated the patch to use $workflow_type_plugin
in the else statement as well.
Attached a reroll of #7 which works with the #3027690-16: Do not send notification if moderation state has not changed → patch.