Problem/Motivation

If you create e.g. a node through a non-standard route, for example in combination with the group.module, then the metatag defaults aren't filled out correctly based on the node type.

That's because it calls metatag_get_default_tags() without passing the current entity to it explicitly, so that has to fall back to the defaults from the route, which only supports the default route.

It's also slower, especially for new forms, as it has to create a new entity just to figure out the entity type/bundle.

Proposed resolution

Change it to $default_tags = metatag_get_default_tags($items->getEntity());.

In some really weird cases, this *could* result in a problem if $items->getEntity() is actually not the node, e.g. if you add metatags through a paragraph to nodes, but that seems like a super-weird thing that shouldn't actually work :)

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir created an issue. See original summary.

Berdir’s picture

Status: Active » Needs review
FileSize
732 bytes
Berdir’s picture

Status: Needs review » Needs work

Realized that \Drupal\metatag\Plugin\Field\FieldType\MetatagFieldItem::preSave() also needs to be updated to be consistent or it will save the defaults as explicit values.

Berdir’s picture

Status: Needs work » Needs review
FileSize
1.29 KB

This.

Testing this would require a custom route to display the node add form, not sure if that's worth it.

DamienMcKenna’s picture

Status: Needs review » Fixed
Parent issue: » #2996500: Plan for Metatag 8.x-1.10

Yeah, this will work. Thanks.

  • DamienMcKenna committed b760bee on 8.x-1.x authored by Berdir
    Issue #3045460 by Berdir: MetatagFirehose::formElement() should pass...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.