Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This module requires a one line core patch in order to function. It is attached to this issue: https://www.drupal.org/files/issues/2019-07-24/no-bundle-filter-when-bun...
Let's brainstorm a way around it or create upstream issues to make it obsolete.
Comment | File | Size | Author |
---|---|---|---|
#21 | interdiff-21.patch | 1.67 KB | dawehner |
#21 | 3070199-21.patch | 9.9 KB | dawehner |
#18 | 3070199-WIP-18.patch | 8.23 KB | mglaman |
#17 | 3070199-WIP-17.patch | 8 KB | mglaman |
#15 | Screen Shot 2019-10-31 at 8.40.20 AM.png | 328.69 KB | mglaman |
Comments
Comment #2
gabesullicePrior to https://git.drupalcode.org/project/jsonapi_cross_bundles/commit/093b893a... this module did not need a core patch. However, that meant that the amount of JSON:API code that needed to be overridden was significant. A non-trivial amount of code had to be copied, pasted, and tweaked.
After that commit, it's not necessary to copy/paste/tweak JSON:API code, it can just be decorated. That comes at the cost of requiring the attached core patch.
I do no think the attached core patch is the "right" way to accommodate this module. Instead, I think JSON:API's
FieldResolver::resolveInternalEntityQueryPath($entity_type_id, $bundle, $external_field_name)
should be refactored to accept a resource type instead of an entity type ID and bundle ID, i.e.FieldResolver::resolveInternalEntityQueryPath(ResourceType $resource_type, $external_field_name)
.I'll see if I can come up with a nice patch that does that. If so, I'll create a core issue and reference this issue.
Comment #3
gabesulliceAs promised in #2, see #3070204: Refactor the JSON:API FieldResolver to use a resource type instead of an entity type ID and bundle ID pair.
With that patch applied, the patch on this issue isn't required and
CrossBundleResourceType::getBundle()
can returnNULL
again.Comment #4
gabesulliceComment #5
mglamanAdded link to the patch again in the summary.
So:
1. Commit made to this module to reduce boilerplate code
2. The quick fix is the one-line patch
3. The full fix is to tackle #3070204: Refactor the JSON:API FieldResolver to use a resource type instead of an entity type ID and bundle ID pair
4. Then #3031173: FieldResolver::resolveInternalEntityQueryPath should accept an array of resource types, not a single resource type (which is in the contrib queue not core?)
Correct?
Comment #6
gabesullice@mglaman, 1-3 is correct. 4 is in the right place, but it's not required for this module.
The "array of resource types" #4 mentions was my early idea for what this module calls a
CrossBundleResourceType
. I think that issue will become more important when/if we decide to make cross bundle collections part of core, but it's not important for this module right now.Comment #7
mglamanCool :) Thanks @gabesullice
Comment #8
Wim Leers#3070204: Refactor the JSON:API FieldResolver to use a resource type instead of an entity type ID and bundle ID pair landed! 🥳
Comment #9
dawehnerI tried to use the module with 8.8. @mglaman pointed me to this issue, thank you!
When trying to use this I run into:
After talking with @Wim Leers we figured out this is caused by the BC layer in
\Drupal\jsonapi\ResourceType\ResourceType::updateDeprecatedFieldMapping
. The problem in there is caused by the old problem that field definitions are per bundle. The patch I've attached copies the core function for now into\Drupal\jsonapi_cross_bundles\ResourceType\CrossBundlesResourceType
to see whether wecan use a superset somehow, see patch.
Comment #10
mglamanIf the only change here is to pass NULL or not, should we just handle that in updateDeprecatedFieldMapping so that we don't need to override the constructor?
We can have this assert $bundle is NULL, or make it be null. Since we know this class expects it to be null.
Wait. I actually have a better idea. Let's make
updateDeprecatedFieldMapping
a no-op in our class. Override the parent so it does nothing.We then update the deprecated method in \Drupal\jsonapi_cross_bundles\ResourceType\CrossBundleResourceTypeRepository::all for our resource type. Then there's no need to update deprecated values.
Comment #11
dawehnerNote: This patch doesn't take into account comment 10 yet, sorry :)
I tried to implement generating a superset of all the field definitions, see interdiff. This resulted in another problem:
Comment #12
mglamanSo in my debugging, the error comes from ResourceTypeRelationship
For me this errors when trying to get the relationship to
commerce_product_variation_type
, as I"m testing on my Commerce install.This module was written before ResourceTypeRelationship was introduced.
Comment #13
dawehnerThis addresses the comments of @mglaman in comment number 10.
Comment #14
mglamanIf \Drupal\jsonapi_cross_bundles\ResourceType\CrossBundleResourceTypeRepository::all is updated to use getFields, this is never invoked. Which means the processing can all live in CrossBundleResourceTypeRepository, still.
$field_mapping_superset should be a grouped array of each bundle's relationship resources.
Comment #15
mglamanHere's my go.
The problem is \Drupal\jsonapi_cross_bundles\ResourceType\CrossBundleResourceTypeRepository::getFieldMappingSuperset returns relationship resources with no related resource types set.
😬yeah, \Drupal\jsonapi\ResourceType\ResourceTypeRepository::getFields is returning relationship resources without related types set, even though we pass in a valid resource type with a bundle.
Comment #16
mglamanDrupal core has a bug in \Drupal\jsonapi\ResourceType\ResourceTypeRepository::getFields.
In the following code, it never sets the relatable types for ResourceTypeRelationship, if it is used. That's why we crash.
Actually, this identifies where the bug might keep going.
In
setRelatableResourceTypes
it should set the relatable types for all ResourceTypeRelationship.So we might need to fix \Drupal\jsonapi_cross_bundles\ResourceType\CrossBundleResourceTypeRepository::getRelatableResourceTypesSuperset
Comment #17
mglamanOkay, this fixes errors when building caches. I need to run for an appointment, let's see what the test suite says.
Comment #18
mglamanFix param conversion.
Comment #19
dawehner@mglaman Thanks a lot! Manually testing this patch worked great!
Comment #20
mglamanGreat! The tests just need to be updated for the new route name
Comment #21
dawehnerThis should resolve the test failures.
Comment #22
mglamanRenaming the issue. It's more than just a patch. Cleaned up the resource name and how we calculated related resources.
Comment #23
Wim LeersExciting to see this green! 🥳
Comment #25
mglaman🙌committed! thanks for the assist @dawehner
Comment #26
dawehnerThank you @mglaman!