You are here

function token_entity_base_field_info in Token 8

Implements hook_entity_base_field_info().

File

./token.module, line 646
Enhances the token API in core: adds a browseable UI, missing tokens, etc.

Code

function token_entity_base_field_info(EntityTypeInterface $entity_type) {

  // We add a pseudo entity-reference field to track the menu entry created
  // from the node add/edit form so that tokens generated at that time that
  // reference the menu link can access the yet to be saved menu link.
  // @todo Revisit when https://www.drupal.org/node/2315773 is resolved.
  if ($entity_type
    ->id() === 'node' && \Drupal::moduleHandler()
    ->moduleExists('menu_ui')) {
    $fields['menu_link'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Menu link'))
      ->setDescription(t('Computed menu link for the node (only available during node saving).'))
      ->setRevisionable(TRUE)
      ->setSetting('target_type', 'menu_link_content')
      ->setClass('\\Drupal\\token\\MenuLinkFieldItemList')
      ->setTranslatable(TRUE)
      ->setInternal(TRUE)
      ->setDisplayOptions('view', [
      'label' => 'hidden',
      'region' => 'hidden',
    ])
      ->setComputed(TRUE)
      ->setDisplayOptions('form', [
      'region' => 'hidden',
    ]);
    return $fields;
  }
  return [];
}