Closed (fixed)
Project:
Drupal core
Version:
10.1.x-dev
Component:
options.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
8 May 2020 at 00:09 UTC
Updated:
23 Jul 2026 at 15:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
geek-merlinTrivial patch flying in.
Comment #3
geek-merlinComment #4
kristen polThanks for the patch.
IMO it would be good to point out any other places in core where a similar thing is done. Also, this sounds like a feature request rather than a bug report but I'll leave that as is for now.
Comment #5
kristen polI did a quick search and only see
'widget' => $this,incore/lib/Drupal/Core/Field/WidgetBase.phpin below examples. Moving to "Feature request" as I think that is more appropriate.form:formSingleElement:Comment #6
kristen polMoving back to "Needs work" as this would need a test.
Comment #7
geek-merlin> (#4) Also, this sounds like a feature request rather than a bug
This irritates me a bit. The IS provides reasoning for "bug". I'm open to a contrary reasoning about this, but i don't see one here.
> (#6) Moving back to "Needs work" as this would need a test.
I doubt this, as ($claim=) our tests cover logic not APIs like hook parameters. At least i'm not aware of any hook $context test in core, or am i missing something?
> NW
Yes.
TODO: Update options.api.php
Comment #8
kristen polWell, I'll leave it up to the core maintainers to decide and argue about it and I'll stop irritating @geek-merlin here. Cheers! Hope your lockdown is going well.
Comment #9
geek-merlinThis adds documentation in options.api.php
Comment #11
matroskeenI have a similar situation, I have a contrib module that needs to access widget 3rd party settings in order to manipulate the options list.
Currently, I'm using
hook_field_widget_form_alter(), buthook_options_list_alter()makes more sense to allow other modules to make some alterations afterwards (hook_field_widget_form_alter()is executed afterhook_options_list_alter()).I wanted to report about the same issue, and current changes look good to me.
I'm not sure this is a bug report, but as long as it's a "Bug report", the "Bug Smash Initiative" tag seems relevant.
Thanks!
Comment #12
alexpottWe have no test coverage of this feature at all. No implementation what-so-ever in core :)
Regardless of whether this is a bug we do need some test coverage and adding that will ensure we don't break this in the future. OptionsWidgetTest looks like a good place to add this and the hook implementation can be added to options_test.module.
Comment #13
geek-merlinThx @alexpott for looking into this.
Especially the guidance where tests fit best is appreciated a lot! 🌼
Comment #15
geek-merlinHmm, i don't remember prior art testing a hook, so starting freestyle: Hook implementations throws if $context not as expected. I hope the current tests trigger the hook, and add an invocation if needed.
For now testing commit-after-commit, later cleaning up and doing separate MR for test-only (i guess this is best practice).
Commits and their tests:
- Test existing context keys, should be green - https://www.drupal.org/pift-ci-job/1906744 - is green OK
- Test missing 'widget' context key, should be red - https://www.drupal.org/pift-ci-job/1906745 - is green NOK
- Add missing 'widget' context key and document it, should be green - https://www.drupal.org/pift-ci-job/1906746 - green
Hmm, as after the second commit we had test-without-fix situation but still green, my assumption did not hold, so will add a test-only MR and add a hook invocation, cherry-pick to fix-MR later.
Comment #17
geek-merlinOK so it looks like mapping commits to tests does not work if i keep pushing.
And it looks like throwing in a hook gives no useful messages, at least in a Functional BrowserTest:
https://www.drupal.org/pift-ci-job/1906786
Thinking...
Comment #18
matroskeen@geek-merlin, thanks for pushing this forward!
I was wondering, should we really test the incoming parameters?
Probably we can just implement a hook, where make some alterations to the existing options (i.e. remove some option) and then verify that option is not visible.
Comment #19
geek-merlin@alexpott:
OK finally found a way to do the test and get it NR.
Following the approach outlined in #3187361: Make DrupalCI generate and run test-only patches:
Comment #20
matroskeenI was probably not clear in my comment #18, so I'd like to attach a patch with another testing approach - using functional test instead of kernel. Using
OptionsWidgetTestwas recommended by @alexpott in #12.Also, it seems we need a change record for this change, so I created a draft version: https://www.drupal.org/node/3190172
Comment #25
smustgrave commentedPatch or MR doesn't apply anymore
The last patch or MR doesn't apply to the target branch, please reroll the code so that it can be reviewed by the automated testbot.
D10 version needed
At this time we would need a D10.1.x patch or MR for this issue.
Also would be nice to get a tests-only patch for #20 to make sure the issue is being fixed.
Comment #26
smustgrave commentedComment #28
smustgrave commentedEven though I submitted the last patch I only changed a space error. So this review is of #20 really
Change record looks good. The example is great addition!
Also like the test coverage as it shows an example of altering it on a live instance.
I think this is good to move on for core committer review.
Comment #30
alexpottCommitted defcb862d6 and pushed to 10.1.x. Thanks!
Given we're asserting that an element exists let's use the correct assertion - you get better and more consistent error messages. Fixed on commit.