- 🇨🇳China hongqing
I have the same issue with Metatag 2.0.0 and Drupal 10.3.0 when add tags to custom route.
- Status changed to Needs review
6 months ago 6:17am 18 July 2024 - 🇮🇳India vinai_katiyar Delhi NCR
Hi @nelo_drup, @hongqing,
I set the meta tags for a custom route of a webform and got a success message "Created metatags for the path: /form/custom-contact. Internal route: entity.webform.canonical.". but when I tried to set meta tags for second webform using their custom route then got the error message "There are already metatags created for this route".
The error "There are already metatags created for this route" typically occurs because the Metatag module in Drupal considers the internal route of the webform rather than the URL alias.
So the internal route for viewing a webform is typically entity.webform.canonical and the path is usually /webform/{webform_id}.
Kindly refer to the attached screenshot for reference.
You can use the below custom logic in custom module or theme hook to set meta tags for custom route of the webforms -
if (\Drupal::routeMatch()->getRouteName() == 'entity.webform.canonical') { $alias = \Drupal::service('path_alias.manager')->getAliasByPath(\Drupal::service('path.current')->getPath()); if ($alias == '/contact-us') { // Add meta tags for /contact-us $variables['#attached']['html_head'][] = [ [ '#tag' => 'meta', '#attributes' => [ 'name' => 'description', 'content' => 'Contact us form description', ], ], ]; } elseif ($alias == '/custom-contact') { // Add meta tags for /custom-contact $variables['#attached']['html_head'][] = [ [ '#tag' => 'meta', '#attributes' => [ 'name' => 'description', 'content' => 'Custom Contact us form description', ], ], ]; } }
- Status changed to Active
6 months ago 3:18pm 18 July 2024 - 🇺🇸United States olarin
FYI, I had a client encounter this same issue and get confused by a page display on a View with a contextual filter in the URL (to the end user it looks like multiple distinct pages, one for each valid value of the contextual filter, whereas it's obviously just one route underneath). It might be nice if there was a way to at least describe the problem more clearly to non-technical users in the error message, but I'm not sure what that would look like.