Problem/Motivation

Currently, when a content editor editor is editing a node and purposefully removes a metatag field value for that node, the empty value does not get saved and does not override the configured default value.

Steps to reproduce

  1. Configure global metatag settings and enter a value for description (or any other field)
  2. Edit or create a node
  3. Open the Meta tags details and delete the contents in the Basic tags description.
  4. Save the node
  5. Note that the description metatag in the node page still shows the value from the global configuration

Proposed resolution

  1. In the massageFormValues() method of Drupal\metatag\Plugin\Field\FieldWidget\MetatagFireHose,, don't remove empty values for individual fields
  2. In the preSave() method of Drupal\metatag\Plugin\Field\FieldTypeMetatagFieldItem, update code so that the entity tag field value is removed from the serialized string when either a default value exists and doesn't match or the default value doesn't exist but the entity value is empty.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork metatag-3161116

Command icon 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

godotislate created an issue. See original summary.

godotislate’s picture

StatusFileSize
new1.4 KB
godotislate’s picture

StatusFileSize
new2.04 KB

Need to account for the default value widget.

neelam.chaudhary’s picture

Patch #3 worked for me.

damienmckenna’s picture

Status: Active » Needs review

Let's see what the testbot says.

The last submitted patch, 2: 316116-metatag-empty-override-2.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 3: 3161116-3.patch, failed testing. View results

godotislate’s picture

Status: Needs work » Needs review
batkor’s picture

Patch #3 worked for me.
Drupal version : 10.1.6
drupal/metatag: 1.26.0

marc.groth’s picture

Version: 8.x-1.x-dev » 2.1.x-dev
Status: Needs review » Reviewed & tested by the community

Not only does this work well, but it even works for the 2.1 branch without a need for re-patching. Great work @godotislate

sokru’s picture

We've had the patch #3 (same as MR) many years on production. So +1 for RTBC.
The MR base branch should be updated to 2.1.x but it requires the author's or module maintainers action.

damienmckenna’s picture

Version: 2.1.x-dev » 2.2.x-dev
Related issues: +#3272202: Add <none> placeholder to clear / unset inherited value

An alternative solution to this was committed in #3272202: Add <none> placeholder to clear / unset inherited value, whereby you can distinguish between the two requests of "I want to revert to the default for this one meta tag" and "I don't want this meta tag to be output".

godotislate’s picture

#3272202: Add <none> placeholder to clear / unset inherited value seems like a better solution. Should this issue be closed?

pfrenssen’s picture

Status: Reviewed & tested by the community » Closed (works as designed)

I agree as well, this is already covered by #3272202: Add <none> placeholder to clear / unset inherited value. Closing this. Feel free to reopen if you feel this adds a benefit over the other approach.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.