public static function ImageHotspot::baseFieldDefinitions in Image Hotspots 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
- src/
Entity/ ImageHotspot.php, line 140
Class
- ImageHotspot
- Defines the image hotspot entity class.
Namespace
Drupal\image_hotspots\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['hid'] = BaseFieldDefinition::create('integer')
->setLabel(t('Hid'))
->setDescription(t('The hotspot id.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('Uuid'))
->setDescription(t('The hotspot uuid.'))
->setReadOnly(TRUE);
$fields['field_name'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Image field with hotspot'))
->setDescription(t('The id of image field with the hotspot.'))
->setSetting('target_type', 'field_config');
$fields['fid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('File Id'))
->setDescription(t('Image file id.'))
->setSetting('target_type', 'file');
$fields['image_style'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Image style'))
->setDescription(t('Image style.'))
->setSetting('target_type', 'image_style');
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('User Id'))
->setDescription(t('The id of user that created hotspot.'))
->setSetting('target_type', 'user');
$fields['title'] = BaseFieldDefinition::create('string')
->setLabel(t('Title'))
->setDescription(t('Title of the hotspot.'))
->setTranslatable(TRUE);
$fields['target'] = BaseFieldDefinition::create('string')
->setLabel(t('Target'))
->setDescription(t('Type of target for a tag.'));
$fields['description'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Description'))
->setDescription(t('Description of the hotspot.'))
->setTranslatable(TRUE);
$fields['link'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Link'))
->setDescription(t('link of the hotspot.'))
->setTranslatable(TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language'))
->setDescription(t('Language of the hotspot.'));
$fields['x'] = BaseFieldDefinition::create('float')
->setLabel(t('X coordinate'))
->setDescription(t('The X coordinate of hotspot.'))
->setSetting('unsigned', TRUE);
$fields['y'] = BaseFieldDefinition::create('float')
->setLabel(t('Y coordinate'))
->setDescription(t('The Y coordinate of hotspot.'))
->setSetting('unsigned', TRUE);
$fields['y2'] = BaseFieldDefinition::create('float')
->setLabel(t('Y2 coordinate'))
->setDescription(t('The Y2 coordinate of hotspot.'))
->setSetting('unsigned', TRUE);
$fields['x2'] = BaseFieldDefinition::create('float')
->setLabel(t('X2 coordinate'))
->setDescription(t('The X2 coordinate of hotspot.'))
->setSetting('unsigned', TRUE);
return $fields;
}