Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is it possible in this module to implement a solution for the following problem:
https://www.drupal.org/node/2625300
I think it will be important for many.
Comment | File | Size | Author |
---|---|---|---|
#62 | metatag-unset-2735195.patch | 10.29 KB | codepress |
#59 | metatag-unset-2735195-59.patch | 10.45 KB | piotrkonefal |
#55 | metatag-unset-2735195-55.patch | 10.89 KB | joelstein |
#42 | interdiff_38-42.txt | 1.53 KB | sonnykt |
#39 | metatag-unset-2735195-38.patch | 8.57 KB | hugovk |
|
Comments
Comment #2
DamienMcKennaThis was fixed in core in #2406533: edit-form, delete-form etc. <link> tags added on /node/{node} are invalid according to W3C Validator.
Comment #3
fomenkoandrey CreditAttribution: fomenkoandrey commenteddrupal 8.1.8 - not fixed.
Comment #4
DamienMcKenna@fomenkoandrey: Yes, because the last release of Drupal 8 was on August 4th but the fix only went in on August 18th. The fix will be in the next core release.
Comment #5
fomenkoandrey CreditAttribution: fomenkoandrey commented8.1.9 - not fixed
Comment #6
DamienMcKennaHere are the meta tags that 8.2.x currently output:
Lets add an option to forcibly remove the link tags.
Comment #7
fomenkoandrey CreditAttribution: fomenkoandrey commentedI understand right: modification in the core to wait only 8.2 branch?
on the main site I have not yet removed the extension Unset HTML head link.
I do not understand what and where I need to add an option?
I think, it is better to wait a core update.
Comment #8
DamienMcKennaThe core change removed some of the additional meta tags that pointed at admin-only paths, the remaining ones are not bad, but obviously people want to have control over them.
Comment #9
fomenkoandrey CreditAttribution: fomenkoandrey commentedtoday updated to 8.2 and still have all discussed metatags
Comment #10
DamienMcKennaYes, because we haven't added anything to remove the extra meta tags. Yet.
Comment #11
fomenkoandrey CreditAttribution: fomenkoandrey commentedthank U, will wait update then.
Comment #12
fomenkoandrey CreditAttribution: fomenkoandrey commentedDamienMcKenna, these changes were not added in the last update?
Comment #13
DamienMcKennaNo patches have been uploaded by others, and s far I've focused on other tasks, so no, it hasn't been done yet. When someone works on a patch to make this change you'll find out because it'll be uploaded here and you're subscribed to notifications for this issue.
Comment #14
DamienMcKennaMarking this "postponed" as I won't be looking at it until after 1.0.
Comment #15
DamienMcKenna8.x-1.0 is out, so this is fair game again.
Comment #16
thejimbirch CreditAttribution: thejimbirch commentedRan into this again today and did some digging. It looks like these tags are set in Drupal 8 core's system.module
I'm not sure you how you would add an option to Metatag to remove, but looks like there is a custom module idea to remove them.
https://github.com/koddr/drupal_8_unset_html_head_link
From discussion at:
https://www.drupal.org/node/2625300
Comment #17
thejimbirch CreditAttribution: thejimbirch commentedIn comment #6 DamienMcKenna added in the meta tags that core is adding, not just the links, so I updated the title.
I found a test in core that had a nice hook that can be used in a custom module to remove the metatags.
Comment #18
thejimbirch CreditAttribution: thejimbirch commentedI made a custom module that removes these Metatags which can be used until this functionality can be built into the main Metatag module.
https://github.com/xenomedia/metatag_remove
This does not solve the issue as this module just completely removes them, does not provide options for removing them individually in the admin interface.
Comment #19
DarkstarTom CreditAttribution: DarkstarTom commentedThe module in #18 correctly removes the meta tags from the header but how do you remove the link tags such as:
Thanks!
Comment #20
thejimbirch CreditAttribution: thejimbirch commented@DarkstarTom I posted a bit about this at the end of the post in #16
I believe this module does that:
https://github.com/koddr/drupal_8_unset_html_head_link
And the issue that you already found:
https://www.drupal.org/node/2625300
Comment #21
DarkstarTom CreditAttribution: DarkstarTom commented@thejimbirch thanks, the drupal_8_unset_html_head_link module does work for content but I am trying to use it on a profile page created with the profile module and it isn't removing the link. I would love to have this feature in Metatag.
Comment #22
WalkingDexter CreditAttribution: WalkingDexter at Initlab commentedI created a patch to fix problem from this issue. Patch adds metatag_unset sub-module, that allows to remove meta tags by "rel" (
<link rel="value">
) and "name" (<meta name="value">
) attributes. Part of the code was taken from the https://github.com/koddr/drupal_8_unset_html_head_link.How to use metatag_unset module:
Please test this patch.
Comment #23
WalkingDexter CreditAttribution: WalkingDexter at Initlab commentedComment #24
DamienMcKennaThis needs to be part of the main module vs a submodule.
Comment #25
WalkingDexter CreditAttribution: WalkingDexter at Initlab commentedMade a patch, where Unset metatags functional is part of the main module.
Comment #27
WalkingDexter CreditAttribution: WalkingDexter at Initlab commentedFix ConfigSchemaChecker errors.
Comment #28
WidgetsBurritos CreditAttribution: WidgetsBurritos at Rackspace commentedI've tested the patch in #27. The functionality definitely works, but I have some feedback about the overall strategy and some minor nitpicks.
Does it make sense for this to live at global level, or should it be available per configuration group? There may be reasons for these tags to exist in certain contexts.
Should this be a little bit more restrictive and only remove "rel" from
<link>
tags like its doing with the meta name tags? Not that anyone should have any<a>
or<area>
tags in their head, but merely from the perspective of being precise I think it makes sense.This should probably say "link tags" instead of "meta tags" to avoid confusion.
What is the intention for removing this here? I'm not seeing its relevance.
If we go this route, I'd imagine we'd want to use
PHP_EOL
instead of\n
in these instances.Comment #29
WidgetsBurritos CreditAttribution: WidgetsBurritos at Rackspace commentedDisregard comment #28.2 above. I just realized that the "html_head_link" key, is what determines it's a link tag.
Comment #30
WalkingDexter CreditAttribution: WalkingDexter at Initlab commentedHi WidgetsBurritos!
Below are the answers to your remarks:
1. For the moment, I see no reason to divide the metatag.unset configuration by the context. The current configuration, which is presented in the patch, is aimed at solving a problem that is global in nature. I don't exclude that in the future, it may be necessary to divide metatag.unset configuration per group, but, I repeat, at the moment I see no reason to do it.
3. I don't think that it's a good idea to say "link tags", because this issue also tells about removing tags with the names Generator, MobileOptimized, HandheldFriendly, viewport, which are meta tags.
4. The metatag_views.links.task.yml file is written incorrectly, since it defines the base local task - metatag_views.defaults. Because of this, the metatag.tab_unset tab will not work if the metatag_views module is disabled. The definition of the local task should be in the metatag.links.task.yml file.
5. I agree on this point, made the changes in the patch below.
Comment #31
DamienMcKennaThis is really great work, thank you.
A small request: instead of having one settings page for the "unset" options, could it be slightly refactored to be a general settings page for the module with a section focused on the unset options? Thanks.
Comment #32
WalkingDexter CreditAttribution: WalkingDexter at Initlab commentedYep, it can be done! Added a new patch.
Comment #33
DamienMcKennaThanks @WalkingDexter, I really appreciate your work on this.
That said, I think this should be able to automatically handle core's meta tags without any additional effort for the site builder - it should just work. I'm still wondering how best to handle this.
Comment #34
Phonoman CreditAttribution: Phonoman commentedHey, I was trying to use this (#30 & #32) patch with composer, but it couldn't be applied (dev-1.x/1.5)?
Perhaps some of the files used here have been changed thus rendering the patch unusable?
Comment #35
joelstein CreditAttribution: joelstein at On Fire Media commentedHere's a patch which applies cleanly against 8.x-1.5 and 8.x-1.x-dev.
Comment #36
phjouOk I've rerolled the patch.
There are some changes on the dev branch that have broken the patch. In particular this issue: https://www.drupal.org/project/metatag/issues/2956199 so I've deleted the changes made in /metatag_views/metatag_views.links.task.yml
Comment #37
wroxbox CreditAttribution: wroxbox for Yle - Finnish Broadcasting Company commentedRerolling the patch against 1.7/head
Comment #39
hugovk CreditAttribution: hugovk at Digia for Yle - Finnish Broadcasting Company commentedRerolled the patch against 1.8/head.
Comment #40
sonnyktPatch #39 does not unset the
rel="revision"
from node pages. Those rel links are set at the end of NodeViewController:view(), not from entity_view() nor hook_page_attachments(). I added an event subscriber listening to the KernelEvents::VIEW to unset those links from the controller result.Comment #41
sonnyktFixed #40 with correct weighting.
Comment #42
sonnyktSorry but just found that patch #40 and #41 introduce an incorrect config file metatag.unset.yml in the root dir. Fixed in patch #42.
Comment #43
govind.maloo CreditAttribution: govind.maloo at Salsa Digital commented@sonnykt for patch
Patch is working fine and resolved the issue.
Also successfully tested and deployed on https://github.com/govCMS/govCMS8
Comment #44
DamienMcKennaGoing back to my request from earlier:
I think the best way forward would be to extend _metatag_remove_duplicate_entity_tags() to compare known meta tags from core and Metatag and delete the core ones - the list is small, so this should be doable.
Comment #45
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedRe-roll of the patch for Metatag 1.11 version (credits to original authors of the patch). Not changing the status because this is just a re-roll and does NOT take DamienMcKenna's request in #44 into account.
Comment #46
fy1128 CreditAttribution: fy1128 commentedgot an error with restful request after metatag-unset-2735195-45.patch applied.
Comment #47
DamienMcKennaThis is the kind of thing I was thinking of.
One thing I noticed is that in when the event subscriber runs the $build['#attached']['html_head'] values aren't defined, so I'm not sure where to remove those.
Comment #48
DamienMcKennaI accidentally left in a kint() call in #47.
Comment #50
DamienMcKennaCore's "Generator" HTTP value comes form Drupal\Core\EventSubscriber\ResponseGeneratorSubscriber, while the meta tags are added in system_page_attachments().. so maybe an EventSubscriber isn't the best approach..
Comment #51
DamienMcKennaHow about disabling system_page_attachments() entirely? :)
Comment #52
DamienMcKenna#52 has unintended consequences and most of the theme doesn't load :-\
Comment #54
hugovk CreditAttribution: hugovk at Digia for Yle - Finnish Broadcasting Company commentedA reroll of #45 is needed for latest metatag 8.x-1.13.
Comment #55
joelstein CreditAttribution: joelstein commentedHere's an updated patch from #45 that applies cleanly.
Comment #56
DamienMcKennaThanks Joel. Seems like you accidentally included some unwanted files, though.
Comment #57
Muath Khraisat CreditAttribution: Muath Khraisat as a volunteer commentedThis way will unset the links from both the HTML and the HTTP headers.
Is there a way to unset them from one method only and keep them via the other?
Comment #58
JulienVey CreditAttribution: JulienVey commentedIs it still ocurring in the latest version of the metatag module : 1.16.0 ? Do we still need this patch ?
Comment #59
piotrkonefal CreditAttribution: piotrkonefal commentedHere is a rerolled version for the latest 8.x-1.16.
Comment #60
JulienVey CreditAttribution: JulienVey commentedMuch appreciated man.
Comment #61
DamienMcKennaThis problem has been resolved in core: https://www.drupal.org/node/3216941
Comment #62
codepress CreditAttribution: codepress commentedIf you are still on 9.2.x, patch against 1.19 is attached.
Comment #63
wsantell CreditAttribution: wsantell commentedI am on 9.3.12 and I notice that these tags are still present:
MobileOptimized, HandheldFriendly, viewport
Generator is also present, and can't be overridden or unset - if you set "generator" in the metatag settings, it will add a separate link, so you will have 2 entries like this:
Reviewing the resolution in #61, they only removed the delete-form, delete-multiple-form, edit-form, version-history, and revision links. It did say shortlink was still included by default, but no shortlink is added when using metatag and this isn't set.
Applying the patch in #62 does resolve this once configured.
Comment #64
jedihe CreditAttribution: jedihe at Council on Foreign Relations commentedI'm seeing the same bug as #63, even with the current 1.x-dev version (e807dc86cf8fb87fd8c302161dcf89b1f2f6fea7). I suggest to re-open this ticket or create a new one to handle cases like 'Generator', etc.
In the meantime, the hook_page_attachments_alter() approach from #62 works for me (I ported only the unset-by-name part into a custom module in my current project).