Linkit Field Formatter isn't attaching attributes on external URLs

Created on 1 August 2024, 3 months ago

Problem/motivation

Attributes are not being attached when an external URL is inputted, whereas attributes are attached as expected when using an internal URL.

Steps to Reproduce

  1. Install link_attributes, which includes the linkit_attributes submodule.
  2. Create a link field on a specified entity.
  3. Use the Linkit field widget (with attributes) and the default Linkit formatter.
  4. Create or update an entity with the newly created link field.
  5. Enter an external URL, such as https://google.com, and select some attributes, such as target="_blank."
  6. Check that the attributes are not being attached to the link field.

Proposed resolution

In the following method \Drupal\linkit\Plugin\Field\FieldFormatter\LinkitFormatter::viewElements, we call $url = $this->getSubstitutedUrl($link_item), which returns the URL based on the $link_item. We only continue to set various information to the object if a URL is returned. If this function returns NULL, nothing is set, which is where I believe the problem lies.

πŸ› Bug report
Status

Active

Version

6.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States droath

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024