Add Default menu_link_content attributes UI

Created on 5 April 2019, about 5 years ago
Updated 17 October 2023, 9 months ago

Issue Summary

Currently, only some attributes are exposed on the link field of the menu_link_content entity. Because, there is no entity_form_display config a site builder cannot edit the configuration of the link_attributes widget. The only way to expose more attributes (such as aria-label) is to add them in code via hook_entity_form_display_alter.

Proposed Resolution

To improve the usability by site builders we should add a configuration form that sets the default attributes in link_attributes_entity_base_field_info_alter.

/**
 * Implements hook_entity_base_field_info_alter().
 */
function link_attributes_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
  if ($entity_type->id() === 'menu_link_content') {
    $fields['link']->setDisplayOptions('form', [
      'type' => 'link_attributes',
      'weight' => -2,
      'settings' => [
        'enabled_attributes' => \Drupal::config('link_attributes.menu_link_content.default_attributes'),
      ]
    ]);
  }
}
✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States malcolm_p

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024