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

Undefined index: #attributes a metatag_html_head_alter() #73

Closed robertgarrigos closed 2 years ago

robertgarrigos commented 3 years ago

Got this error in the logs:

Notice: Undefined index: #attributes a metatag_html_head_alter() (línia 2192 de /.../modules/metatag/metatag.module).

I fixed by adding an if statement:

if (isset($closer_inspection[$key]['#attributes'])) {
        foreach ($closer_inspection[$key]['#attributes'] as $attr_key => $attr_value) {
          $attr_value = strtolower($attr_value); // Account for G in generator.
          // Only hide the metatag if it's one we care about.
          if (in_array($attr_key, $metatag_attrs) && in_array($attr_value, $core_tags)) {
            // Only hide metatag if another is provided.
            if (isset($overridden[$attr_key]) && $overridden[$attr_key] == $attr_value) {
              // Setting the #access attribute to these will stop them from being output
              // but still leave the tags present for other modules to interact with.
              $elements[$key]['#access'] = FALSE;
            }
          }
        }
}
yorkshire-pudding commented 3 years ago

I have tested the fix offered by @robertgarrigos and can confirm that it fixed this issue.

yorkshire-pudding commented 2 years ago

@robertgarrigos - are you able to do a pull request on this issue so it can be merged into the main module repository?

robertgarrigos commented 2 years ago

@jenlampton is in charge of this module.