Problem/Motivation

The config schema provided by conditional fields has a value_form part which lets the person setting up the condition choose a value from the field the condition is on that the condition will act on.

If the author of the module which provides the field that the condition is set on has set up their schema with old conventions, or not set up their field correctly at all, this can cause schema validation errors, which cause PHPUnit to abort out of automated tests, among other problems, with the following errors:

Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for core.entity_form_display.node.example.default with the following errors: core.entity_form_display.node.example.default:content.group_example.third_party_settings.conditional_fields.UUID.settings.value_form.value missing schema

Proposed resolution

The contents of the value_form part of the configuration is already controlled by whatever module provides the field. I propose we make value_form use type: ignore to explicitly say "no data typing is possible", i.e.: "configuration schema validity is the module that provides the field's problem", because:

  1. we can't guarantee that the configuration schema definition for the field will be named what we expect or be located where we expect (which precludes us using a reference - note conventions have changed over time and its reasonable to expect they'll evolve in the future)
  2. we can't guarantee that the configuration schema definition for the field will be valid

Remaining tasks

  1. Write a patch
  2. Review and feedback
  3. RTBC and feedback
  4. Commit

User interface changes

None

API changes

None

Data model changes

None

Documentation links

  1. Documentation -> Drupal -> Drupal APIs -> Configuration API -> Configuration schema/metadata
  2. Drupal core Change records -> Configuration schema for field settings, default values and entity view/form displays changed

Comments

Grimreaper created an issue. See original summary.

grimreaper’s picture

Assigned: grimreaper » Unassigned

Ok. After seeing my exported config, I see that it will be very hard to get this working quickly as the config structure depends on the field types.

My problems come from the keys in conditional_fields.settings (conditional_fields.schema.yml):
- value_form
- values
- and sometimes there is a key with the "controlled by" field name

As we are on short timing on a client project, and as we use conditional fields for only one field in the entire project, I will see if we can use the #states form API directly in custom code.

OlgaRabodzei’s picture

Status: Active » Postponed (maintainer needs more info)

Hi, Florent!

Could you, please, clarify what is the problem with the schema?
Of course the settings will depend on value input type in the settings form and on the controlled field widget type.
Also, please, take a look on this issues template https://www.drupal.org/node/1155816

Regards
Olga.

grimreaper’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active

Hello Olga,

Thanks for your reply. Here is an update of the issue summary.

I will need to see the exact case on my current project but another case I found trying to reproduce:

  • A content type with a "list (text)" (field_list_text) field and an entity reference field targeting nodes (field_content)
  • Add a dependency:
    • target field: field_content
    • controlled by: field_list_text
    • visible when field_list_text has a certain value
  • Result: when inspecting with the module config_inspector: in the entity form display, content.field_content.third_party_settings.conditional_fields.f75bfafe-e565-413b-a0c3-5bbca4d7bdf5.settings.value_form.0.value is undefined

Here is the entity form display:

uuid: 8fdfc8f1-64d1-4c42-a9e7-ac3322af9dd8
langcode: en
status: true
dependencies:
  config:
    - field.field.node.page.body
    - field.field.node.page.field_content
    - field.field.node.page.field_list_text
    - node.type.page
  module:
    - path
    - text
_core:
  default_config_hash: sb0qCkzU_8mNq29NehYAU8jCBXWPLeX0UN8sYFVGVcw
id: node.page.default
targetEntityType: node
bundle: page
mode: default
content:
  body:
    type: text_textarea_with_summary
    weight: 31
    region: content
    settings:
      rows: 9
      summary_rows: 3
      placeholder: ''
    third_party_settings: {  }
  created:
    type: datetime_timestamp
    weight: 10
    region: content
    settings: {  }
    third_party_settings: {  }
  field_content:
    weight: 121
    settings:
      match_operator: CONTAINS
      size: 60
      placeholder: ''
    third_party_settings:
      conditional_fields:
        f75bfafe-e565-413b-a0c3-5bbca4d7bdf5:
          dependee: field_list_text
          settings:
            state: visible
            condition: value
            grouping: AND
            values_set: 1
            value: ''
            values: {  }
            value_form:
              -
                value: test1
            effect: show
            effect_options: {  }
            selector: ''
          entity_type: node
          bundle: page
    type: entity_reference_autocomplete
    region: content
  field_list_text:
    weight: 122
    settings: {  }
    third_party_settings: {  }
    type: options_select
    region: content
  path:
    type: path
    weight: 30
    region: content
    settings: {  }
    third_party_settings: {  }
  promote:
    type: boolean_checkbox
    settings:
      display_label: true
    weight: 15
    region: content
    third_party_settings: {  }
  status:
    type: boolean_checkbox
    settings:
      display_label: true
    weight: 120
    region: content
    third_party_settings: {  }
  sticky:
    type: boolean_checkbox
    settings:
      display_label: true
    weight: 16
    region: content
    third_party_settings: {  }
  title:
    type: string_textfield
    weight: -5
    region: content
    settings:
      size: 60
      placeholder: ''
    third_party_settings: {  }
  uid:
    type: entity_reference_autocomplete
    weight: 5
    region: content
    settings:
      match_operator: CONTAINS
      size: 60
      placeholder: ''
    third_party_settings: {  }
hidden: {  }
vacho’s picture

StatusFileSize
new50.7 KB

The current shema configuration file at conditional_fields/config/schema/conditional_fields.schema.yml at line 50 fails with a field that depends on another widget. For this case widget is a boolean selector.

value_form:
      type: sequence
      label: 'Values from widget'
      sequence:
        # Since it sub-config of field.widget.third_party, get there.
        type: field.value.[%parent.%parent.%parent.%parent.%parent.%parent.type]
        label: 'Value from widget'

Error message

ilya.no’s picture

Another issue I faced is about conditional_fields.{uuid}.settings.values field, called 'Set of values'.
When we add values to this field and save form, this setting is saved as string, which is logical, since type of field is text area, but in schema this field is of type 'sequence', which causes errors during configuration inspection.
I can see 2 options here:
1) Update schema to have string type for 'values' field.
2) Update code for managing this field and either explode text area value to have array of strings or make 'Set of values' field to be multiple text fields with ability to add/remove lines.

andypost’s picture

colan’s picture

From #3134183-2: Functional JavaScript tests are failing:

    value_form:
      type: sequence
      label: 'Values from widget'
      sequence:
        # Since it sub-config of field.widget.third_party, get there.
        type: field.value.[%parent.%parent.%parent.%parent.%parent.%parent.type]
        label: 'Value from widget'

The type refers to the widget type, not the field type. The widget type doesn't hold the schema of the field properties. We need the field type for that. Possibly this used to work, but stopped working after this patch was committed: #2370305-60: Refactor field type configuration schemas for DX, easier to find errors.

The actual field type is actually nowhere available in the configuration tree, and needs to be added to the conditional fields configuration.

brolad’s picture

Status: Active » Needs review
StatusFileSize
new711 bytes
mparker17’s picture

Issue summary: View changes
StatusFileSize
new1.27 KB
new939 bytes

The patch in #9 didn't work for me, even on a core boolean field type. Since the contents of that part of the configuration is already controlled by whatever module provides the field, and we can't really guarantee that the configuration schema definition will be named what we expect, or in the place that we expect, or even valid, I propose we make value_form use type: ignore to explicitly say "no data typing is possible", i.e.: "configuration schema validity is the module that provides the field's problem".

Here's a patch that does that.

mparker17’s picture

Title: Fix config schema » Fix config schema for value_form component

Clarify issue title with a scope, i.e.: to partially distinguish from #3137764: Store field_type; fix regex, effect_options in conditional_fields.settings (which admittedly could benefit from an issue title update too)

mparker17’s picture

Issue summary: View changes

Provided an example error message for the benefit of people who find this issue via a search engine.

mparker17’s picture

Added a test. It looks as if automated tests had been disabled for this project (if so, they would have been disabled for unrelated errors), so I have no idea if this will pass or fail. Likely, a fail would be unrelated to this issue.

colan’s picture

@mparker17: Testing should be up & running. There were a couple of issues in the #2830988: [meta] 4.0.0 release roadmap which should now be fixed. Holler if there's anything missing.

mparker17’s picture

Tests pass \o/

Ready for review!

super_romeo’s picture

After patch #10 applied warning about missing scheme is disappeared.
Thank you @mparker17!

dpacassi’s picture

Can confirm that #10 works, even on the latest 4.0.0-alpha1 release.
Thanks people!

dpacassi’s picture

Status: Needs review » Reviewed & tested by the community
heddn’s picture

Closing #3245121: Variable type is string but applied schema class is Drupal\Core\Config\Schema\Sequence as duplicate. And RTBC++. I also have CI-based test coverage of my configuration and the patch here solves the problem.

  • colan committed 776771d on 4.x authored by mparker17
    Issue #2948786 by mparker17, Brolad, vacho: Fix config schema for...
colan’s picture

Version: 8.x-1.x-dev » 4.x-dev
Status: Reviewed & tested by the community » Fixed

Thanks all!

Status: Fixed » Closed (fixed)

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

baddysonja’s picture

baddysonja’s picture

It would be great if @Grimreap could be credited on this issue for his work. Always good to appreciate the issue creation and initial work. @colan do you agree?

colan’s picture

Added, but I'm not sure it'll kick in after the issue is closed/fixed. Next time, please let me know before that happens.

grimreaper’s picture

Hi,

Sorry for the reply delay and sorry that after comment 4, I didn't have more time to help on this issue.

First thanks to have merged and to have it fixed!

I'm not sure it'll kick in after the issue is closed/fixed.

It will, and it has :). Yep, as a maintainer you have the options in the "credit & committing" fieldset and it is the last comment of a maintainer that takes precedence to give credits.

What I realized is that this fieldset default credit values is mainly based on patches uploaded. I know that it creates an additional step, but what I do on my projects before commiting, is to review the comments to have proper credit attribution because some comments may be useful even without code contribution. And in case of doubt I prefer to give credit.

Best regards,