Starting this as a support request.

If I have a global OG image tag outputting a default site image and then for my content types I have a more specific tag that uses the image in an image field.

If that image field has no image in it I get no OG image tag.

I think it would be useful in this case for the global image to override the empty value.

Now I understand maybe not everyone wants this behaviour but maybe it could be optional as I think a lot of people would want it for things like this image tag.

For a start, is this behaviour currently possible? It seems like it is not.

#3 metatag-parent_overrides-2044621-3.patch6.47 KBrooby
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]


Version:7.x-1.0-beta7» 7.x-1.x-dev
Category:support» feature

This is one of the difficulties of using Token - the logic checks to see if fields are empty before applying the token rather than after. This is something I need to look into.

Thinking out load a little here.

At a quick look it seems like one problem is the metatag_config_load_with_defaults() function, which does a union of the config arrays, starting with the most specific and ending with the global.

This union means that you are basically going to get the entirety of the most specific config all the time because the config array is almost the same between instances. Values left empty in the more specific instance will override a non-empty value in the global one.

On top of that, what metatag_config_load_with_defaults() returns is a single array of raw values so if those values end up empty after token replacement you don't have the parent value available to use.

Seeing as the metadata config is cached, it could be feasible to load the parent configs into the cache as well as just the specific instance config and then use them after token replacement as required.

Either that or metatag_config_load_with_defaults() could return an array of config arrays, from specific to global, instead of just the most specific.

Then maybe before hook_metatag_metatags_view_alter() is invoked in metatag_metatags_view() there could be a check for empty values where it falls back to the parent and tries getElement() again.

Seems it might sometimes be desirable to have empty values though and not fall back to the parent. In which case maybe the global fields should be left empty? or else the alternative is to have a setting for each metatag to specify whether or not the parent can override an empty value.

Status:Active» Needs review
new6.47 KB
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]

Here is a proof of concept that adds the ability to make each individual metatag allow overrides at the instance level.

If a metatag is set to allow overrides and is left empty or token replacements render it empty, then it will check the parent instance for a metatag.

If the parent is also empty and also allows overrides the process continues.

It could probably do with a bit of refactoring and it doesn't take into acount the fact that the allow override setting is useless on the global instance, but it shows a possible solution.

What do you think?

Issue summary:View changes

Adding extra info.