public static function Connection::baseFieldDefinitions in RedHen CRM 8
Provides base field definitions for an entity type.
Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'));
By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().
The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.
Overrides ContentEntityBase::baseFieldDefinitions
See also
\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()
\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()
File
- modules/
redhen_connection/ src/ Entity/ Connection.php, line 121
Class
- Connection
- Defines the Connection entity.
Namespace
Drupal\redhen_connection\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
// Define base fields "endpoint_X" for each our endpoints.
for ($x = 1; $x <= REDHEN_CONNECTION_ENDPOINTS; $x++) {
// Set first endpoint to redhen_contact and second to redhen_org by default.
$default_type = $x & 1 ? 'redhen_contact' : 'redhen_org';
$fields["endpoint_{$x}"] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Endpoint @x', [
'@x' => $x,
]))
->setRequired(TRUE)
->setSetting('target_type', $default_type)
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => -1,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
}
$fields['role'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Role'))
->setRequired(TRUE)
->setRevisionable(TRUE)
->setSetting('target_type', 'redhen_connection_role')
->setSetting('handler', 'default')
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => -1,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Active'))
->setDescription(t('A boolean indicating whether the connection is active.'))
->setDefaultValue(TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
],
'weight' => 16,
])
->setDisplayConfigurable('form', TRUE)
->setRevisionable(TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the connection was created.'))
->setRevisionable(TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the connection was last edited.'))
->setRevisionable(TRUE);
return $fields;
}