function EntityReferenceTestHooks::entityBaseFieldInfo
Implements hook_entity_base_field_info().
Attributes
#[Hook('entity_base_field_info')]
File
- 
              core/modules/ system/ tests/ modules/ entity_reference_test/ src/ Hook/ EntityReferenceTestHooks.php, line 22 
Class
- EntityReferenceTestHooks
- Hook implementations for entity_reference_test.
Namespace
Drupal\entity_reference_test\HookCode
public function entityBaseFieldInfo(EntityTypeInterface $entity_type) : array {
  $fields = [];
  if ($entity_type->id() === 'entity_test') {
    $fields['user_role'] = BaseFieldDefinition::create('entity_reference')->setLabel($this->t('User role'))
      ->setDescription($this->t('The role of the associated user.'))
      ->setSetting('target_type', 'user_role')
      ->setSetting('handler', 'default');
  }
  return $fields;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
