Add Default menu_link_content attributes UI

Created on 5 April 2019, over 5 years ago
Updated 5 September 2024, 3 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 work

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

Merge Requests

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.71.5 2024