You are here

function key_auth_entity_base_field_info in Key auth 8

Implements hook_entity_base_field_info().

File

./key_auth.module, line 15
Module that allows authentication via key.

Code

function key_auth_entity_base_field_info(EntityTypeInterface $entity_type) {

  // Check if this is the user entity type.
  if ($entity_type
    ->id() === 'user') {

    // Add a field to store the api key.
    $fields['api_key'] = BaseFieldDefinition::create('string')
      ->setLabel(t('API key'))
      ->setDescription(t('The API key used for authentication.'))
      ->addConstraint('UniqueField')
      ->setSettings([
      'max_length' => 255,
      'text_processing' => 0,
    ]);
    return $fields;
  }
}