You are here

public static function GoogleApiClient::baseFieldDefinitions in Google API PHP Client 8.3

Same name and namespace in other branches
  1. 8.4 src/Entity/GoogleApiClient.php \Drupal\google_api_client\Entity\GoogleApiClient::baseFieldDefinitions()
  2. 8.2 src/Entity/GoogleApiClient.php \Drupal\google_api_client\Entity\GoogleApiClient::baseFieldDefinitions()

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/GoogleApiClient.php, line 351

Class

GoogleApiClient
Defines the GoogleApiClient entity.

Namespace

Drupal\google_api_client\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

  // Standard field, used as unique if primary index.
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('GoogleApiClient ID'))
    ->setDescription(t('The ID of the GoogleApiClient entity.'))
    ->setReadOnly(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => -1,
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The Google Api Client UUID.'))
    ->setReadOnly(TRUE);
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDescription(t('The name of the GoogleApiClient 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 GoogleApiClient entity.'))
    ->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 GoogleApiClient 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 GoogleApiClient 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 GoogleApiClient entity.'))
    ->setRequired(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 4,
    'multiple' => TRUE,
  ])
    ->setSetting('allowed_values_function', 'google_api_client_google_services_names')
    ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 5,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['scopes'] = BaseFieldDefinition::create('list_string')
    ->setLabel(t('Scopes'))
    ->setDescription(t('scopes of the GoogleApiClient entity.'))
    ->setRequired(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 5,
    'multiple' => TRUE,
  ])
    ->setSetting('allowed_values_function', 'google_api_client_google_scopes_names')
    ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 6,
  ])
    ->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' => 7,
  ])
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['is_authenticated'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Is Authenticated'))
    ->setDescription(t('Is google_api_client account authenticated'))
    ->setDefaultValue(FALSE)
    ->setReadOnly(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 8,
  ])
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', TRUE);

  // Owner field of the google_api_client.
  // 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' => 9,
  ])
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['access_type'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Is Access Type Offline'))
    ->setDescription(t('Access type of the GoogleApiClient entity.'))
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'settings' => [
      'display_label' => TRUE,
    ],
    'weight' => 6,
  ])
    ->setDefaultValue(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => 11,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  return $fields;
}