When a block-field's implementation of hook_block_view() returns an empty array, Display Suite generates a PHP notice "Notice: Undefined index: content in ds_render_block_field() (line 949 of .../ds/ds.module)."

Returning an empty array is supported by core and documented.

CommentFileSizeAuthor
#3 1292324-undefined-index-content.patch877 bytesBevan

Comments

swentel’s picture

luco’s picture

oh ok. I searched by the error message text and was unable to find anything.

thanks!

Bevan’s picture

Version: 7.x-1.3 » 7.x-2.6
Issue summary: View changes
Status: Closed (duplicate) » Needs review
StatusFileSize
new877 bytes

The attached patch fixes the issue by including it inside the subsequent if-clause that checks isset($block['content']) as well as pre-existing is_array($block['content']), and merging the remaining checks for $contextual and isset($block['content']['#contextual_links']) into a single if-clause.

The patch was rolled on 2.4 but I expect will apply fine to 2.6.

aspilicious’s picture

Status: Needs review » Postponed (maintainer needs more info)

A patch has been committed. Can you try latest dev and see if your patch is still needed.

Bevan’s picture

Status: Postponed (maintainer needs more info) » Needs review

Ah I see! I should have checked 7.x-2.x-dev first. I only checked 7.x-2.6.

I didn't test the code but I can see by reading it that it is fixed because ds_render_block_field() now checks isset($block['content']) before is_array($block['content']).

FYI, the patch takes this a step further by de-duplicating the two occurrences of isset($block['content']) && is_array($block['content']) and merging the remaining if (isset($block['content']['#contextual_links'])) and if ($contextual) clauses into one if clause.

I have set this back to "Needs review" in case you want to do that refactoring, but I am equally happy to close this as duplicate or fixed.

FWIW, #1279478 from comment #1 did not fix this issue.

aspilicious’s picture

Status: Needs review » Closed (duplicate)

Duplicating, not going to fix that now. :)

dent_arthur_dent’s picture

For me, this was happening when I entered something into the search field on my home page so I'm assuming it was trying to render a DS layout before it was defined. My error happened at line 878. What I did to eliminate the error is to add a condition in the IF statement prior to the other conditions to ensure that "$block['content']" was set.

Original line of code:
if (is_array($block['content']) && isset($block['content']['#contextual_links'])) {

My line of code:
if (isset($block['content']) && is_array($block['content']) && isset($block['content']['#contextual_links'])){

I hope that helps some folks out.

Cheers!