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: link

And 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: link

And 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: string

User interface changes

None

API changes

None

Data model changes

What are the consequences if we add the attributes property ?

Comments

flocondetoile created an issue. See original summary.

flocondetoile’s picture

Status: Active » Needs review
StatusFileSize
new1.18 KB

This patch add a test to fill some default value. It will fail.

flocondetoile’s picture

Issue summary: View changes
flocondetoile’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: 2823679-2.patch, failed testing.

flocondetoile’s picture

Status: Needs work » Needs review
StatusFileSize
new1.47 KB

The patch with the fix for uri

Status: Needs review » Needs work

The last submitted patch, 6: 2823679-6.patch, failed testing.

flocondetoile’s picture

Status: Needs work » Needs review
StatusFileSize
new1.62 KB

Looks like the attributes array is added by the widget LinkWidget.php in the formElement method, and duplicate the $options['attributes'].

// Exposing the attributes array in the widget is left for alternate and more
    // advanced field widgets.
    $element['attributes'] = array(
      '#type' => 'value',
      '#tree' => TRUE,
      '#value' => !empty($items[$delta]->options['attributes']) ? $items[$delta]->options['attributes'] : array(),
      '#attributes' => array('class' => array('link-field-widget-attributes')),
    );

Status: Needs review » Needs work

The last submitted patch, 8: 2823679-8.patch, failed testing.

flocondetoile’s picture

Status: Needs work » Needs review

So, 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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

May 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.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sheanhoxie’s picture

StatusFileSize
new557 bytes

Removing missing test from 2823679-8.patch, for 8.5.x

Status: Needs review » Needs work

The last submitted patch, 15: 2823679-15.patch, failed testing. View results

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Status: Needs work » Closed (duplicate)

Closing 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.