backdrop-contrib / metatag

Add structured metadata, aka "meta tags", for various pages on your site.
GNU General Public License v2.0
3 stars 15 forks source link

Cannot remove default Open Graph metatag values #18

Open ghost opened 6 years ago

ghost commented 6 years ago

Describe your issue

You cannot remove default Open Graph metatag values.

Steps to reproduce

  1. Install Metatag and Metatag: OpenGraph modules
  2. Go to /admin/config/metadata/metatags and click Override next to Global
  3. Expand the Open Graph fieldset
  4. Note the 'Site name' metatag is currently set to '[site:name]'
  5. Delete the 'Site name' metatag value
  6. Scroll down and click Save
  7. Note Global has been overriden
  8. Click Configue next to Global
  9. Expand the Open Graph fieldset

Actual behavior

The 'Site name' metatag is still set to '[site:name]'

Expected behavior

The 'Site name' metatag should be empty/blank

Further details

I tested this with core metatags (e.g. 'Page title' under 'Basic Tags') and it works (you can remove default values). So the issue seems to be specific to the Open Graph metatags (haven't tested with other sub-modules).

ghost commented 6 years ago

So after some research, I think I've narrowed the issue down to this bit of code: https://github.com/backdrop-contrib/metatag/blob/1.x-1.x/metatag.module#L1313

From my testing, the $options array already has a defaults key, so by using the + array operator, the new defaults (metatag_config_load_with_defaults($instance)) are totally ignored.

I could be wrong, but hopefully this helps points someone in the right direction for a fix.

EDIT: Oh and the new defaults are needed when checking if a metatag is saved or not (metatags are ignored if they're empty and have no default - hence my issue: I removed the value (so it's empty), and the defaults aren't being pulled in properly so it thinks there isn't a default and it's ignored).

laryn commented 4 years ago

I was troubleshooting Metatag for someone on the forum: https://forum.backdropcms.org/forum/newbie-problem-metatag

And this issue looks very similar. I haven't figured out why the defaults for Open Graph keep being used but wanted to tie these issues together.

robertgarrigos commented 3 years ago

The same I reported here: https://github.com/backdrop-contrib/metatag/issues/51

robertgarrigos commented 3 years ago

Although I have to say that I cannot reproduce this problem with the latest version. I just changed a default value and it remains after saving.

quicksketch commented 1 year ago

Following the steps in the issue description, I can reproduce this problem in the current version still. Like @BWPanda suggests, this seems to have to do with a default value ([site:name]) being set, but when an empty-string is submitted, the empty string is not saved to config, then the default value gets used.

I think what needs to be done is that metatag_metatags_form_submit() needs to save empty values if they differ from the defaults. I found that manually modifying metatag.instance.global.json to have an empty string does suppress the og:site_name value entirely.

This does not seem to be specific to the Open Graph module, but rather any metatags that have defaults specified.