public static function Item::baseFieldDefinitions in Drupal 8
Same name and namespace in other branches
- 9 core/modules/aggregator/src/Entity/Item.php \Drupal\aggregator\Entity\Item::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
- core/
modules/ aggregator/ src/ Entity/ Item.php, line 56
Class
- Item
- Defines the aggregator item entity class.
Namespace
Drupal\aggregator\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
$fields = parent::baseFieldDefinitions($entity_type);
$fields['iid']
->setLabel(t('Aggregator item ID'))
->setDescription(t('The ID of the feed item.'));
$fields['langcode']
->setLabel(t('Language code'))
->setDescription(t('The feed item language code.'));
$fields['fid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Source feed'))
->setRequired(TRUE)
->setDescription(t('The aggregator feed entity associated with this item.'))
->setSetting('target_type', 'aggregator_feed')
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'entity_reference_label',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE);
$fields['title'] = BaseFieldDefinition::create('string')
->setLabel(t('Title'))
->setDescription(t('The title of the feed item.'));
$fields['link'] = BaseFieldDefinition::create('uri')
->setLabel(t('Link'))
->setDescription(t('The link of the feed item.'))
->setDisplayOptions('view', [
'region' => 'hidden',
])
->setDisplayConfigurable('view', TRUE);
$fields['author'] = BaseFieldDefinition::create('string')
->setLabel(t('Author'))
->setDescription(t('The author of the feed item.'))
->setDisplayOptions('view', [
'label' => 'hidden',
'weight' => 3,
])
->setDisplayConfigurable('view', TRUE);
$fields['description'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Description'))
->setDescription(t('The body of the feed item.'));
$fields['timestamp'] = BaseFieldDefinition::create('created')
->setLabel(t('Posted on'))
->setDescription(t('Posted date of the feed item, as a Unix timestamp.'))
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'timestamp_ago',
'weight' => 1,
])
->setDisplayConfigurable('view', TRUE);
// @todo Convert to a real UUID field in
// https://www.drupal.org/node/2149851.
$fields['guid'] = BaseFieldDefinition::create('string_long')
->setLabel(t('GUID'))
->setDescription(t('Unique identifier for the feed item.'));
return $fields;
}