class EntityReferenceTestHooks

Hook implementations for entity_reference_test.

Hierarchy

Expanded class hierarchy of EntityReferenceTestHooks

File

core/modules/system/tests/modules/entity_reference_test/src/Hook/EntityReferenceTestHooks.php, line 15

Namespace

Drupal\entity_reference_test\Hook
View source
class EntityReferenceTestHooks {
    use StringTranslationTrait;
    
    /**
     * Implements hook_entity_base_field_info().
     */
    public function entityBaseFieldInfo(EntityTypeInterface $entity_type) : array {
        $fields = [];
        if ($entity_type->id() === 'entity_test') {
            $fields['user_role'] = BaseFieldDefinition::create('entity_reference')->setLabel($this->t('User role'))
                ->setDescription($this->t('The role of the associated user.'))
                ->setSetting('target_type', 'user_role')
                ->setSetting('handler', 'default');
        }
        return $fields;
    }
    
    /**
     * Implements hook_entity_base_field_info_alter().
     */
    public function entityBaseFieldInfoAlter(&$fields, EntityTypeInterface $entity_type) : void {
        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);
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
EntityReferenceTestHooks::entityBaseFieldInfo public function Implements hook_entity_base_field_info().
EntityReferenceTestHooks::entityBaseFieldInfoAlter public function Implements hook_entity_base_field_info_alter().
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

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