When displaying responsive ad units, the following PHP notices are displayed:

Notice: Undefined index: #width in Drupal\adsense\AdsenseAdBase->display() (line 89 of modules/contrib/adsense/src/AdsenseAdBase.php).
Notice: Undefined index: #height in Drupal\adsense\AdsenseAdBase->display() (line 90 of modules/contrib/adsense/src/AdsenseAdBase.php).
CommentFileSizeAuthor
#2 undefined_indexes_in-2715019-2.patch693 bytesmalcomio

Comments

malcomio created an issue. See original summary.

malcomio’s picture

Status: Active » Needs review
StatusFileSize
new693 bytes

  • jcnventura committed e71149a on 8.x-1.x authored by malcomio
    Issue #2715019 by malcomio: Undefined indexes in Drupal\adsense\...
jcnventura’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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

pjeutr’s picture

Seems the #format index also needs to be checked.
I got

Notice: Undefined index: #format in Drupal\adsense\AdsenseAdBase->display() (line 88 of modules/adsense/src/AdsenseAdBase.php).

Adding the next line, solves it (Same solution as previous patch)

'#format' => isset($content['#format']) ? $content['#format'] : NULL,

jcnventura’s picture

How can you not have a format defined? What kind of ad is that?

pjeutr’s picture

In the block settings I chose:
Ad format -> Responsive ad unit
Responsive ad shape -> Auto sizing
Ad alignment -> Centered

I was using an autosize ad, this is the code google suggests

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- auto_size -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-1"
     data-ad-slot="1"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
pjeutr’s picture

I just used the same ad block within another site in the same codebase (multisite) without any problems.
The site where the problem occurs is a migrated site form D6 to D8. So I suppose the problem is caused by something else.
I will try to look in it later, just ignore me for now ;)