Spin-off of #2329937: Allow definition objects to provide options:

Problem/Motivation

The current AllowedValuesInterface has some terminology problems:
- It's not primarily about allowed values, but about both options and their associated values. As options include values, refering to options in the name makes sense.
- The interface is called AllowedValuesInterface, but an $object implementing the AllowedValuesInterfaces *is not* the allowed values - it can provide them to you.
- The term AllowedValues is only in the name, but not in any of its methods.

Proposed resolution

Rename AllowedValuesInterface to OptionsProviderInterface.
That plays well with the bigger plan over at #2329937: Allow definition objects to provide options as well.

Remaining tasks

Do it.

User interface changes

-

API changes

Rename of AllowedValuesInterface to OptionsProviderInterface ;)

Comments

fago’s picture

Status: Active » Needs review
StatusFileSize
new12.86 KB
fago’s picture

Title: Renamed AllowedValuesInterface to OptionsProviderInterface » Rename AllowedValuesInterface to OptionsProviderInterface

Status: Needs review » Needs work

The last submitted patch, 1: d8_allowed_values_rename.patch, failed testing.

cs_shadow’s picture

Status: Needs work » Needs review
StatusFileSize
new12.49 KB

Status: Needs review » Needs work

The last submitted patch, 5: rename-2332885-5.patch, failed testing.

cs_shadow’s picture

StatusFileSize
new11.23 KB
cs_shadow’s picture

Status: Needs work » Needs review

Let's try again. Forgot to `git pull` last time.

Status: Needs review » Needs work

The last submitted patch, 7: rename-2332885-7.patch, failed testing.

Status: Needs work » Needs review

cs_shadow queued 7: rename-2332885-7.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 7: rename-2332885-7.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new11.39 KB
new295 bytes

Looks like the file wasn't renamed...

catch’s picture

I'm not 100% on this for a couple of reasons:

1. The field settings key is still allowed_values

2. In the case of entity reference fields, lots of widgets don't actually use options, and the method just gets used for validation (and for something that taxonomy terms where we only want to check which vocabulary a term is in most of the time, it's really inefficient to check it that way).

3. There's a bit of a weird situation where you have to implement this interface to be able to use certain widgets/formatters, but that doesn't necessarily have anything to do with the field type itself. So a list field that is text or number has exactly the same schema as a non-list field that is text or number - the only difference is this interface and the allowed values setting. The fact the allowed_values setting does double duty for both options and validation feels like a limitation more than a feature.

yched’s picture

Re #13: note that "allowed_values" is only how List* field types chose to formulate their notion of "AllowedValuesInterface / OptionsProvider", the is no generic meaning for "allowed_values" (taxo does too, for D7 reasons).

The one generic feature here is AllowedValuesInterface / OptionsProviderInterface", which is intended to be the interface that makes the generic widgets and formatters work independantly of the field type - well, and for validation too.

I think that the move from "XxxItem implements AllowedValuesInterface" to "The FieldDefinition specifies an OptionsProvider" (as #2329937: Allow definition objects to provide options is doing IIRC) is a good move. So if we think "options" is too UI tainted and does not reflect the use for validation, maybe AllowedValuesProvider ?

catch’s picture

AllowedValuesProvider would work for me.

fago’s picture

yeah, there is allowed_values also, but I'd argue that it's not OptionsProvider what is mis-named as the setting actually contains not only the allowed values, but the allowed values + their labels, i.e. the options. Thus renaming the setting might make sense, but as this is something internal to the field-type implementation it seems like being a separate issue to me (and I do not care much as its internal).

The fact the allowed_values setting does double duty for both options and validation feels like a limitation more than a feature.

yes, but it's actually options who do the double-duty. They provide options + allowed values. Allowed-values do not necessarily include labels, so for having both features you need options imo.

fago queued 12: rename-2332885-12.patch for re-testing.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Discussed with fago in irc and he's going to open an issue to look at list fields (and we probably need one for taxonomy too to stop using options for validation regardless of the formatter - that's an easy OOM).

Back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed f61ad20 and pushed to 8.0.x. Thanks!

  • alexpott committed f61ad20 on 8.0.x
    Issue #2332885 by cs_shadow, Berdir, fago: Rename AllowedValuesInterface...
fago’s picture

Status: Fixed » Closed (fixed)

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