Problem/Motivation

Views taxonomy term filter config schema should contain a sequence of integers, not strings. The schema doesn't match our expectations.

See #2372855-58: Add content & config entity dependencies to views and #2372855-60: Add content & config entity dependencies to views.

Along the way of fixing this bug, we found it is not possible to cleanly implement due to how merging base types is behaving unexpectedly for sequence types and would be impossible while merging/overriding other type information is entirely possible.

Proposed resolution

Adjust the schema and occurrences. Fix the type merging in configuration schema so sequences can be overridden in subtypes like the rest of the types.

Remaining tasks

Review.

User interface changes

None.

API changes

None.

Beta phase evaluation

-->

Reference: https://www.drupal.org/core/beta-changes
Issue priority Major because sequences cannot be subtyped with item type changes in config schema. This is a systemic problem and does not match expectations that other types have.
Prioritized changes Prioritized for the beta phase because it changes configuration schemas for views filters and fixes a bug in how configuration schemas work (and may be written).

Comments

gábor hojtsy’s picture

Issue tags: +Needs tests

Does that have a failing test? If yeah it may be easier to fix it there. It may be more painful to provide a standalone test here.

wim leers’s picture

Yes, it caused a failed test, that's how it was discovered

gábor hojtsy’s picture

Right, it may be simpler to fix it there? No need for one more explicit test then?

wim leers’s picture

If you want to reroll the patch there to include that change, that's fine by me :)

gábor hojtsy’s picture

Status: Active » Postponed
Issue tags: -Needs tests

So we can postpone on #2372855: Add content & config entity dependencies to views and just update that config.

effulgentsia’s picture

Status: Postponed » Active
xjm’s picture

Issue tags: +VDC
xjm’s picture

Issue tags: +Novice

This also could probably be a novice issue!

gábor hojtsy’s picture

Status: Active » Needs review
Issue tags: +D8 upgrade path
StatusFileSize
new1.83 KB

Where the schema is incorrect, it will be a D8 upgrade path issue because we would need to write an update function for updating the config structure to the new correct expectation. At that point I am not sure this would be a novice.

Additionally to the incorrect value type on views.filter.taxonomy_index_tid (inherited from views.filter.many_to_one), the definition of views.filter.taxonomy_index_tid_depth was entirely incorrect. It inherits from views.filter.taxonomy_index_tid on the PHP side (class TaxonomyIndexTidDepth extends TaxonomyIndexTid) so should on the schema side. Then all the duplicate keys should be removed (including values). The only new field is depth. See TaxonomyIndexTidDepth::defineOptions().

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine for me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: 2392263-taxonomy-views-filter-schema.patch, failed testing.

gábor hojtsy’s picture

Title: Views taxonomy term filter config schema should contain a sequence of integers, not strings » Sequence subtyping cannot override item type in config schema, views taxonomy term filter schema incorrect
Priority: Normal » Major
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Novice
StatusFileSize
new1.88 KB
new3.71 KB

So this is a WAY bigger mess than expected. The problem is as follows:

1. views_filter defines a value key as a dynamic type based on the filter's plugin_id:

views_filter:
  type: views_handler
  mapping:
    ...
    value:
      type: views.filter_value.[%parent.plugin_id]
      label: 'Value'
    ...

So all types extending from views_filter theoretically need to define their own value via subtyping in the views.filter_value.X namespace. Here are some:

views.filter_value.boolean:
  type: boolean

views.filter_value.combine:
  type: string

That is all good, and these are actually single value filter types. BUT then there are multivalue field types, chiefly InOperator and its extension ManyToOne. The config schema for those defined the value as a sequence of strings.

views.filter.in_operator:
  type: views_filter
  label: 'IN operator'
  mapping:
    ...
    value:
      type: sequence
      label: 'Values'
      sequence:
        - type: string
          label: 'Value'
    ...

Due to how this is deepmerged, the sequence typing overrides the original dynamic type so all in_operator inheritors (such as many to one, taxonomy index tid, etc) take the string sequence instead of the dynamic type.

Now we naturally want to override that in views.filter.taxonomy_index_tid which turns out to be impossible. Why? If you look into TypedConfigManager::getDefinition(), the definition is merged in with the parent, giving the child precedent but NestedArray::mergeDeep() is used, which accumulates numerically indexed array items instead of replacing them with each other. Configuration schema uses numerically indexed items for typing only for sequences. It is a bit of an odd use of a list because it can only ever have one item, but well, that is how it is now. We could change that and incur the API change across all schemas or we need to fix the merging to not accumulate array items (having second and third type definitions for the sequence) but to overwrite it, so our type definition for the taxonomy item will prevail.

Definitely not novice and at least a major.

Additionally to the PHP bugfix, removing the elements from many_to_one that are already inherited and removing a never ever used views.filter_value.language since the parent filter definition is an in_operator, so as discussed above, the dynamic views.filter_value.language value would never be consulted anyway. (Its also incorrect, the in_operator is multivalued not single valued).

Updated issue summary and added beta evaluation as well.

vijaycs85’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

  1. +++ b/core/modules/views/config/schema/views.filter.schema.yml
    @@ -101,18 +101,9 @@ views.filter.many_to_one:
    -    operator:
    ...
    -    value:
    

    another cleanup?

  2. +++ b/core/modules/views/config/schema/views.filter.schema.yml
    @@ -140,7 +131,3 @@ views.filter_value.combine:
    -views.filter_value.language:
    

    left over removal++

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed a542a43 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation.

  • alexpott committed a542a43 on 8.0.x
    Issue #2392263 by Gábor Hojtsy: Sequence subtyping cannot override item...

Status: Fixed » Closed (fixed)

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