Download & Extend

When the link URL is equal to page URL.

Project:Link
Version:7.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)

Issue Summary

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":

<?php
...
 
// 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
 
}
...
?>

Comments

#1

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.

#2

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);

#3

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.

#4

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 :)

AttachmentSize
link_active_class-1199806.patch 963 bytes

#5

Status:active» reviewed & tested by the community

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

#6

Status:reviewed & tested by the community» fixed

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

?? from June ... o.Ô

#7

Status:fixed» closed (fixed)

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

#8

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.

#9

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