Problem/Motivation

The formatters title field description says "Will be used as the link title unless one has been set on the field. Supports token replacement."

However, when a title is entered, the formatter still prints the title defined in the field formatter.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 firefox_jkh9nD4TeR.png38.99 KBthomas.frobieter

Issue fork micon-3537389

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

thomas.frobieter created an issue. See original summary.

thomas.frobieter’s picture

Title: Formatter "Link (with symbol)": Title override not working » Formatter "Link (with symbol)" [micon_link]: Title override not working
thomas.frobieter’s picture

StatusFileSize
new38.99 KB

Okay I got the cause, but this needs a backend programmer.

Check this: https://git.drupalcode.org/project/micon/-/blob/2.x/modules/micon_link/src/Plugin/Field/FieldFormatter/MiconLinkFormatter.php?ref_type=heads#L170

Inside the foreach I printed:

  kint($title);
  kint($item);
  kint($item->title);

Result:

So from my point of view it needs to be something like this:

if ($title && !empty($item['#title'])) {
  $item['#title'] = $this->token->replace($item['#title'], [$entity_type => $entity]);
} elseif ($title) {
  $item['#title'] = $this->token->replace($title, [$entity_type => $entity]);
}

EDIT: My fix is incorrect because if the link title override field has no value, $item['#title'] is not empty; it falls back on the URL instead.

anybody’s picture

Can't we just look up, how the other link (it) formatters solve it? This isn't a dedicated feature for us, right?
So we should simply use the same logic or am I missing something?

thomas.frobieter’s picture

micon_linkit and micon_linkit_attributes are form field widgets, not display formatters? So, as far as I can see, this is the only formatter with this logic (in this module).

lrwebks made their first commit to this issue’s fork.

lrwebks’s picture

Status: Active » Needs review

Works as expected now. The additional check with the URI is necessary, as the link module shows the link URI as the fallback link text when either nothing was entered in the entity form or the link text was disabled in the field settings.

anybody’s picture

Status: Needs review » Needs work
thomas.frobieter’s picture

Status: Needs work » Reviewed & tested by the community

Okay all done and tested.

anybody’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, merged!

  • anybody committed 3e689399 on 2.x authored by lrwebks
    Issue #3537389 by lrwebks, thomas.frobieter, anybody: Formatter "Link (...
fjgarlin’s picture

(Updating to resolve Drupal.org issue index issue, please disregard)

Status: Fixed » Closed (fixed)

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