致命错误:[include /common.inc中的字符串不支持[]运算符

问题描述:

I built a simple function to modify the default main menu style on Drupal.

But I am receiving the following error now, what am I doing wrong?

edit: I just identified the string that causes the error; $link['href']. But I need to get the links, I dont know how to make it work...

function corporate_links__system_main_menu($variables) {
  $html='<li>
            <a href="#" class="button holdmecloser_btn white_f btn-hasdd">
                <span class="ico-arrow-white">'.t('sections').'</span>
            </a>
            <div class="sub">
                <ul class="holdmecloser_bg white_f">';
                foreach ($variables['links'] as $link) {
                   $html .= '<li>'.l($link['title'], $link['href'], array('attributes' => array('class' => 'white_f'))).'</li> <!--<li><a href="" class="white_f">home</a></li>-->';
                 }  
                $html .= '</ul>
            </div>
        </li>';

  return $html;
}

Turns out, class attributes must be an array in Drupal 7. Changing the following line fixed my problem

wrong

           $html .= '<li>'.l($link['title'], $link['href'], array('attributes' => array('class' => 'white_f'))).'</li> <!--<li><a href="" class="white_f">home</a></li>-->';

correct

$html .= '<li>'.l($link['title'], $link['href'], array('attributes' => array('class' => array('white_f')))).'</li>';

If you just want to add attributes to your main menu items, why not use menu attributes module?