anydigital / drupal-tweme

Ultra lightweight Bootstrap theme for Drupal.
https://www.drupal.org/project/tweme
62 stars 9 forks source link

Fatal error: [] operator not supported for strings #32

Open tonystar opened 9 years ago

tonystar commented 9 years ago

Fatal error: [] operator not supported for strings in /tweme/template.php on line 111

acondura commented 9 years ago

Hi Tony,

I left a comment in the commit too and I believe I've just fixed this issue.

The problem happens when using Panels IPE. If you look into file panels/panels_ipe/panels_ipe.module at lines 139 and 204, you’ll see that only line 139 adds a class as a string instead of an array.

So, I changed the code so that it first checks whether $vars[‘attributes’][‘class’] is an array. If it holds a string, then turn it into an array, add the existing class and then continue with adding the ‘list-unstyled’ class.

I ran into this issue on my own website (condurachi.ro) and I thought I’d give a helping hand. I really like your theme.

Regards, Andrei

acondura commented 9 years ago

I tried syncing my commit to your repo but it looks like I don't have the right permissions. Here's the code change that I did to solve the issue:

function tweme_preprocess_links(&$vars) {

Check if the class value is not an array

if(!is_array($vars['attributes']['class'])) {

Hold the existing value in variable

$temp_value = $vars['attributes']['class'];
# Transform the class to an array
$vars['attributes']['class'] = array();
# Add the existing value to the class array
$vars['attributes']['class'][] = $temp_value;

} $vars['attributes']['class'][] = 'list-unstyled'; }