function profile_entity_base_field_info in Profile 8
Implements hook_entity_base_field_info().
File
- ./
profile.module, line 261 - Support for configurable user profiles.
Code
function profile_entity_base_field_info(EntityTypeInterface $entity_type) {
if ($entity_type
->id() === 'user') {
$entity_type_manager = \Drupal::entityTypeManager();
$fields = [];
// In random cases, this hook is invoked before the profile_type entity
// definition is registered.
if (!$entity_type_manager
->hasDefinition('profile_type')) {
return $fields;
}
$profile_types = $entity_type_manager
->getStorage('profile_type')
->loadMultiple();
foreach ($profile_types as $profile_type) {
$profile_type_id = $profile_type
->id();
$fields[$profile_type_id . '_profiles'] = BaseFieldDefinition::create('entity_reference')
->setName(sprintf('%s profiles', $profile_type
->label()))
->setLabel(t('@label profiles', [
'@label' => $profile_type
->label(),
]))
->setDescription(t('User profiles.'))
->setClass(ProfileEntityFieldItemList::class)
->setSetting('target_type', 'profile')
->setSetting('target_type', 'profile')
->setSetting('handler_settings', [
'target_bundles' => [
$profile_type_id => $profile_type_id,
],
])
->setSetting('profile_type', $profile_type_id)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE)
->setComputed(TRUE);
}
return $fields;
}
}