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.
Problem/Motivation
When trying to group aggregate on a field that isn't in all bundles, you get an error. " Fatal error: Call to a member function view() on a non-object in .../core/modules/views/src/Plugin/views/field/Field.php on line 822"
Proposed resolution
Check for the field before trying to access it's method (view).
Remaining tasks
1. Write a test.
2. Submit the patch.
3. Review.
User interface changes
none
API changes
none
Data model changes
none
Reproduction instructions
1. Create a new site based on 8.0.x (standard install).
2. Generate some content.
3. Import the test-aggregation-view.yml view.
4. Visit example.com/test-aggregation
uuid: ba25d54f-5130-4d7d-8f00-f584ab13e3df
langcode: en
status: true
... File attached ⩒⩒
Comment | File | Size | Author |
---|---|---|---|
#16 | interdiff.txt | 597 bytes | dawehner |
#16 | 2616816-16.patch | 5.93 KB | dawehner |
#14 | interdiff.txt | 1.49 KB | dawehner |
#14 | 2616816-14.patch | 6.19 KB | dawehner |
#11 | 2616816-11.patch | 6.1 KB | dawehner |
Comments
Comment #2
Jaesin CreditAttribution: Jaesin at Chapter Three commentedChecks for the field before accessing it.
Comment #3
Jaesin CreditAttribution: Jaesin at Chapter Three commentedComment #4
Jaesin CreditAttribution: Jaesin at Chapter Three commentedComment #5
Jaesin CreditAttribution: Jaesin at Chapter Three commentedI found another spot were the filed wasn't being checked for existence.
Comment #6
dawehnerWe need to document how this can happen ...
Pointless documentation.
You can make the code easier to read by just using if (!isset($field_item_list)) { return NULL; } and don't deal with an else at all
Comment #7
dawehnerComment #8
dawehnerWow, I would not have expected that its that hard to reproduce the problem with a normal field, not an image field.
This is still not failing.
Comment #9
Jaesin CreditAttribution: Jaesin at Chapter Three commentedTest ME!
Comment #11
dawehnerThere we go.
Comment #13
LendudeI don't think we should call the entity loaded here 'faked', that only goes for entities created by createEntityForGroupBy right?
missing docblock and maybe give some explanation as to what is being set up here.
Comment #14
dawehnerThank you for the review @Lendude!
Well, the method is quite self descriptive to be honest, but well, here is a one line comment.
Comment #15
LendudeDon't think the docblocks for methods are optional :)
sorry missed this the first time, don't think the image module is needed? Tests pass fine without it.
Comment #16
dawehnerFeel free to look at some examples in
\Drupal\Tests\UnitTestCase
:)Nor do I, good catch!
Comment #17
LendudeThis now looks good to me.
Comment #18
catchCommitted/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!