Problem/Motivation
Discovered via #2977848: Update to JSON API 1.20.
if ($target_entity === NULL) {
$host_entity = $parent->getHostEntity();
$relatable_resource_types = $resource_type_repository->get(
$host_entity->getEntityTypeId(),
$host_entity->bundle()
)->getRelatableResourceTypes()[$parent->getPropertyName()];
if (count($relatable_resource_types) !== 1) {
throw new \RuntimeException('Relationships to virtual resources are possible only if a single resource type is relatable.');
}
Having multiple vocabularies causes $relatable_resource_types['parent'] to have multiple resource types. But why?
Turns out that the parent field definition does NOT restrict the parent to be in the same bundle. That means that the Politics term from the Tags vocabulary could have BMW from the Cars vocabulary as its parent term. This of course makes zero sense.
Proposed resolution
- Work around this in the JSON API module.
- Fix it in Drupal core.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
Term entity type's parent field definition is now more precise.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | interdiff.txt | 698 bytes | wim leers |
| #5 | 2977879-5.patch | 2.67 KB | wim leers |
| #5 | interdiff.txt | 924 bytes | wim leers |
| #4 | 2977879-4.patch | 1.78 KB | wim leers |
Comments
Comment #2
wim leersComment #3
wim leersCore issue created: #2977882: Term entity type's "parent" field does not specify "target_bundles" setting: a term from *any* vocabulary can be chosen.
Comment #4
wim leersFailing regression test.
Comment #5
wim leersSolution, until #2977882: Term entity type's "parent" field does not specify "target_bundles" setting: a term from *any* vocabulary can be chosen lands.
Comment #6
wim leersNit: s/base/bundle/
Comment #7
gabesulliceRTBC on the assumption #4 will fail.
Comment #8
gabesullice#4 didn't fail :_(
Comment #9
wim leersAh, right, because the
parentfield is completely broken in 8.5.x. Only in 8.6.x (since #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration) does it work sanely.#4 should only fail on 8.6.x. (And #5 should pass.) Queued test against 8.6. Now there are the expected test failures :)
Comment #10
gabesulliceMakes sense. #4 does fail against 8.6.
Comment #11
wim leersFixed CS violation on commit.
Comment #13
wim leers#2977882: Term entity type's "parent" field does not specify "target_bundles" setting: a term from *any* vocabulary can be chosen landed! So I created #2980593: Follow-up for #2977879: remove work-around for #2977882 to stop applying the work-around on 8.6.
Comment #16
rpayanmMoving to Drupal core's issue queue.
I'm working on https://www.drupal.org/project/drupal/issues/3122113