entity_reference_test.module

Same filename in other branches
  1. 9 core/modules/system/tests/modules/entity_reference_test/entity_reference_test.module
  2. 8.9.x core/modules/system/tests/modules/entity_reference_test/entity_reference_test.module
  3. 11.x core/modules/system/tests/modules/entity_reference_test/entity_reference_test.module

Helper module for the Entity Reference tests.

File

core/modules/system/tests/modules/entity_reference_test/entity_reference_test.module

View source
<?php


/**
 * @file
 * Helper module for the Entity Reference tests.
 */
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;

/**
 * Implements hook_entity_base_field_info().
 */
function entity_reference_test_entity_base_field_info(EntityTypeInterface $entity_type) {
    $fields = [];
    if ($entity_type->id() === 'entity_test') {
        $fields['user_role'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('User role'))
            ->setDescription(t('The role of the associated user.'))
            ->setSetting('target_type', 'user_role')
            ->setSetting('handler', 'default');
    }
    return $fields;
}

/**
 * Implements hook_entity_base_field_info_alter().
 */
function entity_reference_test_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
    if ($entity_type->id() === 'entity_test') {
        // Allow user_id field to use configurable widget.
        $fields['user_id']->setSetting('handler', 'default')
            ->setDisplayOptions('form', [
            'type' => 'entity_reference_autocomplete',
            'weight' => 0,
        ])
            ->setDisplayConfigurable('form', TRUE);
    }
}

Functions

Title Deprecated Summary
entity_reference_test_entity_base_field_info Implements hook_entity_base_field_info().
entity_reference_test_entity_base_field_info_alter Implements hook_entity_base_field_info_alter().

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