Chris@0: createVocabulary(); Chris@0: $vocabulary2 = $this->createVocabulary(); Chris@0: Chris@0: $term = $this->createTerm($vocabulary); Chris@0: $term2 = $this->createTerm($vocabulary2); Chris@0: Chris@0: // Create an entity reference field. Chris@0: $field_name = 'taxonomy_' . $vocabulary->id(); Chris@0: $field_storage = FieldStorageConfig::create([ Chris@0: 'field_name' => $field_name, Chris@0: 'entity_type' => 'entity_test', Chris@0: 'translatable' => FALSE, Chris@0: 'settings' => [ Chris@0: 'target_type' => 'taxonomy_term', Chris@0: ], Chris@0: 'type' => 'entity_reference', Chris@0: 'cardinality' => 1, Chris@0: ]); Chris@0: $field_storage->save(); Chris@0: $field = FieldConfig::create([ Chris@0: 'field_storage' => $field_storage, Chris@0: 'entity_type' => 'entity_test', Chris@0: 'bundle' => 'test_bundle', Chris@0: 'settings' => [ Chris@0: 'handler' => 'default', Chris@0: 'handler_settings' => [ Chris@0: // Restrict selection of terms to a single vocabulary. Chris@0: 'target_bundles' => [ Chris@0: $vocabulary->id() => $vocabulary->id(), Chris@0: ], Chris@0: ], Chris@0: ], Chris@0: ]); Chris@0: $field->save(); Chris@0: Chris@0: $handler = $this->container->get('plugin.manager.entity_reference_selection')->getSelectionHandler($field); Chris@0: $result = $handler->getReferenceableEntities(); Chris@0: Chris@0: $expected_result = [ Chris@0: $vocabulary->id() => [ Chris@0: $term->id() => $term->getName(), Chris@0: ], Chris@0: ]; Chris@0: Chris@0: $this->assertIdentical($result, $expected_result, 'Terms selection restricted to a single vocabulary.'); Chris@0: } Chris@0: Chris@0: }