Comments

Sam152 created an issue. See original summary.

sam152’s picture

Status: Active » Needs review
StatusFileSize
new7.29 KB
wim leers’s picture

+++ b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
@@ -117,7 +117,7 @@ public function onDependencyRemoval(array $dependencies) {
-  public function getInitialState(WorkflowInterface $workflow) {
+  public function getInitialState() {

+++ b/core/modules/workflows/src/WorkflowTypeInterface.php
@@ -80,13 +80,10 @@ public function workflowStateHasData(WorkflowInterface $workflow, StateInterface
-  public function getInitialState(WorkflowInterface $workflow);
+  public function getInitialState();

This is the API change.


Is this WI Critical?

wim leers’s picture

+++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
@@ -340,11 +340,11 @@ public function getConfiguration() {
-  public function getInitialState(WorkflowInterface $workflow, $entity = NULL) {
+  public function getInitialState($entity = NULL) {

If it's optional, then how can you ensure it is passed?

Shouldn't $entity be required?

sam152’s picture

Issue tags: +WI critical

I agree on critical status.

Currently $entity is not part of the workflows interface because we can't assume all workflow types are necessarily going to be concerned with entities at all, those are semantics that content_moderation introduces. Thus $entity became an optional parameter, so that we're still satisfying the original interface.

Within content_moderation, for all places where we have instances of an entity and the plugin, we're able to get a more contextually-relevant default state. For other consumers of the api, in the cases where they want to use this method, we don't assume an entity is present, the param can be omitted and a return value is falls back to a sane default, still honouring the contract of the interface.

wim leers’s picture

Issue tags: +Needs documentation

#5: Thanks for that explanation! That's then something we should document in both Workflows' API docs ("is not tied to entities") and Content Moderation's docs ("is tied to content entities").

wim leers’s picture

Status: Needs review » Needs work
timmillwood’s picture

Status: Needs work » Needs review
StatusFileSize
new1.03 KB
new7.67 KB

Adding some inline docs to \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration::getInitialState to explain why we are passing in $entity and what we're doing with it.

This should be ready for RTBC now, the code from @Sam152 looks perfect to me, this would be a nice parameter to remove.

wim leers’s picture

  1. The comments added in #8 are very helpful, thanks! I think it'd be good to add though that all calls made to getInitialState() by the Content Moderation module's code MUST pass the $entity parameter.
  2. I still think some documentation like #5 would be great to have in workflows.api.php and content_moderation.api.php.
  3. However, here's a key question: What is a use case of a non-entity workflow?. In other words: why not make getInitialState(EntityInterface $entity) the actual API? Then we don't need to deal with any of these ambiguities. In other words, I'm questioning Currently $entity is not part of the workflows interface because we can't assume all workflow types are necessarily going to be concerned with entities at all
sam152’s picture

#9.3, at this point it'd be the first touch point that makes any such assumption. I think it would be a shame to introduce this coupling, at the expense of flexibility when:

  • We haven't necessarily conceived of every use case yet.
  • The alternative is fairly tolerable.

Happy to add the other suggested docs. Is that in scope for this issue?

wim leers’s picture

Since Drupal's all about entities, I think it's reasonable to limit to entities. That's also what https://www.drupal.org/project/jsonapi did, which allowed it to become significantly simpler (the benefit/impact here is much smaller obviously, we're talking about a single API method).

However, it seems you're strongly convinced that there are use cases beyond entities :) I respect your opinion as the module maintainer of course. I'm merely trying to help you make your maintainer life as simple as possible!

Happy to add the other suggested docs. Is that in scope for this issue?

I think it is, because the lack of clarity around this is the entire reason this issue was spawned!

timmillwood’s picture

We could throw an exception and/or trigger_error if $entity is not set?

I would not want to make $entity a required field in Workflows without passing it by @alexpott who lead the work on splitting it out of Content Moderation. If we are making workflows entity specific we might as well merge the two modules back together.

wim leers’s picture

See, I didn't know about that background/history! :)

My key concern is that some people end up interacting with Workflows' API, and expect it to work also for Content Moderation. But the Workflows API specifies you don't need to pass $entity to getInitialState(). So this is confusing/somewhat contradicting.

But it sounds like this was already discussed. Which issues should I read to understand how we arrived at the current architecture?

timmillwood’s picture

timmillwood’s picture

StatusFileSize
new3.05 KB
new9.9 KB
timmillwood’s picture

Adding the two api.php files, and throwing an exception if the $entity in getInitialState() is not an instance of ContentEntityInterface.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs documentation
StatusFileSize
new2.78 KB
new9.78 KB
  1. +++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
    @@ -345,6 +346,9 @@ public function getInitialState($entity = NULL) {
    +    if (!($entity instanceof ContentEntityInterface)) {
    +      throw new \InvalidArgumentException('A content entity object must be supplied.');
    +    }
    

    +1

  2. +++ b/core/modules/workflows/workflows.api.php
    @@ -0,0 +1,17 @@
    + * This allows the module to tailor the workflow to it's specific need. For
    + * example, Content Moderation module uses it's the Workflow Type Plugin to
    

    s/it's/its/

  3. +++ b/core/modules/workflows/workflows.api.php
    @@ -0,0 +1,17 @@
    + * link workflows to entities. On their own workflows are a stand alone concept,
    

    s/own/own,/
    s/stand alone/stand-alone/

Fixed these nits (and a few more), and RTBC'd!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 17: 2900046-17.patch, failed testing. View results

wim leers’s picture

Issue tags: +Needs reroll
amateescu’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
StatusFileSize
new9.77 KB

Rerolled :)

wim leers’s picture

Looks like this was committed to 8.5.x but the issue was not updated: http://cgit.drupalcode.org/drupal/commit/?id=d4165ff1085da979f52b23a9d8f...

sam152’s picture

I think the commit message got messed up and thus hasn't updated the issue:

commit d4165ff1085da979f52b23a9d8fd5c74d2f998c4
Author: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date:   Fri Aug 11 14:59:26 2017 +0900

    https://www.drupal.org/files/issues/2900046-20.patch
wim leers’s picture

D'oh, right.

But that's only been committed to 8.5.x anyway, we still need this to be committed to 8.4.x. So actually the state of this issue is still accurate :)

wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Nope, I'm wrong — it's since been cherry-picked: http://cgit.drupalcode.org/drupal/commit/?id=7da23b0bbf0a55dd54fc7a352f9... — hurray!

wim leers’s picture

Status: Fixed » Active

This still needs a change record though.

I don't think it makes sense to add this change to the existing https://www.drupal.org/node/2897706 change record, since it's independent from that change set.

sam152’s picture

Status: Active » Needs review
Issue tags: -Needs change record

Added the CR, currently in a draft. Feel free to review/edit or publish.

larowlan’s picture

Status: Needs review » Fixed

Published the CR

Status: Fixed » Closed (fixed)

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