You are here

public static function TwitterProfileEntity::baseFieldDefinitions in Tweet Feed 8.3

Same name and namespace in other branches
  1. 4.x src/Entity/TwitterProfileEntity.php \Drupal\tweet_feed\Entity\TwitterProfileEntity::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/TwitterProfileEntity.php, line 257

Class

TwitterProfileEntity
Defines the Twitt3er Profile entity.

Namespace

Drupal\tweet_feed\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);

  // Standard field, used as unique if primary index.
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The ID of the tweet entity.'))
    ->setReadOnly(TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setDescription(t('The time that the entity was created.'));

  // Standard field, unique outside of the scope of the current project.
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the entity was last changed.'));

  // Standard field, unique outside of the scope of the current project.
  $fields['user_id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('User Id'))
    ->setReadOnly(FALSE);

  // 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 tweet entity.'))
    ->setReadOnly(TRUE);
  $fields['twitter_user_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Twitter User ID'))
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'weight' => 0,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDescription(t('The name used on this profile.'))
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => 5,
  ])
    ->setDisplayOptions('form', [
    'weight' => 5,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['screen_name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Screen Name'))
    ->setDescription(t('The screen name for this profile.'))
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => 10,
  ])
    ->setDisplayOptions('form', [
    'weight' => 10,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['location'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Listed Profile Location'))
    ->setDescription(t('The location of the user of this profile.'))
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => 15,
  ])
    ->setDisplayOptions('form', [
    'weight' => 15,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['description'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Description'))
    ->setDescription(t('The description/information text under the profile name for this profile.'))
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => 20,
  ])
    ->setDisplayOptions('form', [
    'weight' => 20,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['followers_count'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Number of Followers'))
    ->setDescription(t('The number of followers this profile has.'))
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => 25,
  ])
    ->setDisplayOptions('form', [
    'weight' => 25,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['verified'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Twitter Author Verified'))
    ->setDescription(t('Is this author verified?'))
    ->setDefaultValue(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'boolean',
    'weight' => 30,
  ])
    ->setDisplayOptions('form', [
    'weight' => 30,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['statuses_count'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Tweet Count'))
    ->setDescription(t('The number of tweets for this profile.'))
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => 35,
  ])
    ->setDisplayOptions('form', [
    'weight' => 35,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['profile_image'] = BaseFieldDefinition::create('image')
    ->setLabel(t('Profile Image'))
    ->setDescription(t('The user profile image.'))
    ->setSettings([
    'uri_scheme' => 'public',
    'file_directory' => 'tweet_feed/[date:custom:Y]-[date:custom:m]',
    'alt_field_required' => FALSE,
    'file_extensions' => 'png jpg jpeg gif',
  ])
    ->setDisplayOptions('view', array(
    'label' => 'hidden',
    'type' => 'default',
    'weight' => 40,
  ))
    ->setDisplayOptions('form', array(
    'weight' => 40,
  ))
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['banner_image'] = BaseFieldDefinition::create('image')
    ->setLabel(t('Banner Image'))
    ->setDescription(t('The banner image for this user\'s profile.'))
    ->setSettings([
    'uri_scheme' => 'public',
    'file_directory' => 'tweet_feed/[date:custom:Y]-[date:custom:m]',
    'alt_field_required' => FALSE,
    'file_extensions' => 'png jpg jpeg gif',
  ])
    ->setDisplayOptions('view', array(
    'label' => 'hidden',
    'type' => 'default',
    'weight' => 45,
  ))
    ->setDisplayOptions('form', array(
    'weight' => 45,
  ))
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['hash'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Hash'))
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'weight' => 50,
  ])
    ->setDisplayOptions('form', [
    'weight' => 50,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  return $fields;
}