Commit e60979f1 authored by catch's avatar catch

Issue #2977882 by Wim Leers: Term entity type's "parent" field does not...

Issue #2977882 by Wim Leers: Term entity type's "parent" field does not specify "target_bundles" setting: a term from *any* vocabulary can be chosen
parent 49a45db6
......@@ -176,6 +176,16 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
return $fields;
}
/**
* {@inheritdoc}
*/
public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
// Only terms in the same bundle can be a parent.
$fields['parent'] = clone $base_field_definitions['parent'];
$fields['parent']->setSetting('handler_settings', ['target_bundles' => [$bundle => $bundle]]);
return $fields;
}
/**
* {@inheritdoc}
*/
......
......@@ -72,6 +72,15 @@ protected function setUp() {
->save();
}
/**
* The "parent" field must restrict references to the same vocabulary.
*/
public function testParentHandlerSettings() {
$vocabulary_fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('taxonomy_term', $this->vocabulary->id());
$parent_target_bundles = $vocabulary_fields['parent']->getSetting('handler_settings')['target_bundles'];
$this->assertIdentical([$this->vocabulary->id() => $this->vocabulary->id()], $parent_target_bundles);
}
/**
* Test terms in a single and multiple hierarchy.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment