Undefined array key

250 views
Skip to first unread message

me&em design

unread,
Jun 20, 2022, 9:51:15 AM6/20/22
to Joomla! General Development
I'm working on upgrading a site from J3 to J4 and using the GiMeSpace Bootstrapped Menu module.

Everything appeared to be working fine until I upgraded the PHP to 8 and I'm now getting the following notification with Error Reporting set to - "System Default"

Warning: Undefined array key "class" in /Applications/.../modules/mod_gmsmenu4/tmpl/default_component.php on line 25

I did reach out to the GiMeSpace developer but haven't had a response and I'm guessing this might be resolved with a code tweak but while I can just about understand the principle of what might be happening by reading the PHP code I'm a bit clueless as to how to write it and wondered if there was anybody who could help?

The code is -

[code]

use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\HTML\HTMLHelper;

$attributes = array();

if ($item->level>1)
{
    $attributes['class'] .= 'dropdown-item ';
}
else
{
    $attributes['class'] .= 'nav-link ';
}

[/code]

I realise I could just set error reporting to "None" but it would be great if I can find a proper solution

Many thanks in advance

seraphim

unread,
Jun 20, 2022, 10:00:47 AM6/20/22
to joomla-de...@googlegroups.com
Try changing $attributes = array(); into $attributes = array('class' => '');

Or

remove the . in  $attributes['class'] .= 'dropdown-item '; so that $attributes['class'] = 'dropdown-item '; and $attributes['class'] = 'nav-link ';

Hope this helps

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/92d350e1-527d-42a6-a681-837a634ef3e2n%40googlegroups.com.


Hannes Papenberg

unread,
Jun 20, 2022, 10:01:43 AM6/20/22
to joomla-de...@googlegroups.com
If that really is the only code you have there, then you need to just
remove the . before the two =

Am 20.06.2022 um 15:48 schrieb 'me&em design' via Joomla! General
Development:
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to joomla-dev-gene...@googlegroups.com
> <mailto:joomla-dev-gene...@googlegroups.com>.
> <https://groups.google.com/d/msgid/joomla-dev-general/92d350e1-527d-42a6-a681-837a634ef3e2n%40googlegroups.com?utm_medium=email&utm_source=footer>.

me&em design

unread,
Jun 20, 2022, 2:48:47 PM6/20/22
to Joomla! General Development
Hi, Thanks for looking at this for me.

The think the array does more than the class? With this in mind am I ok to just remove the . ?

 The full code in the file reads as - 

use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\HTML\HTMLHelper;

$attributes = array();

if ($item->anchor_title)
{
    $attributes['title'] = $item->anchor_title;

}

if ($item->level>1)
{
    $attributes['class'] .= 'dropdown-item ';
}
else
{
    $attributes['class'] .= 'nav-link ';
}


if ($item->anchor_css)
{
    $attributes['class'] .= $item->anchor_css;
}


if ($item->anchor_rel)
{
    $attributes['rel'] = $item->anchor_rel;
}

if ($item->id == $active_id)
{
    $attributes['aria-current'] = 'location';

    if ($item->current)
    {
        $attributes['aria-current'] = 'page';
    }
}

$linktype = $item->title;

if ($item->menu_image)
{
    if ($item->menu_image_css)
    {
        $image_attributes['class'] = $item->menu_image_css;
        $linktype = HTMLHelper::_('image', $item->menu_image, $item->title, $image_attributes);
    }
    else
    {
        $linktype = HTMLHelper::_('image', $item->menu_image, $item->title);
    }

    if ($itemParams->get('menu_text', 1))
    {
        $linktype .= '<span class="image-title">' . $item->title . '</span>';
    }
}

if ($item->browserNav == 1)
{
    $attributes['target'] = '_blank';
}
elseif ($item->browserNav == 2)
{
    $options = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes';

    $attributes['onclick'] = "window.open(this.href, 'targetWindow', '" . $options . "'); return false;";
}

echo HTMLHelper::_('link', OutputFilter::ampReplace(htmlspecialchars($item->flink, ENT_COMPAT, 'UTF-8', false)), $linktype, $attributes);

Niels Braczek

unread,
Jun 20, 2022, 6:17:35 PM6/20/22
to 'me&em design' via Joomla! General Development
Hi,

> The think the array does more than the class? With this in mind am I ok to
> just remove the . ?
>
> The full code in the file reads as -

Since there are multiple conditional assignments to
$attributes['class'], follow seraphim's advice and change

$attributes = array();

into

$attributes = array('class' => '');

Regards,
Niels

me&em design

unread,
Jun 21, 2022, 3:54:48 AM6/21/22
to Joomla! General Development
Both ways seemed to fix the problem but as suggested i went with - 

$attributes = array('class' =>"");

Thanks for all your help - much appreciated

Reply all
Reply to author
Forward
0 new messages