I have created a custom content entity type in a module, which defines the "title" field in the entity definition baseFieldDefinitions() code as follows:

$fields['title'] = BaseFieldDefinition::create('string')
	      ->setLabel(t('Name'))
	     ->setTranslatable(TRUE)
	      ->setDescription(t('The name of the item'))
	      ->setSettings(array(
	        'default_value' => '',
	        'max_length' => 255,
	        'text_processing' => 0,
	      ))
	      ->setDisplayOptions('view', array(
	        'label' => 'above',
	        'type' => 'string',
	        'weight' => -6,
	      ))
	      ->setDisplayOptions('form', array(
	        'type' => 'string_textfield',
	        'weight' => -6,
	      ))
	      ->setDisplayConfigurable('form', TRUE)
	      ->setDisplayConfigurable('view', TRUE);

Using pathauto 8.x-1.x-dev, I am attempting to add a Pathauto pattern for this custom content entity type that uses the "title" field. When I select my entity type, and then click "Browse available tokens", the "title" token is absent.

All fields for this entity type defined via the drupal interface are available as tokens, and so is ID, but title is not. This field needs to be defined programmatically as it is part of the entity's entity_keys annotation.

The title field is available as a token for default entity types like node, but not for custom created ones.

Comments

jmadden27 created an issue. See original summary.

Berdir’s picture

Can you share the whole class to make it easier to reproduce?

Berdir’s picture

Status: Active » Postponed (maintainer needs more info)
jidrone’s picture

Status: Postponed (maintainer needs more info) » Active

Hi @Berdir,

I have a similar issue, I reproduced this way:

  • I added a base field for nodes using hook_entity_base_field_info.
    $fields['group_content'] = BaseFieldDefinition::create('entity_reference')
          ->setName('group_content')
          ->setTargetEntityTypeId('node')
          ->setSetting('target_type', 'group_content')
          ->setLabel(t('Group content'))
          ->setTranslatable(FALSE)
          ->setComputed(TRUE)
          ->setCustomStorage(TRUE)
          ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
          ->setClass('\Drupal\gcontent_field\Field\GcontentFieldItemList')
          ->setDisplayConfigurable('form', TRUE)
          ->setDisplayOptions('form', [
            'type' => 'group_selector_widget',
            'weight' => 50,
          ])
          ->setDisplayConfigurable('view', TRUE)
          ->setDisplayOptions('view', [
            'label' => 'hidden',
            'type' => 'hidden',
            'weight' => 50,
          ]);
  • Ensure the field works.
  • The token for the field is not available.
Berdir’s picture

Category: Bug report » Support request
Status: Active » Fixed

token.module only exposes tokens for base fields for entity types that do *not* define their own tokens, otherwise you would get conflicts and overlaps. So that is by-design.

Status: Fixed » Closed (fixed)

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