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 ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bjaxelsen created an issue. See original summary.

TR’s picture

Priority: Normal » Minor
FileSize
1.21 KB

Yes, 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().

  • TR committed 578d257 on 8.x-4.x authored by bjaxelsen
    Issue #2848805 by bjaxelsen, TR: Empty cart causes fatal error
    
TR’s picture

Status: Needs review » Fixed

Thanks for finding this. Committed #2.

bjaxelsen’s picture

Thanks :)

(and I agree about the code readability)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.