How to set a URL alias for a custom entity type generated with drush?

cn flag

I created a custom content entity type with the command drush generate entity:content. Now I want to set a URL alias pattern at /admin/config/search/path/patterns, but my new custom content entity type is not available. How can I add URL aliases to this type?

cn flag

The custom entity type needs to have a path base field.

You can add it to /src/MyEntity.php in the baseFieldDefinitions() function:

$fields['path'] = BaseFieldDefinition::create('path')
  ->setLabel(t('URL alias'))
  ->setDisplayOptions('form', [
    'type' => 'path',
    'weight' => 30,
  ->setDisplayConfigurable('form', TRUE)

Note that you need to uninstall the module containing the entity definition, make this change, and then re-enable the module, or run a database query to avoid messing up your DB.

Reference: Discussion on changing the way this is handled in core

I sit in a Tesla and translated this thread with Ai:


Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.