Problem/Motivation
Metatags uses inheritance to, for example, set global defaults > node defaults > node type values.
This is very flexible, helpful and also allows overriding inherited values with other strings or tokens.
But one thing you currently can't do (or it's not well documented in the UI) is to override an inherited value with NULL. This is for example a problem if "canonical" is set to [current-page:url:absolute] which means also on NOT FOUND (403) pages the canonical is being output, which is incorrect (at least SEO crawlers complain).
This concrete issue was also pointed out here: #3247275: Remove canonical for 404 and 403 pages
But also in other cases, you may want to REMOVE / UNSET an inherited value.
Steps to reproduce
See above.
Proposed resolution
Define a fixed (or configurable with default) value which is a placeholder for UNSET.
My suggestion would be to use <none> as Drupal uses this in other places. If it's important for anyone that the string "" can be a metatag value (and it's a rare case), we could make that value also editable. But I think it can be a constant.
Another alternative would be to use a checkbox, but that would bloat configuration and would also be less intuitive.
If a metatag has a <none> value, unset it when handling the metatag and do not output the metatag.
Document the behavior in the general description or metatag field description.
A further combined improvement would be to show the inherited value in the inherited metatags, see #2936826: Inherit parent metatags as placeholder in override forms. And / or only show the <none> documentation below in these cases.
Of course should always be allowed, even if there is no inherited value and in such case also behave like the field was left empty.
Remaining tasks
- Discuss
- Create MR with implementation & documentation
- Review & Test
- Release
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | metatag-n3272202-9.patch | 1.08 KB | damienmckenna |
Issue fork metatag-3272202
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
Comment #2
anybodyI'd be interested, what @DamienMcKenna thinks about this. Hopefully I didn't oversee an already existing issue or functionality for this. That would already have been helpful in Drupal 7 though :)
Comment #3
anybodyIndeed, I found some related or even duplicate issues, which manifests the requirement for such a solution.
Comment #4
damienmckennaFrom a usability perspective I'd prefer something in the UI, e.g. a checkbox that lets you control whether the value is overridden. Let's pick this up in #1798984.
Comment #5
anybodyComment #6
anybodyThank you super-fast Damien!
Comment #7
anybody@damienmckenna just came back here for the same needs. The question is, do you think it will be realistic to implement the full featured override solution within the next decade? :D (Not asking you do do so or something like that, this is really meant to read with a smile).
My thought is the following:
I think needing to clear a predefined default in an override is clearly an edge-case. Still it's an edge-case that can happen!
It already works for any kind of string, it's just not possible to unset a value at higher level, because clearing the value would bring back the defaults. And entering a space would (hopefully) just set a space for the metatag value.
So if we'd allow a special string like
<unset><empty><none>for technical users, we could quite simply extend the overriding to this remaining case.
And we could still convert that into checkboxes one day, if anyone solves it.
If you should change your opinion on this, our team would be happy to implement that, as we're running into this again and again.
Implementing the full-featured checkbox solution is great, but a big bunch of work and risky to never getting done.
This might be just "good enough" and fit things like Drupals magic "code> placehoder.
Comment #8
damienmckennaReopening this as a simpler solution that won't involve greatly expanding the DOM structure and JS logic on edit forms.
Comment #9
damienmckennaSo something like this might work, maybe?
Comment #10
anybodyHi Damien, thanks, I'll take a look asap, bookmarked this! Also asked @Grevil to take a look!
Comment #13
grevil commentedWorks great! Thanks for the fix @damien!
I basically copied the example by @anybody, and it works like a charm! The canonical url will get removed on 403 pages if we declare it as .
I'll add a test for this.
Comment #14
grevil commentedTo be honest, I don't quite get this request and how the inheritance works for metatags?
Based on the request, it sounds like, if we would set the metatag value of a child metatag to an empty string (e.g. setting the 403 canonical_url to ""), the metatag would use the parents value (global's canonical url). But this isn't the case.
Setting an empty string instead of already does the exact same thing. This is also represented in code and the currently failing tests.
And how does the whole inheritance work then?
I don't think it does.
Comment #15
grevil commentedIf we allowed to set an empty string, inherit the value from the parent and delete the metatag, @thomas.frobieter, and I suggest having the following changes:
<none>as value, to kill the metatag entirely.<empty>as value, to let the metatag have an empty string.Note, that the inherit / empty string functionality could also be implemented via checkbox.
Comment #16
anybodyThanks, I'll check that!
Comment #17
anybody@Grevil: Like just tested together I can not confirm this. Having an empty value leads to inheritance (as expected)!
Comment #18
grevil commentedAll done, please review.
Yea, this whole endeavour was caused, because programmatically setting a metatag value to an empty string will kill the metatag output entirely, resulting in the same behaviour as providing
<none>(which is the root cause of my confusion).Only if we set an empty string via UI, the submit call will silently override our empty string with its parent value. That is also, why the tests failed originally. This is REALLY confusing! ESPECIALLY if there is also an empy / isNull check on the ouput handler and no way to tell, that $this->value will silently get overriden on submit...
Comment #19
anybodySuper nice @grevil thank you! Works fine and as expected now. Please open a follow-up to reduce the confusion you described.
Next step (UX-wise) should be #2936826: Inherit parent metatags as placeholder in override forms
Comment #20
grevil commentedCreated the follow-up issue here: #3500307: Set metatag parent programmatically (inherited value).
Comment #21
damienmckennaComment #22
tostinni commentedWhat about values coming from
<select>?We have some in the Twitter card, but mostly in Schema.org Metatag module that use a lot of them.
Is there a way to automatically add
<none>to the<select>or this is due to this module ?Comment #23
damienmckennaComment #24
damienmckennatostinni: That's a great point - please add a separate issue to extend tags to provide the "none" option. Thank you.
Comment #28
damienmckennaCommitted. Thanks everyone, and Anybody ;-)
Comment #31
anybodyWHAO thank you so much @damienmckenna! This is great and super helpful! :)