Hide attributes details if none are enabled.

Issue information

From user: himerus

Related to !12

Contribution record

Fork management

Problem/Motivation

Empty attributes

I'm using this module specifically for two custom attributes that get preprocessed and passed as attributes on a web component. Not using any of the default attributes.

They are all set to default by default, and are intended only for custom link fields attached to nodes/blocks/etc.
However, I now have an empty attributes details item on default menu links as pictured in the attached screenshot.

Steps to reproduce

<?php
$fields
['link']->setDisplayOptions('form', [
     
'type' => 'link_attributes',
     
'weight' => -2,
     
'settings' => [
       
'enabled_attributes' => [
         
'id' => FALSE,
         
'name' => FALSE,
         
'target' => FALSE,
         
'rel' => FALSE,
         
'class' => FALSE,
         
'accesskey' => FALSE,
         
// Add your own custom attributes as required.
         
'data-variant' => FALSE,
         
'data-arrow' => FALSE,
        ],
      ],
    ]);
?>

Proposed resolution

<?php
  $element
['options']['attributes'] = [
     
'#type' => 'details',
     
'#title' => $this->t('Attributes'),
     
'#tree' => TRUE,
     
'#open' => count($attributes),
    ];
?>

in LinkWithAttributesWidget.php should be hidden entirely if there aren't any available attributes to be configured for a link.

Edited by drupalbot
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information