Views has functionality to rewrite the display of a field, optionally output as a link. It looks as though either a) custom link output handling is broken or b) custom link output does not properly handle core link fields.

Expected Behavior: link outputs as http://www.externallink.com

Steps to reproduce and behaviors observed:

  • Create view that shows entity title and a core link field
  • Configure link field to show URL only, default link formatter.
  • Rewrite output of title, configure to display {{ title }} token
  • Enable "Output this field as a custom link" and set value as {{ field_news_link }}
    Result: field outputs link as http://site.com/http://www.externallink.com
  • Enable "use absolute path" option - no change
  • Enable "external URL" option - outputs link as http://{{ field_news_link }} (hover for link shows url as http://site.com/admin/structure/views/nojs/handler/view_name/view_displa...
  • Change "output this field as a custom link" value to {{ field_news_link-uri }} - outputs link as http://1

Comments

tannerjfco created an issue. See original summary.

hampercm’s picture

hampercm’s picture

One of the problems listed above is reported in #2488540: Rewrite external links in views fields

webchick’s picture

Priority: Normal » Major

Broken sounds at least major.

webchick’s picture

Issue tags: +VDC

Also, tagging for the Views team.

lendude’s picture

Would like to close this as a duplicate of #2488540: Rewrite external links in views fields, since that has a patch that solves the issues here, except one.

Change "output this field as a custom link" value to {{ field_news_link-uri }} - outputs link as http://1

{{ field_news_link-uri }} is not in my valid replacements list when I use a link field, am I missing a step to make that a valid replacement? Or has it been removed?
I get a notice when I use that token:
Notice: Object of class Drupal\Core\Render\SafeString could not be converted to int

Haven't looked into Views handling of invalid tokens but that seems like a different issue to me.

tannerjfco’s picture

Perhaps it is dependent on which options you have set for the field? In this case I the "URL only" option checked on the field in the view. These are the replacement options for the link field that I see:

{{ field_link }} == News Link
{{ field_link__uri }} == Raw uri
{{ field_link__title }} == Raw title
{{ field_link__options }} == Raw options

lendude’s picture

@tannerjfco ah thanks! It's one of the tokens that is only available when you rewrite the actual link field. I was rewriting a different field to use the link field.

Manually tested it, and the patch in #2488540: Rewrite external links in views fields should fix that too.

lendude’s picture

Status: Active » Closed (duplicate)

Looking at the specific link tokens lead to #2567339: PHP Warning when using link field tokens in a view.

Closing this one as duplicate of #2488540: Rewrite external links in views fields, if you feel specific cases need to be tested, please add them there.