Problem/Motivation
Since #2411143: Change LinkItem schema to store URIs rather than URLs/paths/routes has been committed, the link.schema.yml need to be updated to match the new schema (property uri instead of url). Tests which try to set some default values generate a PHP fatal error.
This error occurs with the the uri property, but also for the attributes property for contrib module which add some attributes in the form element with a new widget.
If we export the configuration of a field link, we saw that the attributes property (defined under the options property) is duplicated directly at the "root configuration".
Example for field.field.node.article.field_link.yml
uuid: 03b5aa35-9594-41b3-a52d-40c8c1278fcc
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_link
- node.type.article
module:
- link
id: node.article.field_link
field_name: field_link
entity_type: node
bundle: article
label: Link
description: ''
required: false
translatable: false
default_value:
-
attributes: { }
uri: 'internal:/contact'
title: Contact
options: { }
default_value_callback: ''
settings:
link_type: 17
title: 1
field_type: linkAnd the exported configuration of a field link with attributes on form element (used with link_class module)
uuid: 126a3187-6fca-4ef8-886b-44004ca835d8
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_link
- node.type.article
module:
- link
id: node.article.field_link
field_name: field_link
entity_type: node
bundle: article
label: Link
description: ''
required: false
translatable: false
default_value:
-
attributes:
class: button
uri: 'internal:/contact'
options:
attributes:
class: button
title: 'Nous contacter'
default_value_callback: ''
settings:
link_type: 17
title: 2
field_type: linkAnd so contrib modules get a fatal error if they try to fill default values for an attribute. You can see the fatal error for uri and attributes properties here https://www.drupal.org/node/2823552#comment-11756280
Proposed resolution
Change the property url to uri for field.value.link in the link.schema.yml. Add the attributes property under in field.value.link
Remaining tasks
Review patch for uri/url issue.
Discuss what to do about the attributes property ? Do we need to add it the the link.schema.yml as below
field.value.link:
type: mapping
label: 'Default value'
mapping:
title:
type: label
label: 'Link text'
url:
type: string
label: 'URL'
attributes:
type: sequence
label: 'Link attributes'
sequence:
type: string
options:
type: mapping
label: 'Link options'
mapping:
query:
type: sequence
label: 'URL query key value pairs'
sequence:
type: string
fragment:
type: string
label: 'URL fragment'
absolute:
type: boolean
label: 'Is this URL absolute'
https:
type: boolean
label: 'If the URL should use a secure protocol'
attributes:
type: sequence
label: 'Link attributes'
sequence:
type: stringUser interface changes
None
API changes
None
Data model changes
What are the consequences if we add the attributes property ?
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 2823679-15.patch | 557 bytes | sheanhoxie |
| #8 | 2823679-8.patch | 1.62 KB | flocondetoile |
| #6 | 2823679-6.patch | 1.47 KB | flocondetoile |
| #2 | 2823679-2.patch | 1.18 KB | flocondetoile |
Comments
Comment #2
flocondetoileThis patch add a test to fill some default value. It will fail.
Comment #3
flocondetoileComment #4
flocondetoileComment #6
flocondetoileThe patch with the fix for uri
Comment #8
flocondetoileLooks like the attributes array is added by the widget LinkWidget.php in the formElement method, and duplicate the $options['attributes'].
Comment #10
flocondetoileSo, the fatal error due to "default_value.0.attributes missing schema" is now gone.
All other test failures are because they use the property url instead of uri.
Waiting feedback before move on on this.
Comment #12
joelpittetMay be worth moving the attributes to a separate follow-up issue so it doesn't hold this one up.
Making the uri the schema match though does seem reasonable.
Comment #15
sheanhoxieRemoving missing test from 2823679-8.patch, for 8.5.x
Comment #19
alexpottClosing in favour of #3067609: Fix config schema for links and migration of link default values - that issue comes at this problem from a slightly different angle. I've credited the contributors to this issue on that one.