You are here

public static function Gauth::baseFieldDefinitions in Google Auth 8

Define the field properties here.

Field name, type and size determine the table structure.

In addition, we can define how the field and its content can be manipulated in the GUI. The behaviour of the widgets used can be determined here.

Overrides ContentEntityBase::baseFieldDefinitions

File

src/Entity/Gauth.php, line 294

Class

Gauth
Defines the Gauth entity.

Namespace

Drupal\gauth\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

  // Standard field, used as unique if primary index.
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Gauth ID'))
    ->setDescription(t('The ID of the Snapshot entity.'))
    ->setReadOnly(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => -1,
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDescription(t('The name of the Gauth entity.'))
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 0,
  ])
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 1,
  ])
    ->setRequired(TRUE)
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['developer_key'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Developer Key'))
    ->setDescription(t('The developer key of the Gauth entity.'))
    ->setRequired(TRUE)
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 1,
  ])
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 2,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['client_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Client Id'))
    ->setDescription(t('The client id of the Gauth entity.'))
    ->setRequired(TRUE)
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 2,
  ])
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 3,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['client_secret'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Client Secret'))
    ->setDescription(t('The client secret of the Gauth entity.'))
    ->setRequired(TRUE)
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 3,
  ])
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 4,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['services'] = BaseFieldDefinition::create('list_string')
    ->setLabel(t('Services'))
    ->setDescription(t('services of the Gauth entity.'))
    ->setRequired(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 4,
    'multiple' => TRUE,
  ])
    ->setSetting('allowed_values_function', 'gauth_google_services_names')
    ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 5,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['access_token'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Access Token'))
    ->setDescription(t('Access token from google'))
    ->setReadOnly(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 6,
  ])
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['is_authenticated'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Is Authenticated'))
    ->setDescription(t('Is gauth account authenticated'))
    ->setDefaultValue(FALSE)
    ->setReadOnly(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 7,
  ])
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', TRUE);

  // Owner field of the gauth.
  // Entity reference field, holds the reference to the user object.
  // The view shows the user name field of the user.
  // The form presents a auto complete field for the user name.
  $fields['uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('User Name'))
    ->setDescription(t('The Name of the associated user.'))
    ->setSetting('target_type', 'user')
    ->setSetting('handler', 'default')
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 8,
  ])
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['access_type'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Is Access Type Offline'))
    ->setDescription(t('Access type of the Gauth entity.'))
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'settings' => [
      'display_label' => TRUE,
    ],
    'weight' => 8,
  ])
    ->setDefaultValue(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 9,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  return $fields;
}