public static function CountryList::baseFieldDefinitions in Country, State and City Fields 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/ CountryList.php, line 167
Class
- CountryList
- Defines the countrylist entity.
Namespace
Drupal\country_state_city\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 Country 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 Country entity.'))
->setReadOnly(TRUE);
// Name field for the slider.
// 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('The name of the Country entity.'))
->setTranslatable(TRUE)
->setSettings([
'max_length' => 255,
'text_processing' => 0,
])
->setDefaultValue(NULL)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -6,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -6,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['iso3'] = BaseFieldDefinition::create('string')
->setLabel(t('ISO3'))
->setDescription(t('The iso3 name of the Country list entity.'))
->setTranslatable(TRUE)
->setSettings([
'max_length' => 10,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['iso2'] = BaseFieldDefinition::create('string')
->setLabel(t('ISO2'))
->setDescription(t('The iso2 name of the Country list entity.'))
->setTranslatable(TRUE)
->setSettings([
'max_length' => 10,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['currency'] = BaseFieldDefinition::create('string')
->setLabel(t('Currency'))
->setDescription(t('The currency of the Country list entity.'))
->setTranslatable(TRUE)
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code of Country 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;
}