class UniqueFieldConstraintTestHooks

Hook implementations for unique_field_constraint_test.

Hierarchy

Expanded class hierarchy of UniqueFieldConstraintTestHooks

File

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

Namespace

Drupal\unique_field_constraint_test\Hook
View source
class UniqueFieldConstraintTestHooks {
    
    /**
     * Implements hook_entity_base_field_info_alter().
     */
    public function entityBaseFieldInfoAlter(&$fields, EntityTypeInterface $entity_type) : void {
        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');
        }
    }
    
    /**
     * Implements hook_query_entity_test_access_alter().
     */
    public function queryEntityTestAccessAlter(AlterableInterface $query) : void {
        // Set an impossible condition to filter out all entities.
        
        /** @var \Drupal\Core\Database\Query\Select|\Drupal\Core\Database\Query\AlterableInterface $query */
        $query->condition('entity_test.id', 0);
    }

}

Members

Title Sort descending Modifiers Object type Summary
UniqueFieldConstraintTestHooks::entityBaseFieldInfoAlter public function Implements hook_entity_base_field_info_alter().
UniqueFieldConstraintTestHooks::queryEntityTestAccessAlter public function Implements hook_query_entity_test_access_alter().

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