link_test_base_field.module

Same filename in other branches
  1. 8.9.x core/modules/link/tests/modules/link_test_base_field/link_test_base_field.module
  2. 10 core/modules/link/tests/modules/link_test_base_field/link_test_base_field.module
  3. 11.x core/modules/link/tests/modules/link_test_base_field/link_test_base_field.module

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;
}

Functions

Title Deprecated Summary
link_test_base_field_entity_base_field_info Implements hook_entity_base_field_info().

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