public static function Filebrowser::baseFieldDefinitions in Filebrowser 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
- lib/
Drupal/ filebrowser/ Entity/ Filebrowser.php, line 70 - Contains \Drupal\filebrowser\Entity\Filebrowser.
Class
- Filebrowser
- Defines the Filebrowser entity.
Namespace
Drupal\filebrowser\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['fbid'] = FieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Filebrowser entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = FieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Filebrowser entity.'))
->setReadOnly(TRUE);
$fields['langcode'] = FieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code of the Filebrowser entity.'));
$fields['name'] = FieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Filebrowser entity.'))
->setTranslatable(TRUE)
->setPropertyConstraints('value', array(
'Length' => array(
'max' => 32,
),
))
->setSettings(array(
'default_value' => '',
'max_length' => 255,
'text_processing' => 0,
))
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -6,
))
->setDisplayOptions('form', array(
'type' => 'string',
'weight' => -6,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['type'] = FieldDefinition::create('string')
->setLabel(t('Type'))
->setDescription(t('The bundle of the Filebrowser entity.'))
->setRequired(TRUE);
$fields['user_id'] = FieldDefinition::create('entity_reference')
->setLabel(t('User ID'))
->setDescription(t('The ID of the associated user.'))
->setSettings(array(
'target_type' => 'user',
))
->setTranslatable(TRUE);
$fields['filebrowser_field'] = FieldDefinition::create('string')
->setLabel(t('First Filebrowser Field'))
->setDescription(t('One field of the Filebrowser entity.'))
->setTranslatable(TRUE)
->setPropertyConstraints('value', array(
'Length' => array(
'max' => 32,
),
))
->setSettings(array(
'default_value' => '',
'max_length' => 255,
'text_processing' => 0,
))
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -5,
))
->setDisplayOptions('form', array(
'type' => 'string',
'weight' => -5,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}