metatag_get_route_entity() uses some code that seems prone to not working well. Not every entity type includes its full entity type name in the add URL, for example (look at commerce_product, which uses just "product" as the URL prefix for an example).

It seems like there needs to at a minimum be a hook which modules can register with to tell metatag about their URL adding structure, or maybe to match the current route and return an entity type if known. This would allow proper default values to carry through to the entity add forms for any custom entity type.

Comments

bmcclure created an issue. See original summary.

replicaobscura’s picture

Attached is a patch which implements a new hook, metatag_entity_add_routes, which returns an array of route_name => entity_type. Metatag then checks that map first, and falls back to attempting to automatically determine the entity type if not specified.

This works for me exactly as it did before without any further modification. However, it also works to easily support any custom entities which previously had route names which used a different pattern by implementing a hook in a custom module (or, ultimately, in whatever module is adding that route would be best).

I've tested this quite a bit on beta10 but just now implemented it on top of 8.x-1.x, so if anything is not working right, the patch may need to be updated to account for changes since beta10.

I know there should probably be an API file which defines how to use the new hook, but since I don't even know if this is the best approach, I wanted to get some feedback first.

replicaobscura’s picture

StatusFileSize
new2.86 KB

May be overkill, but I had some incorrect text a function comment that I've fixed in this version of the patch.

replicaobscura’s picture

Attached is a version of the patch that I've re-rolled specifically for beta10 for anyone needing to use this in a production site and isn't comfortable with using the dev release.

replicaobscura’s picture

I've over-complicated this--I don't think a hook is needed at all the more I look into it. Instead, metatag just needs to take into account Drupal's standard entity route naming scheme to be able to support pretty much any entity's add/edit form. Rolling a new patch shortly.

replicaobscura’s picture

replicaobscura’s picture

Title: metatag_get_route_entity() needs a hook » metatag_get_route_entity should support custom entity types better
replicaobscura’s picture

Title: metatag_get_route_entity should support custom entity types better » Support add/edit pages for all entity types
replicaobscura’s picture

Related issues: +#2654148: Support for custom entities

The more I think about it, I should just roll a new patch in https://www.drupal.org/node/2654148 that fixes this rather than have multiple patches floating around for adding custom entity support. I'm going to go there instead.

replicaobscura’s picture

Status: Active » Closed (duplicate)