You are here

public static function Feed::baseFieldDefinitions in Feeds 8.3

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/Feed.php, line 590

Class

Feed
Defines the feed entity class.

Namespace

Drupal\feeds\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = [];
  $fields['fid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Feed ID'))
    ->setDescription(t('The feed ID.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The feed UUID.'))
    ->setReadOnly(TRUE);
  $fields['type'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Feed type'))
    ->setDescription(t('The feed type.'))
    ->setSetting('target_type', 'feeds_feed_type')
    ->setReadOnly(TRUE);
  $fields['title'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Title'))
    ->setDescription(t('The title of this feed, always treated as non-markup plain text.'))
    ->setRequired(TRUE)
    ->setDefaultValue('')
    ->setSetting('max_length', 255)
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'string',
    'weight' => -5,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -5,
  ])
    ->setDisplayConfigurable('form', TRUE);
  $fields['uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Authored by'))
    ->setDescription(t('The user ID of the feed author.'))
    ->setRevisionable(TRUE)
    ->setSetting('target_type', 'user')
    ->setSetting('handler', 'default')
    ->setDefaultValueCallback('Drupal\\feeds\\Entity\\Feed::getCurrentUserId')
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'author',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'entity_reference_autocomplete',
    'weight' => 5,
    'settings' => [
      'match_operator' => 'CONTAINS',
      'size' => '60',
      'autocomplete_type' => 'tags',
      'placeholder' => '',
    ],
  ])
    ->setDisplayConfigurable('form', TRUE);
  $fields['status'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Importing status'))
    ->setDescription(t('A boolean indicating whether the feed is active.'))
    ->setDefaultValue(TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Authored on'))
    ->setDescription(t('The time that the feed was created.'))
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'timestamp',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'datetime_timestamp',
    'weight' => 10,
  ])
    ->setDisplayConfigurable('form', TRUE);
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the feed was last edited.'));
  $fields['imported'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Last import'))
    ->setDescription(t('The time that the feed was imported.'))
    ->setDefaultValue(0)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'timestamp_ago',
    'weight' => 1,
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['next'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Next import'))
    ->setDescription(t('The time that the feed will import next.'))
    ->setDefaultValue(0)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'timestamp',
    'weight' => 1,
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['queued'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Queued'))
    ->setDescription(t('Time when this feed was queued for refresh, 0 if not queued.'))
    ->setDefaultValue(0);
  $fields['source'] = BaseFieldDefinition::create('uri')
    ->setLabel(t('Source'))
    ->setDescription(t('The source of the feed.'))
    ->setRequired(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'feeds_uri_link',
    'weight' => -3,
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['config'] = BaseFieldDefinition::create('map')
    ->setLabel(t('Config'))
    ->setDescription(t('The config of the feed.'));
  $fields['item_count'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Items imported'))
    ->setDescription(t('The number of items imported.'))
    ->setDefaultValue(0)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'number_integer',
    'weight' => 0,
  ]);
  return $fields;
}