Problem/Motivation
Some views are not over entities. The 'Entity' row display for REST views still allows itself to be added to them, it just breaks.
Steps to reproduce:
- Enable the REST module
- Create a view over 'Log entries', and provide a REST export display. Hit Save. See NewView.png
- Notice that the new view uses the 'Entity' row display, and yields an error. See ViewError.png
Without an actual entity, QueryPluginBase::getEntityTableInfo() finds nothing, and no base fields are added. So there's no fields at all, and the query breaks.
Proposed resolution
Solution: use hook_views_plugins_row_alter() and add all entity base tables to data_entity][base. (Per @dawehner, see #5.)
This is not the most elegant solution, but it retains BC. The "proper" solution will have to wait for D9. We should open a new issue for that proper D9 solution and add a @todo to the hook_views_plugins_row_alter() implementation pointing to that issue.
The proper D9 solution:
DataEntityRowshould filter by entity type (or rather, by the base table). This probably means making it a derived plugin. Just like\Drupal\views\Plugin\views\row\EntityRowusesderiver = "Drupal\views\Plugin\Derivative\ViewsEntityRow", we'd need pretty much the same forDataEntityRow.
While we're at it, we might want to make DataEntityRow and EntityRow both inherit from a TranslatedRowPluginBase. That would save a bunch of boilerplate (eg: for EntityTranslationRenderTrait), and they could probably use the same deriver too.
Remaining tasks
| Task | Novice task? | Contributor instructions | Complete? |
|---|---|---|---|
| Create a patch | Instructions | ||
| Add automated tests | Instructions |
User interface changes
Minimal. Only the default row will change for new REST export views on non-entities, but that's broken anyway. We might decide to change the displayed row plugin name from 'Entity' to eg: 'User', 'Node', etc.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | 2666226-drupal-9-45.patch | 6.41 KB | rafmagsou |
| #44 | 2666226-drupal-9-38.patch | 2.89 KB | rafmagsou |
| #37 | interdiff-2666226-26-37.txt | 3.82 KB | jacobsanford |
| #37 | 2666226-37.patch | 6.4 KB | jacobsanford |
| #26 | 2666226-26.patch | 6.36 KB | vasi |
Comments
Comment #2
vasi commentedComment #4
wim leersIf we want this, then this should be blocked on #2664880: DataEntityRow doesn't respect translations (which I just RTBC'd, yay!).
But I think this can continue regardless in the mean time, because the bulk of the work can still be done.
Thanks for the great bug report! Updated the issue summary's proposed resolution with some more details.
Comment #5
dawehnerTo be honest I disagree with the solution in the issue summary as it would require a BC breaking change. It would certainly require an update of existing views, which we better avoid if possible.
An alternative approach is to use
hook_views_plugins_row_alter()and add all entity base tables todata_entity][base.Comment #6
wim leersOhhh, I like that idea! I was also concerned about the BC break, and first wrote a comment explaining how I didn't see how that could work, but then I saw it, and couldn't see a better way.
So, I guess, #5 is the recommended solution because no BC break, but for D9, we'd want to do it in the way described in the IS?
Comment #7
dawehnerYeah I think so. It provides a better UX (as it has a better label) and it provides more semantic information in the configuration. It also allows specialized plugins per entity type, even we should avoid that.
Comment #8
wim leersAlright, cool. Updated IS accordingly.
Comment #9
wim leersForgot to update the and sections.
Comment #10
dawehnerThank you wim!
Comment #11
dawehnerHere is a quick try.
Comment #12
wim leersManually tested.
Finally, this probably needs an integration test? That would:
/admin/structure/views/addView::load(), inspect therest_export_1display's[display_options][row][type]Comment #13
dawehnerThank you for the manual test
Oh I see, so this is about the wizard part as well.
Comment #14
geertvd commentedAdded tests and made sure the default row type was not set to
data_entityfor non-entities.Comment #17
geertvd commentedThis one should be better
Comment #18
dawehnerNice test!
Comment #19
alexpottNeeds a reroll.
Comment #20
geertvd commentedComment #21
dawehnerThank you @geertvd!
Comment #22
catchInstead of three lines of logic in a hook implementation, we have one line, then 15 lines of boiler plate in the class, so we can call a method from the hook implementation that contains the three lines. Really?
Also, can we not do the original solution in 8.x? We could add new plugins, deprecate the old ones, hide them in the UI, keep them around for bc for exported Views, and potentially even do the upgrade path for non-exported views. And then even later add deprecation notices for the old plugins to inform people they need to update their Views in preparation for 9.x
Comment #23
wim leersInteresting. Assigning to @dawehner, this is more Views than it is REST. I think this makes it no longer novice.
Comment #24
catchTwo clarifications on #22:
1. If this was complex and/or needed unit testing, then I could see the case for taking the logic out of the hook implementation into a class, neither is the case here though.
2. We don't necessarily have to do that fix here, but it seems worth exploring whether it's possible since it could apply to more things later on, and worth trying in a follow-up.
Comment #25
dawehnerWell yeah I'm following this pattern on custom module development, as it enables you to actually do TDD, which well, at the end of the day, doesn't require you to keep the tests around.
Well we could try that fix together with an update path. The more you talk about it, the more I'm convinced of the other solution not really being a BC break.
Comment #26
vasi commentedHere's an attempt at the original deriver-based solution. We keep around data_entity for BC, but mark it no_ui.
Notes:
* Our deriver is a lot of boilerplate, any way to shrink that?
* No update hook yet
* It will look a bit weird if you try to edit the row style on an existing view, because the currently selected row style will not be available for selection
* Probably more tests are needed
Comment #28
dawehnerWhat happens if you go to the UI, don't the radio than not has this value and you get a form validation error?
Comment #29
wim leersComment #31
wim leersComment #32
wim leersAlso, I wonder if this is the root cause of #2858814: REST views: fatal error when using row plugin and Views is aware of non-Entity-based tables.
Comment #33
wim leersI think #2858814: REST views: fatal error when using row plugin and Views is aware of non-Entity-based tables may be a duplicate of this.
Comment #34
wim leersApparently I already said that in #32.
Comment #37
jacobsanford@vasi's patch in #26 no longer applied to 8.6.x. A reroll with no further modifications is attached - comments in #28 still not addressed.
Comment #44
rafmagsou commentedJust adaptation to the patch works on drupal 9 update
Comment #45
rafmagsou commentedComment #49
larowlanMarked #2858814: REST views: fatal error when using row plugin and Views is aware of non-Entity-based tables as a dupe and transferred credit
Can we get an issue summary update of what's left here - looks like #28?