function LinkTestBaseFieldHooks::entityBaseFieldInfo

Implements hook_entity_base_field_info().

Attributes

#[Hook('entity_base_field_info')]

File

core/modules/link/tests/modules/link_test_base_field/src/Hook/LinkTestBaseFieldHooks.php, line 21

Class

LinkTestBaseFieldHooks
Hook implementations for link_test_base_field.

Namespace

Drupal\link_test_base_field\Hook

Code

public function entityBaseFieldInfo(EntityTypeInterface $entity_type) : array {
  $fields = [];
  if ($entity_type->id() === 'entity_test') {
    $fields['links'] = BaseFieldDefinition::create('link')->setLabel('Links')
      ->setRevisionable(TRUE)
      ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
      ->setDescription('Add links to the entity.')
      ->setRequired(FALSE)
      ->setSettings([
      'link_type' => LinkItemInterface::LINK_GENERIC,
      'title' => DRUPAL_REQUIRED,
    ])
      ->setDisplayOptions('form', [
      'type' => 'link_default',
      'weight' => 49,
    ]);
  }
  return $fields;
}

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