You are here

public static function SocialAuth::baseFieldDefinitions in Social Auth 3.x

Same name and namespace in other branches
  1. 8.2 src/Entity/SocialAuth.php \Drupal\social_auth\Entity\SocialAuth::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/SocialAuth.php, line 131

Class

SocialAuth
Defines the Social Auth entity.

Namespace

Drupal\social_auth\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The ID of the Social Auth record.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The Social Auth user UUID.'))
    ->setReadOnly(TRUE);

  // The ID of user account associated.
  $fields['user_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('User ID'))
    ->setDescription(t('The Drupal uid associated with social network.'))
    ->setSetting('target_type', 'user');

  // Name of the social network account associated.
  $fields['plugin_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Plugin ID'))
    ->setDescription(t('Identifier for Social Auth implementer.'));

  // Unique Account ID returned by the social network provider.
  $fields['provider_user_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Provider user ID'))
    ->setDescription(t('The unique user ID in the provider.'));

  // Token received after user authentication.
  $fields['token'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Token received after user authentication'))
    ->setDescription(t('Used to make API calls.'));

  // Additional Data collected social network provider.
  $fields['additional_data'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Additional data'))
    ->setDescription(t('The additional data kept for future use.'));

  // User creation time.
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setDescription(t('The time that the entity was created.'));

  // User modified time.
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the entity was last edited.'));
  return $fields;
}