Generally link fields with a disabled "title" property should be a single-property field with src attribute.
If "title" is present link should be output by default <a href="#the-url" slot="NAME">The link label</a>

Comments

pagach created an issue. See original summary.

pagach’s picture

Status: Active » Needs review
StatusFileSize
new2.74 KB

Added patch with default link processor.

pagach’s picture

There is a wrong comment there. Will fix when committing.

fago’s picture

Status: Needs review » Needs work

+ $element->setSlot('default', $link_item->get('title')->getValue(), 'span');

Weird that it uses $link_item->get('title')->getValue() and not the usual shortcut $link_item->title !?

+ if (!empty($link_item->get('title')->getValue())) {
+ $element->setTagPrefix('');
+ $element->setTag('a');
+ $element->setSlot('default', $link_item->get('title')->getValue(), 'span');
+ $element->setAttribute('href', $link_item->getUrl()->toString());
+ }
+ else {
+ $element->setAttribute('src', $link_item->getUrl()->toString());
+ }

This will output a different structure if the user decides the leave the title empty, what is a nogo as it will break frontend code relying on the structure. The check must look at teh configuration whether a title input is allowed and if it's allowed it must always output a full element.

pagach’s picture

Status: Needs work » Needs review
StatusFileSize
new2.76 KB

Switched to short syntax.
Changing structure only when link title is disable.

pagach’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.