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.

Files: 
CommentFileSizeAuthor
#8 metatag-parent_overrides-2044621-8.patch6.48 KBmrjmd
FAILED: [[SimpleTest]]: [MySQL] 100 pass(es), 1 fail(s), and 0 exception(s).
[ View ]
#4 metatag-parent_overrides-2044621-4.patch6.47 KBrooby
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch metatag-parent_overrides-2044621-4.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

DamienMcKenna’s picture

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.

rooby’s picture

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.

rooby’s picture

Status:Active» Needs review
StatusFileSize
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?

rooby’s picture

Issue summary:View changes

Adding extra info.

rooby’s picture

Issue summary:View changes
StatusFileSize
new6.47 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch metatag-parent_overrides-2044621-4.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

This version applies to latest dev and fixes a couple of warning messages that were coming from the code in the old version.

Status:Needs review» Needs work

The last submitted patch, 4: metatag-parent_overrides-2044621-4.patch, failed testing.

jeffdiecks’s picture

Issue tags:+Needs reroll
mrjmd’s picture

Status:Needs work» Needs review
Issue tags:-Needs reroll+SprintWeekend2015
StatusFileSize
new6.48 KB
FAILED: [[SimpleTest]]: [MySQL] 100 pass(es), 1 fail(s), and 0 exception(s).
[ View ]

Reroll attached.

Status:Needs review» Needs work

The last submitted patch, 8: metatag-parent_overrides-2044621-8.patch, failed testing.