Closed (works as designed)
Project:
Drupal core
Version:
11.x-dev
Component:
workflows.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
7 Feb 2017 at 19:14 UTC
Updated:
12 Nov 2024 at 20:23 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
scott_euser commentedPerhaps there is a good reason not to change this that I am missing but it seems to work for me fine and saves deleting and having to recreate.
Comment #3
timmillwoodI think it'd be good to add a test that edits the "to".
Comment #4
alexpottI can't remember for the life of me why we did that. I think it might have been to do with how the ID was being set - but this is no longer done that way. We need tests for this change though.
Comment #5
scott_euser commentedSounds good, should be a good novice one for me to get into testing a bit more. I'll take a first stab at it.
Comment #6
scott_euser commentedTook me a bit to figure out the tests, essentially need to create additional states and transitions then clean up after so other tests work fine.
I matched the formatting of the existing tests but the existing tests have coding standards complaints (lines to long, no empty lines before comments) but I assume the goal of that is to make it easier to see which bits of the code belong together to be able to glance over the method easier? Would be happy to have feedback and advice, especially on the tests.
Comment #7
scott_euser commentedChanging title as it sounds like you both agree that it should be done and just needs the work to be done.
Comment #8
tstoecklerDidn't look at the tests yet, but the code looks great. One comment:
As far as I can tell this validation is not performed in the form, so it's possible to trigger this from the UI, which we should not allow.
Comment #9
scott_euser commentedThanks for the review!
I think it is covered by this:
if ($workflow->hasTransitionFromStateToState($from_state_id, $values['to'])) {within the validation in web/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php as that seems to cover both directions from and to / to and from.
(Edit, adding full validation code, as it's not to understandable without it):
Comment #10
tstoecklerOh that's absolutely correct. Sorry, I hadn't even thought to look.
Comment #11
scott_euser commentedNo problem at all!
Comment #12
scott_euser commentedAdded unit test coverage on top of UI coverage to handle the new method in the Workflow class.
Comment #13
scott_euser commentedComment #14
scott_euser commentedComment #15
alexpottI'm not sure that \Drupal\workflows\Form\WorkflowTransitionAddForm::validateForm() is correct. It might be that you want to duplicate transitions - but have attached different actions and permissions to each transitions. We discussed this a bit in #2779647: Add a workflow component, ui module, and implement it in content moderation. It is tricky - flexibility vs making things simple.
Comment #16
scott_euser commentedShould we open that up then in a separate issue (I haven't touched the validation in the patch) or do you think the validation should be changed along with this?
Comment #17
timmillwoodI think the validation is a separate issue.
The patch in #12 looks good.
Comment #18
th_tushar commentedLooks good. Making it as RTBC!
Comment #19
alexpottWe need to add test coverage of creating a duplication transition by changing a to state in UI.
If there was a new line before each comment the test would be easier to read.
Comment #20
alexpottComment #21
scott_euser commentedOkay sounds good, will add that in likely tomorrow morning.
Comment #22
alexpottRe #15 - I was wrong we decided to prevent such duplicate transitions in UI and API so the approach in the patch is correct. Just need the missing test coverage. @scott_euser++ nice one.
Comment #23
scott_euser commentedUpdated patch with UI test to ensure we cannot create a duplicate transition by changing the 'to'.
Comment #24
sam152 commentedThe test looks looks good. As suggested in #19 adding some newlines between distinct sections of the test would make it seem like less of a wall of text and make it easier to read, but given that's a style thing not a standard RTBCing. Can RTBC any follow-up patches if you feel like resolving that :)
Comment #26
sam152 commentedGiven I only reviewed the interdiff, here are a few things I would probably include in a full review if --uber-nit-mode was on. These comments are totally subjective, so not changing issue status.
s/$transition/$existing_transition/ is perhaps more explicit?
Another style thing, but the comment should describe the "why" more than the "what". The latter is useful when it's not 100% apparent just by glancing at the code, but we can see here transitions are being updated without the comment.
Some deal with the comment here. If a comment was necessary, this could describe why it's important the to_state exists, not that the check is happening. The comment reads exactly like a synonym of the code.
Hint: giving interdiffs a .txt extension will stop the bot testing them.
Comment #27
alexpott@scott_euser - @Sam152 makes some good points in #26 - given that this is an API/UI loosening for an experimental module it can go into a patch release. Therefore there's no rush - let's make the patch perfect :) Readable tests really help future-us.
@Sam152 are there any other nits you'd pick up if "--uber-nit-mode" was on?
Comment #28
scott_euser commentedThanks for the feedback!
1) I had just copied it from the existing setTransitionToState method, but I have changed it.
2) Have tried to make it more clear, but I am not 100% sure how to make it say the why beyond that as it's essentially the action of the method (the rest of the method is just validation that the action is allowed; hopefully that change makes it a bit more clear.
3) Also just copied from the existing setTransitionToState method, but I have changed it to make it more clear.
Comment #29
sam152 commentedIf a comment adds no value, no reason to keep it.
I wonder if the schema definition enforces this as an empty array, making this check not required?
That's all I got, rest LGTM.
Comment #30
sam152 commentedOpened #2851708: Workflow entity getters should return FALSE or NULL instead of throwing an exception if their data doesn't exist as a follow up to discuss being required to call hasTransitionFromStateToState before getTransitionFromStateToState.
Comment #31
scott_euser commentedRe #29 I think as it is at the moment without this if statement, if you would call this function straight away, it could throw a php notice, no?
Removed comment as suggested.
Comment #32
sam152 commentedWe already call isset, so the question is, can a transition be initialized without 'from' as an empty array. FWIW, the tests pass without it.
Comment #33
alexpott@scott_euser Re #2851708: Workflow entity getters should return FALSE or NULL instead of throwing an exception if their data doesn't exist you could just call getTransitionFromStateToState and catch the exception - then less nesting and no call to hasTransitionFromStateToState
Comment #34
alexpott@Sam152 is right this is initialized to be an empty array it will always be one.
You actually only need only need to do this if the to state is changing. And if the to state is changing and
$this->hasTransitionFromStateToState($from_state_id, $to_state_id)returns true then you know that the transition is not your transition.In fact there is a method already to help us get the problem - see \Drupal\workflows\Entity\Workflow::getTransitionIdFromStateToState()...
So the method could look as simple as this:
So I'm going to close #2851708: Workflow entity getters should return FALSE or NULL instead of throwing an exception if their data doesn't exist
Comment #35
alexpottIn my suggested update I did
That's not good because it clashes with $transition_id passed in ... this could be something like:
Comment #36
scott_euser commentedThat works for me and seems to pass test when I reran.
Comment #37
scott_euser commentedComment #41
scott_euser commentedI should be more careful about stopping tests from being run on the interdiffs; waste of resources.
Comment #42
sam152 commentedRTBCing with the last unresolved nit fixed.
Comment #43
scott_euser commentedApologies I missed that one, thanks!
Comment #44
xjmHm it looks like the only change in this hunk is that a local variable is being renamed. That's out-of-scope-ish. I checked this with a word diff. I guess it's for consistency with the added method implementation.
What docs is this inheriting? I couldn't find any existing method named this?
Comment #45
xjmEdit: Nope, this was wrong. Removing to avoid confusion.
Comment #46
xjmHm nope, #45 is not the origin. I thought the change for the machine name had overshot but looks like it was not #36 that introduced the other; bad merge on my part.
Comment #47
xjmAha. So it first appears as this in #2779647-61: Add a workflow component, ui module, and implement it in content moderation:
Comment was:
The comment of @bojanz' being referenced is apparently in #48:
So maybe that will jog memories. If @alexpott still does not remember why, though, then I think the why is lost to history and we should just do what makes the most sense. I guess we could check with @bojanz if this makes any difference for his usecases.
Comment #48
scott_euser commentedThanks for reviewing. Re, the reasoning behind it being originally disabled, I'm not able to chime in on that.
That comes in because of #35
Updated in attached patch. Would it be wise to instead add it to the interface class? If so, we'll need to update quite a few classes that implement it - not sure what the rules are around API changes.
Comment #49
sam152 commentedAPI changes are allowed as this is an experimental module, this should indeed be added to the interface, nice catch @xjm.
Comment #50
scott_euser commentedSounds good, updated
Comment #51
scott_euser commentedAh missing the updates to all the workflowInterfaces, needs work still
Comment #52
scott_euser commentedIt seems no problems caused by any existing tests / implementations of the interface.
Comment #53
sam152 commentedThere is only one implementation of the interface in core, so this looks good to me. I believe that's all of the feedback resolved.
Comment #54
timmillwoodLooks like my RTBC clashed with @Sam152, so +1 to RTBC.
I'm a little confused by the variable name change, it doesn't seem in scope. Not sure that should block things though.
Comment #55
scott_euser commentedThanks for reviewing. Just on my phone but I believe the variable name change comes from #35
Comment #56
xjmYep @timmillwood, I said the same in #44. In #35 alexpott did not suggest changing the variable name in a completely different method, only in the method added by this patch. So let's go ahead and remove that hunk.
I think 'to' should be in quotes here as it is elsewhere; otherwise, it's hard to parse the sentence.
Thanks!
Comment #57
scott_euser commentedUpdated patches as per #54 and #56.
Comment #58
timmillwoodFixes everything in #56.
Comment #59
alexpottSo the reason the 'to' was disabled is this. When you create a transition you label it and this creates a machine name. The label you chose nearly always has the 'to' state in mind - consider the core examples:
@scott_euser Why did you want to change the 'to'? Was there a practical reason - or were you just surprised you couldn't?
I'm ambivalent about the change - ie. I can see that it helps when people make a mistake - but also I can see that the extra freedom gives people more ways to make something confusing when they come back in 6 months time.
Comment #60
scott_euser commentedI do agree that there are risks of renaming to something that doesn't match the machine name, but Isn't that the same case with Nodes / Taxonomy / Menus / etc though? For instance, if you create a node type 'News' the machine name is news, but if you decide to later add commenting and call it a blog, the machine name will still be news and there would be the same confusion.
As the user can delete the transition and start over, also fine if you prefer to leave it as is.
Comment #61
xjmI guess #59 and #60 need further discussion. Thanks!
Comment #62
timmillwoodI'm also ambivalent about the change.
Do we want to give more flexibility or prevent people from creating confusing systems?
I think if I was to sway one way or another it would be flexibility, thus RTBCing this again.
Comment #63
vijaycs85Patch at #57still applies to HEAD cleanly. As there is no straightforward impact of allowing this (except the transition machine name represent 'to' field value, which kinda same case with any other entity machine name as explained by @scott_euser in #60), RTBC assuming it's OK to allow. If not we eventually close this issue as 'won't fix' or 'works as designed' anyway.
Comment #64
gábor hojtsyLooking at the patch I was wondering if the user facing error handling needs updating but the possibility to change the from state already required validation on transition duplicity and indeed, it does still work when changing the destination on my testing.
Comment #65
alexpott@Gábor Hojtsy and @vijaycs85 - I still think we haven't really answered #59. Sure we can make this change but does it really buy us anything? Or does it just potentially make things more confusing? I'd love the UI work to be done before this - ie. #2830584: Use modals for creating, updating, and deleting workflows, with a new DialogFormTrait. Shall we postpone based on that one?
Comment #66
vijaycs85Indeed it is UI related and more of usability improvement than functional change. I am happy to postpone this on #2830584: Use modals for creating, updating, and deleting workflows, with a new DialogFormTrait
Comment #67
alexpottSo let's postpone on #2830584: Use modals for creating, updating, and deleting workflows, with a new DialogFormTrait
Comment #80
amateescu commentedComment #81
scott_euser commentedWow this is an old one; must have been one of my first attempting to do tests :) Rereading wondering if its better just to close this given #59. Deleting a transition and creating it again really only typically means having to redo the permissions, but given its likely to happen while you are setting up a workflow, its likely you have not yet gotten to permissions yet in the first place. Feel free to re-open if disagreeing.