function EntitySchemaTestHooks::entityBaseFieldInfo

Implements hook_entity_base_field_info().

Attributes

#[Hook('entity_base_field_info')]

File

core/modules/system/tests/modules/entity_schema_test/src/Hook/EntitySchemaTestHooks.php, line 46

Class

EntitySchemaTestHooks
Hook implementations for entity_schema_test.

Namespace

Drupal\entity_schema_test\Hook

Code

public function entityBaseFieldInfo(EntityTypeInterface $entity_type) : array {
  if ($entity_type->id() == 'entity_test_update') {
    $definitions['custom_base_field'] = BaseFieldDefinition::create('string')->setName('custom_base_field')
      ->setLabel($this->t('A custom base field'));
    if (\Drupal::state()->get('entity_schema_update')) {
      $definitions += EntityTestMulRev::baseFieldDefinitions($entity_type);
      // And add a revision log.
      $definitions['revision_log'] = BaseFieldDefinition::create('string_long')->setLabel($this->t('Revision log message'))
        ->setDescription($this->t('The log entry explaining the changes in this revision.'))
        ->setRevisionable(TRUE);
    }
    return $definitions;
  }
  return [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.