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:
- 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)
- we can't guarantee that the configuration schema definition for the field will be valid
Remaining tasks
Write a patch- Review and feedback
- RTBC and feedback
- Commit
User interface changes
None
API changes
None
Data model changes
None
Documentation links
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 2948786-10--fix-config-schema-for-value-form.patch | 1.27 KB | mparker17 |
Comments
Comment #2
grimreaperOk. 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.
Comment #3
OlgaRabodzei commentedHi, 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.
Comment #4
grimreaperHello 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:
Here is the entity form display:
Comment #5
vacho commentedThe 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.
Comment #6
ilya.no commentedAnother issue I faced is about
conditional_fields.{uuid}.settings.valuesfield, 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.
Comment #7
andypostIt looks more like sequence so could use same as contact form
- https://git.drupalcode.org/project/drupal/blob/8.8.x/core/modules/contac...
- https://git.drupalcode.org/project/drupal/blob/8.8.x/core/modules/contac...
Comment #8
colanFrom #3134183-2: Functional JavaScript tests are failing:
Comment #9
brolad commentedComment #10
mparker17The 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_formusetype: ignoreto 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.
Comment #11
mparker17Clarify 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)
Comment #12
mparker17Provided an example error message for the benefit of people who find this issue via a search engine.
Comment #13
mparker17Added 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.
Comment #14
colan@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.
Comment #15
mparker17Tests pass \o/
Ready for review!
Comment #16
super_romeo commentedAfter patch #10 applied warning about missing scheme is disappeared.
Thank you @mparker17!
Comment #17
dpacassiCan confirm that #10 works, even on the latest 4.0.0-alpha1 release.
Thanks people!
Comment #18
dpacassiComment #19
heddnClosing #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.
Comment #21
colanThanks all!
Comment #23
baddysonjaComment #24
baddysonjaIt 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?
Comment #25
colanAdded, but I'm not sure it'll kick in after the issue is closed/fixed. Next time, please let me know before that happens.
Comment #26
grimreaperHi,
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!
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,