Problem/Motivation
InOperator introduces the getValueOptions() method. It returns the value options. Not all children of the class return the options. They should.
Proposed resolution
Return the values the method already sets up.
Remaining tasks
Review. Commit.
User interface changes
NONE
API changes
NONE. Children do the same return behavior as InOperation already does.
Data model changes
NONE
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | interdiff.txt | 738 bytes | gábor hojtsy |
| #27 | 2605214-27.patch | 7.88 KB | gábor hojtsy |
| #23 | 2605214-23.patch | 7.15 KB | gábor hojtsy |
| #23 | interdiff.txt | 2.98 KB | gábor hojtsy |
| #19 | interdiff.txt | 1.02 KB | gábor hojtsy |
Comments
Comment #2
eclipsegc commentedCODE!
Comment #4
eclipsegc commentedThis appears to be passing tests as expected.
Eclipse
Comment #5
eclipsegc commentedTagging for rc triage.
Eclipse
Comment #6
alexpottLooks like a testable bug to me...
Comment #7
dawehnerHistorically this function was not meant to return something, but yeah I always hated that design.
These are the examples we should change in order to be consistent.
\Drupal\user\Plugin\views\filter\Roles::getValueOptions\Drupal\user\Plugin\views\filter\Permissions::getValueOptions\Drupal\user\Plugin\views\filter\Name::getValueOptions\Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::getValueOptions\Drupal\file\Plugin\views\filter\Status::getValueOptions\Drupal\comment\Plugin\views\filter\NodeComment::getValueOptionsComment #8
eclipsegc commentedOver in #2607594: Customize views block settings on each block instance I'm using this method to determine user input on exposed filters that are being used as block configuration. For every single one of the filter plugins dawhener just mentioned, I'd have to guess at the submitted value during block submit in order to determine if the form element had been interacted with at all. With return values (which at least some other filters actually do) I can determine if the exposed filter's "submitted value" should be saved as configuration or if I can throw it away.
Eclipse
Comment #9
chuchunaku commentedMaking sure that the other plugins all have proper return values.
Comment #10
tim.plunkettThis should be converted to a // comment on it's own line in between. Also capitalize the D and put a . at the end
Hmm. This and the other one should probably be the same comment. Maybe it needs rewriting in general. Also they could use {@inheritdoc} docblocks.
Comment #11
chuchunaku commentedThanks @tim.plunkett . I made the above changes and attached a new patch.
Comment #12
jacobak commentedComment #13
jacobak commented@ChuChuNaKu,
Your changes look good, but based on the files suggested for change by @dawehner, you missed making changes to:
\Drupal\user\Plugin\views\filter\Permissions::getValueOptions
\Drupal\views\Plugin\views\filter\LanguageFilter::getValueOptions
Should these also be changed?
Also in some of the cases there are comments that note: // Don't overwrite the value options.
Should there be a comment such as //Overwrite the value options.
or something similar in functions that do change them?
Comment #14
dawehnerYEAH IMHO we should change all of them.
Comment #15
chuchunaku commentedSorry about that! I included the two missing changes.
Comment #16
andypostComment #17
dawehnerThis is a super weird comment now. Can we maybe come up with something better?
Comment #18
chuchunaku commentedI just used the comment that was already there but I'm open for suggestions. How about $this->valueOptions should not be overwritten ?
Comment #19
gábor hojtsySo the two methods where the comment is debated the methods override the base implementation in InOperator. That has:
(Note the InOperator already returns the options :P) So in effect, what we are doing in this patch is we return the value even if not set. (With or without this patch, options callback is not supported). Not sure this can be succinctly explained in a short comment. I guess Yes/No are not good defaults for a taxonomy term or username :) We could say "return the value options as-is" but that is what the code does, so not a very valuable comment. I would just do away with the comment.
Comment #20
gábor hojtsyAs for what tests are there for getValueOptions():
Are all the test mentions.
Comment #21
gábor hojtsyAlso as to whether this is an API change InOperator::getValueOptions() is not defined on an interface. Parents do not implement it. The first definition is on InOperator. That returns the value options. So the children do it wrong to not return it. Not sure if adding an interface would constitute an API change in a funny turn of events given a new requirement :D So for a point release fix, I don't think we should make an interface.
Comment #22
gábor hojtsyComment #23
gábor hojtsyTest coverage. In detail:
- language filter tested with all options
- permissions filter test updated to not call the get method twice, so expecting it to return the right value right away
- roles test updated to assert for roles options
- user name filter test updated to assert NULL (there is nothing that sets the value options, so that will be NULL)
Reviews welcome :)
Comment #24
dawehnerGreat cleanup!
For those methods it is perfect to return effectively NULL, as they don't provide all possible value options. Examples like the taxonomy one would cause too many items at once,
so we rather rely on an autocomplete widget.
Nice small cleanup!
Comment #25
gábor hojtsy@dawehner: yeah, re the one line removed, now that the permissions are returned in all cases immediately, we can/should get rid of calling it twice :)
Comment #26
alexpottLet's fix up the @return documentation as we're now saying that it should always return
$this->valueOptionsso the "if someone expects it." seems a bit weird.I'm not sure but maybe also it might be worth a CR for existing contrib views plugins to find out about this fix as they might have copied the incorrect behaviour - from one of the child classes.
Comment #27
gábor hojtsyUpdated with that suggestion.
Comment #28
gábor hojtsyChange record draft at #2633182: Views filter InOperator::getValueOptions() children should always return the stored value options.
Comment #29
dawehnerThank you
Comment #30
alexpottCommitted 66ae877 and pushed to 8.0.x and 8.1.x. Thanks!
Comment #32
alexpottI've committed this to 8.0.x because even though it is an API change now everything conforms to the documentation.
Comment #34
quietone commentedpublished the cr