Problem/Motivation
Found in #1853524: Reintroduce Views integration for Book that rendering fields using optional relationship does not work when the relationship does not exist.
Steps to reproduce:
- Add an article with one tag
- Add another article without tags
- Create a view of articles with page display
- Set page path to /test-page
- Add node title field "Content: title"
- Add a relationship using field_tags "field_tags: Taxonomy term" and do not check the "Require this relationship" checkbox
- Add term name field "Taxonomy term: Name"
- Save the view
- View /test-page.
Expected result: You should see two articles and one term
Actual result: Blank page with text "Fatal error: Call to a member function bundle() on a non-object in core/modules/views/src/Entity/Render/EntityFieldRenderer.php on line 203"
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#1 | 2534780-1.patch | 5.12 KB | olli |
#1 | 2534780-1-test.patch | 2.72 KB | olli |
Comments
Comment #1
olli CreditAttribution: olli commentedThis is almost the same fix as in #1853524-49: Reintroduce Views integration for Book and a small test.
Comment #2
olli CreditAttribution: olli commentedThis part is different from the interdiff.txt in #1853524-49: Reintroduce Views integration for Book.
Comment #4
dawehnerI'm a little bit confused about the test, because it does not use entities, so the fix in the entity related code will actually not run for those tests ...
Nitpick: I think we use an empty line before that.
Comment #5
olli CreditAttribution: olli commented#4: I'm trying to use that code by rendering user entity field here. Is there a better way to do that? Also, I wonder if we should explicitly set 'hide_empty' and 'required' to FALSE.
Comment #6
jibran#1 fixed the error for me in #2321721-67: Provide a views relationship for each dynamic entity reference field. Thank you @olli for finding and fixing this.
Comment #7
jibranIt is at least major if not critical because it's a very normal use case.
Comment #8
dawehnerOH I see, well it still feels better to start maybe with the entity_test table.
Comment #9
Tim Asplin CreditAttribution: Tim Asplin commentedHello,
Thanks for this, fixed same issue for me.
Had a view with an optional relation ship and was causing: Fatal error: Call to a member function bundle() on a non-object in core/modules/views/src/Entity/Render/EntityFieldRenderer.php
Thanks for the patch
Comment #10
dawehnerBut this way it actually even ensures that the other usescases work.
Comment #11
alexpott@olli nice find, nice fix and nice test. Committed 8ddd134 and pushed to 8.0.x. Thanks!