You are here

link_test_base_field.module in Drupal 10

Contains main module functions.

File

core/modules/link/tests/modules/link_test_base_field/link_test_base_field.module
View source
<?php

/**
 * @file
 * Contains main module functions.
 */
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\link\LinkItemInterface;

/**
 * Implements hook_entity_base_field_info().
 */
function link_test_base_field_entity_base_field_info(EntityTypeInterface $entity_type) {
  $fields = [];
  if ($entity_type
    ->id() === 'entity_test') {
    $fields['links'] = BaseFieldDefinition::create('link')
      ->setLabel(t('Links'))
      ->setRevisionable(TRUE)
      ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
      ->setDescription(t('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;
}