Robots metatag configuration always added to metatag table on node save

Created on 14 October 2020, over 3 years ago
Updated 29 November 2023, 7 months ago

Problem/Motivation

Drupal 7.73 and metatags 1.27. I am not sure if this is default behavior or if I am doing something wrong, but after every node save (from node edit form, even nothing is changed) saved nodes gets they record in metatag db table. This table should store overridden configuration per node, if some configuration has been changed in node edit form. It looks like, even no changes on node metatags has been made, robots metatag configuration (Advanced Tags section) is always recorded to this table. All other configurations behave as expected, they are recorded in metatag table only if they are changed on node edit form before node save.
Is this correct behavior or I have some miss configuration?

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡·πŸ‡ΈSerbia rakun

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States xlin1003

    I believe the issue stems from the use of array_filter on $options['defaults'][$metatag]['value'] within the metatag_metatags_form() function. This results in a mismatch between the default and value when the instance (e.g., global) is overridden, impacting the functionality in metatag_filter_values_from_defaults().

    function metatag_metatags_form(array &$form, $instance, array $metatags = array(), array $options = array()) {
      // ... (other code)
    
      // Add a default value form element.
      if (isset($options['defaults'][$metatag]['value'])) {
        if (is_array($options['defaults'][$metatag]['value'])) {
          $options['defaults'][$metatag]['value'] = array_filter($options['defaults'][$metatag]['value']);
        }
    
        $metatag_form['default'] = array(
          '#type' => 'hidden',
          '#value' => $options['defaults'][$metatag]['value'],
        );
      }
    

    When metatag_filter_values_from_defaults() is called, the default is set, but it does not match the value.

    function metatag_filter_values_from_defaults(array &$values, array $defaults = array()) {
      foreach ($values as $metatag => $data) {
        $default = isset($data['default']) ? $data['default'] : (isset($defaults[$metatag]['value']) ? $defaults[$metatag]['value'] : NULL);
        if (isset($default) && isset($data['value']) && $default === $data['value']) {
          // Meta tag has a default, and it matches the user-submitted value.
          unset($values[$metatag]);
        }
      }
    }
    
  • πŸ‡ΊπŸ‡ΈUnited States xlin1003

    Link related issues.

  • Status changed to Needs review 7 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 7.x + Environment: PHP 7.4 & MySQL 8
    last update 7 months ago
    263 pass
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Thanks for putting that together. Let's see what the testbot says.

Production build 0.69.0 2024