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.
When
- rendering the cart block as a Display Suite field and
- having set the block to hide if empty
I get a fatal error.
This is because Display Suite uses Drupal\Core\Render\Element::isEmpty to check if the block is empty or not. However, uc_cart returns a NULL value if the block is empty, but Drupal\Core\Render\Element::isEmpty only accepts arrays.
Can we apply this minor change? to fix it and make uc_cart align with Drupal\Core\Render\Element::isEmpty ?
Comment | File | Size | Author |
---|---|---|---|
#2 | 2848895-2.patch | 1.21 KB | TR |
| |||
block_empty.patch | 352 bytes | bjaxelsen | |
|
Comments
Comment #2
TR CreditAttribution: TR commentedYes, this doesn't have anything to do with Display Suite per se, that just exposed the problem. The problem is that the build() method of a block is typed to return an array and we don't do that in the case you describe. See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Block%21B...
I changed your patch and added comments - it does the same thing but I think it's easier to read this way so there's less likelihood that someone will "optimize" the code and remove this fix.
We do have a test to ensure the hide when empty functionality works, but I guess Drupal core doesn't care if the return value is NULL or array().
Comment #4
TR CreditAttribution: TR commentedThanks for finding this. Committed #2.
Comment #5
bjaxelsen CreditAttribution: bjaxelsen commentedThanks :)
(and I agree about the code readability)