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 is a follow-up for #2113345, see #2113345-129: Define a mechanism for custom link relationships:
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -340,4 +356,35 @@ public function calculateDependencies() { + $relationship = $relation_name; + if (!empty($definition['uri'])) { + $relationship = $definition['uri']; + }
Would be nice to use the interface here instead of the definition array. But that requires instantiating the plugin, which maybe has a performance cost that needs to be looked at. Which is why I'm ok punting it to a follow-up.
Comment | File | Size | Author |
---|---|---|---|
#15 | 2848927-15.patch | 3.32 KB | Wim Leers |
Comments
Comment #2
Wim LeersComment #3
Wim LeersWe should update
EntityResourceTestBase
in a similar way.Comment #4
Wim LeersNobody picking up novice tasks, so then just getting this done.
Comment #5
tedbowTest coverage shows a new better way of getting $expected_link_relation_headers but tests still pass so looks good to me! RTBC!
Comment #6
xjmLooks like it needs a reroll. Thanks!
Comment #7
Wim LeersRerolled. Conflicted with #2852992: EntityResourceTestBase: only assert presence of Link headers for entity types that have link templates. Trivial conflict :)
Comment #8
alexpottFrom the issue summary:
As far as I can see there's no comment that addresses this - is it a concern?
Comment #9
Wim LeersREST API performance is not superb, but that's pretty much entirely due to D8's routing and bootstrap (instantiating many services) being so expensive. Not to mention that in this case (a
GET
request for an entity resource), we have to run entity access and field access.Besides, the changes only result in very thin value objects being created: see
\Drupal\Core\Http\LinkRelationType
.In other words: any performance cost here, which is likely negligible, is absolutely dwarfed by the already poor performance in all other aspects of serving a
GET
entity resource request.@effulgentsia wrote #2113345: Define a mechanism for custom link relationships). It wasn't. The reason it didn't happen there was because it was simply overlooked in earlier patch iterations.
— emphasis mine. He thought that might be the reason for not doing that just yet in the original issue (Finally, benchmarks (not profiling) to back up my argument above:
Comment #11
Wim LeersRandom fail in
FormErrorHandlerCKEditorTest
, which is completely unrelated.Comment #12
alexpottThis should be ->hasDefinition() no?
Comment #13
alexpottOh and @Wim Leers thanks for the performance numbers.
Comment #14
Wim LeersGlad they were useful! :)
Comment #15
Wim Leers#12: nice little catch. I wonder how we missed that so far. Anyway, trivial fix :)
Comment #16
tstoecklerRTBC++
Comment #17
alexpottCommitted 7cad23a and pushed to 8.4.x. Thanks!
Credited myself as a reviewer because my feedback affected the code in the patch.