Hi All,

When the link URl is equal to page URL, I get this fatal error:

Fatal error: [] operator not supported for strings in /home/ss81/EclipseWorkspace/pcms2011/includes/common.inc on line 2314

The reason of it is that function l() tries to expand link class with "active":

...
  // Append active class.
  if (($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) &&
      (empty($options['language']) || $options['language']->language == $language_url->language)) {
    $options['attributes']['class'][] = 'active'; <<< line 2314
  }
...
CommentFileSizeAuthor
#4 link_active_class-1199806.patch963 bytesss81

Comments

ss81’s picture

So far I found only this way to fix this:

### Eclipse Workspace Patch 1.0
#P ********
Index: sites/all/modules/contrib/link/link.module
===================================================================
--- sites/all/modules/contrib/link/link.module	(revision 254)
+++ sites/all/modules/contrib/link/link.module	(working copy)
@@ -64,7 +64,7 @@
   $form = array(
     '#element_validate' => array('link_field_settings_form_validate'),
   );
-  
+
   $form['validate_url'] = array(
     '#type' => 'checkbox',
     '#title' => t('Validate URL'),
@@ -665,6 +665,7 @@
  */
 function theme_link_formatter_link_default($vars) {
   $link_options = $vars['element'];
+  $link_options['attributes']['class'] = array($link_options['attributes']['class']);
   unset($link_options['element']['title']);
   unset($link_options['element']['url']);
   // Display a normal link if both title and URL are available.

But I think there should be better way.

ss81’s picture

Fixed patch:

### Eclipse Workspace Patch 1.0
#P ********
Index: sites/all/modules/contrib/link/link.module
===================================================================
--- sites/all/modules/contrib/link/link.module	(revision 270)
+++ sites/all/modules/contrib/link/link.module	(working copy)
@@ -64,7 +64,7 @@
   $form = array(
     '#element_validate' => array('link_field_settings_form_validate'),
   );
-  
+
   $form['validate_url'] = array(
     '#type' => 'checkbox',
     '#title' => t('Validate URL'),
@@ -667,6 +667,11 @@
   $link_options = $vars['element'];
   unset($link_options['element']['title']);
   unset($link_options['element']['url']);
+
+  if (isset($link_options['attributes']['class'])) {
+    $link_options['attributes']['class'] = array($link_options['attributes']['class']);
+  }
+
   // Display a normal link if both title and URL are available.
   if (!empty($vars['element']['title']) && !empty($vars['element']['url'])) {
     return l($vars['element']['title'], $vars['element']['url'], $link_options);

jcfiala’s picture

Wow, that's a pretty crazy error. Thanks for working on a patch.

Thing is, usually we upload a patch as a fire instead of including it like this. But, this is easier to read.

ss81’s picture

StatusFileSize
new963 bytes

Unfortunately yesterday I didn't have a time to checkout Link module from Git repository and make correct patch. So I made only a quick patch with SVN and posted it. Today I have a bit more free time, so I made it in correct way :)

acbramley’s picture

Status: Active » Reviewed & tested by the community

Very strange error, good work for finding it! Can confirm this patch fixes the problem

dqd’s picture

Status: Reviewed & tested by the community » Fixed

finally committed to latest --dev and pushed to repo. ss81++! ROCK!

?? from June ... o.Ô

Status: Fixed » Closed (fixed)

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

mikebell_’s picture

Status: Closed (fixed) » Active

Hi sorry to re-open this but this is causing the following error on our setup:

Notice: Array to string conversion in theme_link_formatter_link_default() (line 754 of /var/www/vhosts/nsacademynew.co.uk/www/sites/all/modules/link/link.module).

Removing array() fixes.

dqd’s picture

Status: Active » Postponed (maintainer needs more info)

@ digital006, can U provide more infos to what you think hay caused it exactly and why and what you have removed? Thanks

jkingsnorth’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (fixed)

No further information came back, and the original issue was fixed. So I'm going to close this old issue. Please open a new issue (and reference this one) if you are still experiencing the problem.