Closed (fixed)
Project:
Drupal core
Version:
10.1.x-dev
Component:
views.module
Priority:
Major
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 Apr 2021 at 20:59 UTC
Updated:
30 Jan 2023 at 15:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
daffie commentedComment #4
kapilv commentedComment #5
kapilv commentedComment #6
daffie commented@KapilV: Thank you for working on this issue. Could you in the future when an issue the new merge request (MR) functionality, add your changes to that MR and not add a patch file. The changes are between the MR and a patchfile are difficult to follow.
Comment #7
lendudeSounds like a fair request to me.
Already looks pretty good, mostly wondering about the test coverage here. We currently only test that the hook is being called, but since we are not using the out of the box _alter functionality here (and it makes sense not to), should we not add a test to see that we can actually alter the Views data using the hook and that the expected order of calls is being maintained (so normal alter first, then the driver provider alter)
Comment #8
daffie commented@Lendude: Thank you for your review! I have added the requested improvements for the testing.
Comment #9
lendudeNothing more to add from my end, looks good.
Comment #10
jibranWhy are we doing it on ViewsData level? Why can't we do it in views query plugin? Or in the views relationship plugin?
Comment #11
daffie commentedWhen a user builds a view in the browser, he or she does so from the entity perspective. The ViewsData is the translation layer between the entity perspective and the database table structure in which the data is stored in the database. When a view is executed the views query plugin collects and combines all the query parts from all the used views handlers. The handlers use the ViewsData build their part of the query. It is designed in this way to make a very complicated process maintainable and extensible for programmers. Moving the required changes to the ViewsData for the MongoDB database driver to the views query plugin or the views relationship plugin would making the maintainability and the extensibility of the views module for MongoDB a lot harder if not almost impossible.
Comment #12
jibran...and the *SQL* database table structure...in the *SQL* database. Views in cores has a lot of
SqlEntityStorageInterfacechecks.Harder yes but not impossible, but the way it is done in the Views module is already harder, query, join, and relationships plugins. If that is still too hard then why not override
views.views_dataservice and extend\Drupal\views\ViewsData.IMO the problem is the following change:
As you pointed out
ViewsDatais a map IOW a domain object and adding DB connection changes it form that.Setting it to NR for more discussion. @Lendude what do you think about this point?
Comment #13
daffie commentedYes, overriding the
views.views_dataservice and extending\Drupal\views\ViewsDatais also an option. To me the MR is a cleaner solution, in line with how the views module works and that is why I would like it committed to core.@jibran: What does "map IOW a domain object" mean? And what does "IOW" stand for?
Comment #14
jibranViewsDataholds the mapping between entity fields and DB tables & columns (along with plugin info) butViewsDatais just a domain object which means implementation details doesn't matter so instead of injecting DB connection it should be extended to accommodate the requirements of the other DB driver.Comment #16
lendudeHmm looking at this again, I'm going to agree with @jibran on this. I do agree that using a hook is cleaner than overriding views.views_data, but injecting the DB connection does feel like a bit too much to accomplish this.
Overriding views.views_data also allows you to act on any joins done in
\Drupal\views\ViewsData::processEntityTypeswhich the hook currently misses.The old skool solution of giving you module a big weight would probably also work to ensure you are altering last, but that feels even less clean than the other options.
Comment #20
daffie commentedLets do the by @jibran in comment #12 suggested solution and backend override the 'views.views_data' service.
A good example how to fix this is in #3209931: The service "cache_tags.invalidator.checksum" and the service "cache.backend.database" should be backend_overridable.
Comment #21
arantxioPer request of @daffie, I've created a patch for the suggestions posted in comment #12.
And i've added a new file which tests the added tag.
Comment #22
nitin shrivastava commentedfix ccf error #21
Comment #23
nitin shrivastava commentedSorry for the wrong patch
Comment #25
daffie commentedI do not know why this change was added, but it can be removed.
Comment #26
arantxio@nitin Thank you for the patch, as I had to travel I haven't seen that it failed on the check.
Few things I would like to comment on is the following:
This part is not necessary and should not be added to the patch. If it is due to your project setup please try to remove it before posting the patch.
Comment #27
arantxioI've removed the subproject part of the patch.
Comment #28
daffie commentedThe chosen solution is the one from @jibran (comment #12).
The service
views.views_datais now backend overridable.There is testing added.
I have updated the IS and the CR.
For me it is RTBC.
Comment #29
daffie commentedComment #30
quietone commentedJust a small thing.
The service name should be lower case, "views.views_data".
Comment #31
arantxioI've made the service name lower case.
@quietone thank you for your comment.
Comment #32
daffie commentedThe remark of @quietone has been addressed.
Back to RTBC.
Comment #35
xjmI was not familiar with this service tag, but the change record on backend-overridable services explains it quite well. The feedback from @Jibran and @Lendude was quite helpful, and @Lendude's signoff as a subsystem maintainer lends credence to this being the correct approach. I also made some improvements to the change record to better explain the purpose of this change (and to reference the original CR on the service tag).
I closed the MR since it was for a previous approach that is no longer used.
I made the following small grammar fixes on commit:
I removed credit for the broken patch from @Nitin shrivastava (since they were not able to come back and post a fixed version). If you need assistance with the patch creation process, I recommend the
#contributechannel in the Drupal community Slack.I also removed credit for the patch when an MR already existed from @KapilV. It's important to read the issue carefully and build on the work of other contributors, rather than attaching patches that fragment the review process and do not build on the work of previous contributors.
Committed #31 to 10.1.x, and published the change record. Thanks!