public static function WeatherPlace::baseFieldDefinitions in Weather 2.0.x
Same name and namespace in other branches
- 8 src/Entity/WeatherPlace.php \Drupal\weather\Entity\WeatherPlace::baseFieldDefinitions()
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/ WeatherPlace.php, line 29
Class
- WeatherPlace
- Defines the Weather place entity.
Namespace
Drupal\weather\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = [];
$fields['geoid'] = BaseFieldDefinition::create('string')
->setLabel(t('Geoid'))
->setRequired(TRUE)
->setDescription('GeoID of the location')
->setSetting('max_length', 20);
$fields['latitude'] = BaseFieldDefinition::create('float')
->setLabel(t('Latitude'))
->setDescription('Latitude of location')
->setRequired(TRUE)
->setDefaultValue(0.0);
$fields['longitude'] = BaseFieldDefinition::create('float')
->setLabel(t('Longitude'))
->setDescription('Longitude of location')
->setRequired(TRUE)
->setDefaultValue(0.0);
$fields['country'] = BaseFieldDefinition::create('string')
->setLabel(t('Country'))
->setRequired(TRUE)
->setDescription('Country of location')
->setSetting('max_length', 225);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setRequired(TRUE)
->setDescription('Name of location')
->setSetting('max_length', 225);
$fields['link'] = BaseFieldDefinition::create('string')
->setLabel(t('Link'))
->setRequired(TRUE)
->setDescription('Shortened link of location at yr.no.')
->setSetting('max_length', 225);
$fields['status'] = BaseFieldDefinition::create('string')
->setLabel(t('Status'))
->setRequired(TRUE)
->setDescription('Status of place')
->setSetting('max_length', 8);
return $fields;
}