public static function Flipbook::baseFieldDefinitions in 3D Flipbook 8
Define the field properties here.
Field name, type and size determine the table structure.
In addition, we can define how the field and its content can be manipulated in the GUI. The behaviour of the widgets used can be determined here.
Overrides ContentEntityBase::baseFieldDefinitions
File
- src/
Entity/ Flipbook.php, line 218
Class
- Flipbook
- Defines the Flipbook entity.
Namespace
Drupal\flipbook\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
// Standard field, used as unique if primary index.
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Contact entity.'))
->setReadOnly(TRUE);
// Standard field, unique outside of the scope of the current project.
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Contact entity.'))
->setReadOnly(TRUE);
// Name field for the contact.
// We set display options for the view as well as the form.
// Users with correct privileges can change the view and edit configuration.
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('Name of the Flipbook entity.'))
->setRequired(TRUE)
->setSettings([
'default_value' => '',
'max_length' => 255,
'text_processing' => 0,
])
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -6,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -6,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['flipbook_cover'] = BaseFieldDefinition::create('image')
->setLabel(t('Flipbook Cover Image'))
->setDescription(t('Upload Flipbook Cover Image'))
->setRequired(TRUE)
->setSettings([
'file_directory' => 'flipbook',
'alt_field_required' => FALSE,
'file_extensions' => 'png jpg jpeg',
])
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'default',
'weight' => 0,
])
->setDisplayOptions('form', [
'label' => 'hidden',
'type' => 'image_image',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
// Owner field of the contact.
// Entity reference field, holds the reference to the user object.
// The view shows the user name field of the user.
// The form presents a auto complete field for the user name.
$validators = [
'file_validate_extensions' => [
'pdf doc docx xls xlsx ppt pptx png jpg jpeg',
],
'file_validate_size' => [
file_upload_max_size(),
],
];
$fields['flipbook'] = BaseFieldDefinition::create('file')
->setLabel(t('Flipbook PDF'))
->setDescription(t('Upload Flipbook pdf file.'))
->setRequired(TRUE)
->setSetting('upload_validators', $validators)
->setSetting('file_extensions', 'pdf png jpg jpeg svg ... etc ')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'file',
'weight' => -3,
])
->setDisplayOptions('form', [
'type' => 'file_generic',
// doesn't work.
'description' => [
// doesn't work.
'theme' => 'file_upload_help',
// doesn't work.
'description' => t('A Gettext Portable Object file.'),
],
'settings' => [
'upload_validators' => $validators,
],
'weight' => -3,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code of Flipbook entity.'));
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
return $fields;
}