You are here

public static function Log::baseFieldDefinitions in Log entity 8

Same name and namespace in other branches
  1. 2.x src/Entity/Log.php \Drupal\log\Entity\Log::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/Log.php, line 237
Contains \Drupal\log\Entity\Log.

Class

Log
Defines the Log entity.

Namespace

Drupal\log\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The ID of the Log entity.'))
    ->setReadOnly(TRUE);
  $fields['user_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Authored by'))
    ->setDescription(t('The user ID of author of the Log entity.'))
    ->setRevisionable(TRUE)
    ->setSetting('target_type', 'user')
    ->setSetting('handler', 'default')
    ->setDefaultValueCallback('Drupal\\log\\Entity\\Log::getCurrentUserId')
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', array(
    'label' => 'hidden',
    'type' => 'author',
    'weight' => 99,
  ))
    ->setDisplayOptions('form', array(
    'type' => 'entity_reference_autocomplete',
    'weight' => 99,
    'settings' => array(
      'match_operator' => 'CONTAINS',
      'size' => '60',
      'autocomplete_type' => 'tags',
      'placeholder' => '',
    ),
  ))
    ->setDisplayConfigurable('view', TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Authored on'))
    ->setDescription(t('The time that the log was created.'))
    ->setRevisionable(TRUE)
    ->setDisplayOptions('view', array(
    'label' => 'hidden',
    'type' => 'timestamp',
    'weight' => 0,
  ))
    ->setDisplayOptions('form', array(
    'type' => 'datetime_timestamp',
    'weight' => 99,
  ))
    ->setDisplayConfigurable('form', TRUE);
  $fields['vid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Revision ID'))
    ->setDescription(t('The log revision ID.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['type'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Type'))
    ->setDescription(t('The log type.'))
    ->setSetting('target_type', 'log_type')
    ->setReadOnly(TRUE);
  $fields['langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language'))
    ->setDescription(t('The log language code.'))
    ->setTranslatable(TRUE)
    ->setRevisionable(TRUE)
    ->setDisplayOptions('view', array(
    'type' => 'hidden',
  ))
    ->setDisplayOptions('form', array(
    'type' => 'language_select',
    'weight' => 2,
  ));
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setRevisionable(TRUE)
    ->setDefaultValue('')
    ->setSetting('max_length', 255)
    ->setSetting('text_processing', 0)
    ->setDisplayOptions('view', array(
    'label' => 'hidden',
    'type' => 'string',
    'weight' => -5,
  ))
    ->setDisplayOptions('form', array(
    'type' => 'string_textfield',
    'weight' => -5,
  ))
    ->setDisplayConfigurable('form', TRUE);
  $fields['timestamp'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Date'))
    ->setDescription(t('Timestamp of the event being logged.'))
    ->setDefaultValueCallback('Drupal\\log\\Entity\\Log::getCurrentTimestamp')
    ->setRevisionable(TRUE)
    ->setDisplayOptions('view', array(
    'label' => 'above',
    'type' => 'timestamp',
    'weight' => 10,
  ))
    ->setDisplayOptions('form', array(
    'type' => 'datetime_timestamp',
    'weight' => 80,
  ))
    ->setDisplayConfigurable('view', TRUE)
    ->setDisplayConfigurable('form', TRUE);
  $fields['done'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Done'))
    ->setDescription(t('Boolean indicating whether the log is done (the event happened).'))
    ->setRevisionable(TRUE)
    ->setDefaultValue(TRUE)
    ->setDisplayOptions('view', array(
    'label' => 'above',
    'type' => 'boolean',
    'weight' => 10,
  ))
    ->setDisplayOptions('form', array(
    'settings' => array(
      'display_label' => TRUE,
    ),
    'weight' => 90,
  ))
    ->setDisplayConfigurable('view', TRUE)
    ->setDisplayConfigurable('form', TRUE);

  // Read only.
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the log was last edited.'));
  $fields['revision_timestamp'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Revision timestamp'))
    ->setDescription(t('The time that the current revision was created.'))
    ->setQueryable(FALSE)
    ->setRevisionable(TRUE);
  $fields['revision_uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Revision user ID'))
    ->setDescription(t('The user ID of the author of the current revision.'))
    ->setSetting('target_type', 'user')
    ->setQueryable(FALSE)
    ->setRevisionable(TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The UUID of the Log entity.'))
    ->setReadOnly(TRUE);
  return $fields;
}