Creating multiple aliases for a single entity

Created on 8 September 2017, about 7 years ago
Updated 22 August 2024, 3 months ago

I know in SEO you wouldn't have the same content at two separate URL's but I believe I have a genuine use case for 2 aliases for the same entity. I'm using view modes to render variations of a specific entity. For example I have a Competition entity that has a URL of /competition/my-new-comp

Then I have view modes and separate routes set up in my routing file that direct to those view modes, and the URL structure is /competition/my-new-comp/participants and /competition/my-new-comp/register

If I manually create the aliases then everything works, my question is, where would be the best place to generate the additional aliases. Looking at \Drupal\pathauto\PathautoGenerator::createEntityAlias that won't work because \Drupal\pathauto\PathautoGenerator::getPatternByEntity will only select one pattern even If i've created multiple patterns.

Is there a good place to hook in and write custom code to generate the view mode aliases?

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia benjy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States bobburns

    Doesn't work apparently for commerce products. Apparently the error is

    AssertionError: The file specified by the given app root, relative path and file name (/var/www/public_html/modules/pathauto/pathauto.info.yml) do not exist. in assert() (line 68 of /var/www/public_html/core/lib/Drupal/Core/Extension/Extension.php)
    #0 /var/www/public_html/core/lib/Drupal/Core/Extension/Extension.php(68): assert(false, 'The file specif...')
    #1 /var/www/public_html/core/lib/Drupal/Core/Extension/ModuleHandler.php(114): Drupal\Core\Extension\Extension->__construct('/var/www/...', 'module', 'modules/pathaut...', 'pathauto.module')
    #2 /var/www/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(259): Drupal\Core\Extension\ModuleHandler->__construct('/var/www...', Array, Object(Drupal\Core\Cache\DatabaseBackend))
    #3 /var/www/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(449): Drupal\Component\DependencyInjection\Container->createService(Array, 'private__n_y1_q...')
    #4 /var/www/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
    #5 /var/www/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container

    and more

    I could use this for crawlers that keep looking for and old link

  • πŸ‡³πŸ‡±Netherlands boazpoolman

    Rerolled the patch for version 8.x-1.12

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    48 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    3 pass, 21 fail
  • πŸ‡³πŸ‡±Netherlands boazpoolman

    Rerolled the patch again to fix the tests.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    48 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    48 pass
  • πŸ‡¬πŸ‡§United Kingdom newaytech

    I have a requirement here where a commerce product can be reached via several paths. I want to have a URL per taxonomy term - so need to be able to have multiple URL aliases per Commerce Product - all with a single canonical. Does this patch work with Commerce Products - I saw in a note that there was an issue? Thanks for the work here - really enjoying D8/9/10...

  • What does prevent from merging the latest patch exactly ?

Production build 0.71.5 2024