.../rest/tests/modules/rest_test/rest_test.module | 17 +++++++++-------- .../EntityResource/EntityResourceTestBase.php | 21 +-------------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/core/modules/rest/tests/modules/rest_test/rest_test.module b/core/modules/rest/tests/modules/rest_test/rest_test.module index 7ee3aa6..197b82f 100644 --- a/core/modules/rest/tests/modules/rest_test/rest_test.module +++ b/core/modules/rest/tests/modules/rest_test/rest_test.module @@ -35,13 +35,14 @@ function rest_test_entity_field_access($operation, FieldDefinitionInterface $fie } /** - * Implements hook_entity_bundle_field_info_alter(). - * - * @see \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::setUp() - * @todo Remove this in https://www.drupal.org/node/2905890. + * Implements hook_entity_base_field_info(). */ -function rest_test_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) { - if (!empty($fields['rest_test_validation'])) { - $fields['rest_test_validation']->addConstraint('rest_test_validation', []); - } +function rest_test_entity_base_field_info(EntityTypeInterface $entity_type) { + $fields = []; + $fields['rest_test_validation'] = BaseFieldDefinition::create('string') + ->setLabel(t('REST test validation field')) + ->setDescription(t('A text field with some special validations attached used for testing purposes')) + ->addConstraint('rest_test_validation'); + + return $fields; } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 9517b62..cfa9d1a 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -180,26 +180,7 @@ public function setUp() { ->setTranslatable(FALSE) ->save(); - // Add field for testing validation. - // @see rest_test_entity_bundle_field_info_alter() - FieldStorageConfig::create([ - 'entity_type' => static::$entityTypeId, - 'field_name' => 'rest_test_validation', - 'type' => 'string', - ]) - ->setCardinality(2) - ->save(); - FieldConfig::create([ - 'entity_type' => static::$entityTypeId, - 'field_name' => 'rest_test_validation', - 'bundle' => $this->entity->bundle(), - 'description' => 'A text field with some special validations attached used for testing purposes', - ]) - ->setLabel('REST test validation field') - ->setTranslatable(FALSE) - ->save(); - - // Reload entity so that it has the new fields. + // Reload entity so that it has the new field. $this->entity = $this->entityStorage->loadUnchanged($this->entity->id()); // Set a default value on the field.