You are here

public static function GatsbyLogEntity::baseFieldDefinitions in Gatsby Live Preview & Incremental Builds 8

Same name and namespace in other branches
  1. 2.0.x modules/gatsby_fastbuilds/src/Entity/GatsbyLogEntity.php \Drupal\gatsby_fastbuilds\Entity\GatsbyLogEntity::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

modules/gatsby_fastbuilds/src/Entity/GatsbyLogEntity.php, line 70

Class

GatsbyLogEntity
Defines the Gatsby log entity entity.

Namespace

Drupal\gatsby_fastbuilds\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);
  $fields['entity_uuid'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Entity UUID'))
    ->setDescription(t('The UUID of the logged entity.'))
    ->setSettings([
    'max_length' => 50,
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -3,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -3,
  ])
    ->setRequired(TRUE);
  $fields['title'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Title'))
    ->setDescription(t('The title of the entity being logged.'))
    ->setSettings([
    'max_length' => 250,
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -2,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -2,
  ])
    ->setRequired(TRUE);
  $fields['entity'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Entity'))
    ->setDescription(t('The entity type being logged.'))
    ->setSettings([
    'max_length' => 50,
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -2,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -2,
  ])
    ->setRequired(TRUE);
  $fields['bundle'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Bundle'))
    ->setDescription(t('The entity bundle type being logged.'))
    ->setSettings([
    'max_length' => 50,
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -1,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -1,
  ])
    ->setRequired(TRUE);
  $fields['action'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Action'))
    ->setDescription(t('The action of the entity being logged (insert, update, or delete).'))
    ->setSettings([
    'max_length' => 50,
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -1,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -1,
  ])
    ->setRequired(TRUE);
  $fields['json'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Entity JSON'))
    ->setDescription(t('The entity JSON.'))
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textarea',
    'weight' => 0,
  ]);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setDescription(t('The time that the entity was created.'));
  return $fields;
}