Problem/Motivation

LinkItem::getUrl doesn't respect any options it may hold.
This prevents us from being able to write an enhanced widget for setting attributes etc.
See https://www.drupal.org/project/link_attributes for one such widget.

Proposed resolution

Do so

Remaining tasks

Review

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan created an issue. See original summary.

larowlan’s picture

larowlan’s picture

Simple bug

jibran’s picture

+++ b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php
@@ -169,7 +169,11 @@ public static function mainPropertyName() {
+    $url = Url::fromUri($this->uri);

Why not just pass the options as 2nd param?

larowlan’s picture

The last submitted patch, 3: 2760557-link-options.fail_.patch, failed testing.

larowlan’s picture

larowlan’s picture

jibran’s picture

Version: 8.2.x-dev » 8.1.x-dev
Status: Needs review » Reviewed & tested by the community
Issue tags: -needs backport to 8.1.x

Nice and easy thanks @larowlan. For D8 it's forwardport policy.

dawehner’s picture

Just a shameless ad about some other issue :) #2656534: Provide a way to extract a menu plugin from a menu form

This looks perfect for me.

jibran’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 2760557-link-options.2.patch, failed testing.

jibran’s picture

Status: Needs work » Reviewed & tested by the community

Everything is green.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed f94a4c2e13a6d77d757a1d396268c0764725c093 to 8.2.x and 8a7eab2 to 8.1.x. Thanks!

  • alexpott committed f94a4c2 on 8.2.x
    Issue #2760557 by larowlan, jibran: LinkItem::getUrl ignores the value...

  • alexpott committed 8a7eab2 on 8.1.x
    Issue #2760557 by larowlan, jibran: LinkItem::getUrl ignores the value...

Status: Fixed » Closed (fixed)

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

Berdir’s picture

Interesting, this breaks an older D8 site that I have pretty badly. For some strange reason, I have N; (serialized NULL) in the options column for my shortcuts. passing NULL along results in a recoverable fatal error.

Looking a bit more, I can see that in at least 4 older D8 sites, some are empty arrays, some NULL. Expecting them all to choke on this.

Quick patch to prevent that, need one for composer, will open a new issue later.

Berdir’s picture

Berdir’s picture