Issue #3272202 introduced the possibility to fill a tag with <none> which prevents inheritance and clear the value.

It works well unless for the `canonical` and `shortlink` tags. The reason is that Drupal Core set these tags by default (see EntityViewController::view()).

In _metatag_remove_duplicate_entity_tags() invoked by metatag_entity_view_alter(), we unset the values set by the Core only if Metatags is overriding the values. <none> is translated to empty and not considered as a replacement. The default Drupal Core tags are displayed.

Expected output:
Canonical and shortlink tags are removed if set to <none>.

Fixing this bug would give a workaround to #3247275.

CommentFileSizeAuthor
#7 3631058 after.png44.48 KBcsakiistvan
#7 3631058 before.png111.65 KBcsakiistvan

Issue fork metatag-3631058

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

vbouchet created an issue. See original summary.

vbouchet’s picture

Issue summary: View changes
wkr1shna’s picture

Assigned: Unassigned » wkr1shna

wkr1shna’s picture

Status: Active » Needs review

I've addressed the CSpell and PHPCS issues reported by the initial CI run in the latest commit.

The change handles `` for canonical and shortlink tags independently, preserves the existing duplicate-removal behavior for normal overrides, and includes Kernel and Functional test coverage.

The Kernel test passed in the previous CI run. The latest pipeline is being checked for the follow-up changes.

Please review and let me know if any further changes are needed.

csakiistvan’s picture

Assigned: wkr1shna » csakiistvan
csakiistvan’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new111.65 KB
new44.48 KB

✅ Tested and works — with Canonical URL and Shortlink set to <none> in the Content defaults, a new article still output both <link rel="canonical"> and <link rel="shortlink"> on 2.2.x; after checking out MR !277 as-is (not rebased on current 2.2.x) and rebuilding caches, both tags are gone from the page source. <none> now removes the core-provided tags as the issue expects.

csakiistvan’s picture

Assigned: csakiistvan » Unassigned

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

damienmckenna’s picture

Assigned: Unassigned » damienmckenna

This is an unnecessary change:

-  return $metatag_manager->generateElements($metatags, $entity);
+  $elements = $metatag_manager->generateElements($metatags, $entity);
+  $elements['#metatags'] = $metatags;
+
+  return $elements;

I'm going to revert that part and see how it works.

damienmckenna’s picture

Assigned: damienmckenna » Unassigned

Correction - the change is needed to make it work.

damienmckenna’s picture

damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed, Thank you.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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