Skip to content

Commit

Permalink
Validate the --target-bundle option of field:create (#5116)
Browse files Browse the repository at this point in the history
  • Loading branch information
DieterHolvoet committed Apr 15, 2022
1 parent ed06117 commit 71dbbc6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Drupal/Commands/field/FieldCreateCommands.php
Expand Up @@ -429,6 +429,7 @@ protected function createField(): FieldConfigInterface

if ($targetTypeDefinition->hasKey('bundle')) {
if ($referencedBundle = $this->input->getOption('target-bundle')) {
$this->validateBundle($targetType, $referencedBundle);
$referencedBundles = [$referencedBundle];
} else {
$referencedBundles = $this->askReferencedBundles($field);
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/FieldTest.php
Expand Up @@ -37,9 +37,8 @@ public function testFieldCreate()
// New field storage
$this->drush('field:create', ['unish_article', 'alpha'], ['field-label' => 'Test', 'field-name' => 'field_test2', 'field-type' => 'entity_reference', 'field-widget' => 'entity_reference_autocomplete', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED], null, null, self::EXIT_ERROR);
$this->assertStringContainsString('The target-type option is required.', $this->getErrorOutputRaw());
/// @todo --target-bundle not yet validated.
// $this->drush('field:create', ['unish_article', 'alpha'], ['field-label' => 'Test', 'field-name' => 'field_test3', 'field-type' => 'entity_reference', 'field-widget' => 'entity_reference_autocomplete', 'cardinality' => '-1', 'target-type' => 'unish_article', 'target-bundle' => 'NO-EXIST']);
// $this->assertStringContainsString('TODO', $this->getErrorOutputRaw());
$this->drush('field:create', ['unish_article', 'alpha'], ['field-label' => 'Test', 'field-name' => 'field_test6', 'field-type' => 'entity_reference', 'field-widget' => 'entity_reference_autocomplete', 'cardinality' => '-1', 'target-type' => 'unish_article', 'target-bundle' => 'NO-EXIST'], null, null, self::EXIT_ERROR);
$this->assertStringContainsString("Bundle 'NO-EXIST' does not exist on entity type with id 'unish_article'.", $this->getErrorOutputRaw());
$this->drush('field:create', ['unish_article', 'alpha'], ['field-label' => 'Test', 'field-name' => 'field_test3', 'field-type' => 'entity_reference', 'field-widget' => 'entity_reference_autocomplete', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'target-type' => 'unish_article', 'target-bundle' => 'beta']);
$this->assertStringContainsString("Successfully created field 'field_test3' on unish_article type with bundle 'alpha'", $this->getErrorOutputRaw());
$this->assertStringContainsString("http://dev/admin/structure/unish_article_types/manage/alpha/fields/unish_article.alpha.field_test3", $this->getSimplifiedErrorOutput());
Expand Down

0 comments on commit 71dbbc6

Please sign in to comment.