Problem/Motivation
In our site improper empty og:image tags were generated. It was, because we used a definition for the og:image field where multiple values were allowed. If all of the fields have value, everything is ok. The MetatagManager.php replaces the given tokens and creates a proper temporary value which will be processed well. But if any of them is missing, the result will not be proper, the html source will also contain empty "og:image" meta tags.
Steps to reproduce
Set the following metatag to Open Graph, image:
[node:field_image:max_1300x1300], [node:field_images:max_1300x1300], [node:field_logo:max_1300x1300], [node:field_result_logo:max_1300x1300]
It will generate 3 og:image metas to the header of the content pages (unless you have such fields with content in them) with the base url of the site.
Proposed resolution
I have a kind of solution patching the MetatagManager.php where the empty values are removed. However some might create a more elaborate solution.
Related issues
This bug has been already reported by me here: https://www.drupal.org/project/metatag/issues/3182954
The status of that ticket is "Closed (won't fix)" + I was requested to create a new issue if the modifications in #3067803 won't fix this one. So here it is, I think #3067803 did not addressed this bug or has not been included in the code for more than a year.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3378434-5.patch | 628 bytes | abhinand gokhala k |
| #4 | 3378434-4.patch | 630 bytes | heykarthikwithu |
| metatag_module_bugfix_patch_has_been_added_for_v_2_0_0.patch | 1014 bytes | zolt_toth |
Issue fork metatag-3378434
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
damienmckennaThank you for reporting this bug, and I see that the work on multi-value tag output didn't resolve it.
Let's see what the testbot says about the patch.
Comment #3
damienmckennaThe patch uses the wrong paths, so it needs to be corrected.
Comment #4
heykarthikwithuOnly rewriting the patch with correct patch (should see will it on work on multi-value tag output)
Comment #5
abhinand gokhala k commentedComment #6
damienmckennaComment #8
xamountThe patch at #5 fixes the issue for me. Thanks!
Comment #11
xamountComment #12
naveenvalechaAdded related issue
Comment #13
damienmckennaThe change needs to accommodate "empty" values that are not blank, i.e. the number zero.
Comment #14
damienmckennaComment #15
naveenvalecha@damienmckenna How to reproduce with values number 0. Could you help with the steps to reproduce?
The above steps to reproduce steps are not generating values number 0
Comment #17
eleonelThe MR now strips empty/whitespace-only values from multi-value meta tags while keeping a literal 0 (per #13). Fix is in MetaNameBase::output(), gated on multiple(), so single-value tags are untouched.
Reverted the old array_filter() in MetatagManager (it dropped 0 and hard-coded the comma).
Added Kernel tests for empty removal, the zero case, and a custom separator. Also included two small pre-existing D11 test/CSS fixes so the pipeline runs.
Comment #18
radimklaskaTested MR !111 locally on a Drupal 11.3.10 site:
* empty values removed from multi-value tags, literal "0" preserved
* no regressions on the site
Works as expected.
The "merge error" on the MR is just the target branch: it still targets 2.0.x while 2.1.x was merged into it. Verified locally, it merges cleanly into 2.1.x.
Comment #19
skipper-vp commentedReviewed the MR locally against 2.1.x.
The GitLab diff looks large because the MR is still targeting 2.0.x, but when compared locally against 2.1.x the actual diff is limited to:
- metatag_extended_perms/tests/src/Functional/PermissionsTest.php
- src/Plugin/metatag/Tag/MetaNameBase.php
- tests/src/Kernel/MetatagManagerTest.php
The fix in MetaNameBase::output() looks correct to me. It skips empty/whitespace-only values only for multi-value tags, and uses a strict empty-string check so the literal value "0" is preserved.
The added kernel coverage also looks appropriate. It covers empty values, whitespace-only values, "0", custom separators, and a single-value tag containing the separator character.
Moving to RTBC.
Comment #20
skipper-vp commentedComment #21
damienmckennaComment #22
damienmckennaLet's get this into the next release.
Comment #24
damienmckennaCommitted. Thank you!