1. Create new custom content entity (or you can use Group entity from Group module)
2. Configure metatags for this entity, add [entity:url] for example.
3. Go to the group add page
4. Aaaand it's gone.

The website encountered an unexpected error. Please try again later.Drupal\Core\Entity\EntityMalformedException: The "group" entity cannot have a URI as it does not have an ID in Drupal\Core\Entity\Entity->toUrl() (line 180 of core/lib/Drupal/Core/Entity/Entity.php).

group_tokens('group', Array, Array, Array, Object)
call_user_func_array('group_tokens', Array) (Line: 402)
Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array) (Line: 304)
Drupal\Core\Utility\Token->generate('group', Array, Array, Array, Object) (Line: 196)
Drupal\Core\Utility\Token->replace('[group:url]', Array, Array) (Line: 48)
Drupal\metatag\MetatagToken->replace('[group:url]', Array, Array) (Line: 496)
Drupal\metatag\MetatagManager->generateRawElements(Array, Object) (Line: 425)
Drupal\metatag\MetatagManager->generateElements(Array, Object) (Line: 409)
metatag_get_tags_from_route() (Line: 113)
metatag_page_attachments(Array) (Line: 297)
Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 273)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 108)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

So, I guess that Metatag module should not generate meta tags for not existing entities yet.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kala4ek created an issue. See original summary.

kala4ek’s picture

DamienMcKenna’s picture

A minor tweak, putting back the !empty($entity) bit.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. Thanks!

Status: Fixed » Closed (fixed)

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