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
Comment | File | Size | Author |
---|---|---|---|
#4 | metatag-defaults-widget-3045460-4.patch | 1.29 KB | Berdir |
#2 | metatag-defaults-widget-3045460-2.patch | 732 bytes | Berdir |
Comments
Comment #2
BerdirComment #3
BerdirRealized 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.
Comment #4
BerdirThis.
Testing this would require a custom route to display the node add form, not sure if that's worth it.
Comment #5
DamienMcKennaYeah, this will work. Thanks.