In short, this code works if I create a php field in a view:

$options = array('query'=>array('viewer' => $row->uid), 'attributes'=>array('title'=>'Share this'));
$link = l('share', 'node/' . $view->args[0], $options );
print $link;

But, if I try to add a class field to the attributes array:

$options = array('query'=>array('viewer' => $row->uid), 'attributes'=>array('class'=>'share', 'title'=>'Share this'));
$link = l('share', 'node/' . $view->args[0], $options );
print $link;

I get this error:

Fatal error: [] operator not supported for strings in /home/content/97/9512397/html/includes/common.inc on line 2353

This seems to be caused by your module as this bug report suggests http://drupal.org/node/1650762

Comments

NoRandom’s picture

Extra information:

The problem seems to be related to the fact that the created link could already have, under certain circumstances, other classes (i.e. "active" if the link leads to the same url you're viewing).

In case someone needs a workaround while the bug is solved, you can alter the link after it's created for adding your extra classes:

$link = str_replace('class="', 'class="extra_classes_here ', $link); 
sirajs’s picture

I had this problem when trying to use the following on a node that wasn't a in the teaser viewmode:

l(t('Read More'), 'node/' . $nid, array('attributes' => array('class' => t('read-more'))));

In my case, at least, my suspicion is that this is because the attribute is not defined outside of the context of a teaser.

ecommercium’s picture

Priority: Normal » Critical
Status: Active » Needs review

Hi,
I just deleted the [] in $options['attributes']['class'][] = 'active'; (#2358 in common.inc. But, this is a workaround for me and should not have to edit things in core!
Can someone have a look at this? I had this after my site upgrade to 7.16 from .15 and had 'fixed' it in that too!
Cheers!

ttkaminski’s picture

Status: Needs review » Closed (works as designed)

Please read the documentation. The class attribute must be an array. See this comment for a good example.