function UniqueFieldConstraintTestHooks::entityBaseFieldInfoAlter

Implements hook_entity_base_field_info_alter().

File

core/modules/system/tests/modules/unique_field_constraint_test/src/Hook/UniqueFieldConstraintTestHooks.php, line 19

Class

UniqueFieldConstraintTestHooks
Hook implementations for unique_field_constraint_test.

Namespace

Drupal\unique_field_constraint_test\Hook

Code

public function entityBaseFieldInfoAlter(&$fields, EntityTypeInterface $entity_type) {
    if ($entity_type->id() === 'entity_test_string_id') {
        
        /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
        $fields['name']->addConstraint('UniqueField');
    }
    if ($entity_type->id() === 'entity_test') {
        
        /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
        $fields['name']->addConstraint('UniqueField');
    }
}

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