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
49a45db6f8
commit
e60979f160
|
@ -176,6 +176,16 @@ class Term extends ContentEntityBase implements TermInterface {
|
||||||
return $fields;
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -72,6 +72,15 @@ class TermTest extends TaxonomyTestBase {
|
||||||
->save();
|
->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.
|
* Test terms in a single and multiple hierarchy.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue