Hi,

I've set id and class on menu-items using Menu attributes module, and it seems like Superfish overwrites any attributes set by this module. This was not the case with previous version 1.8-alpha version of Superfish.

Comments

mehrpadin’s picture

Status: Closed (fixed) » Active

Fixed as of version 1.8 :)

mehrpadin’s picture

Status: Active » Fixed
dhatman’s picture

Great Mehrpadin! Many cudos.

Status: Fixed » Closed (fixed)

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

h3rj4n’s picture

Version: 7.x-1.9-beta1 » 7.x-1.x-dev

This issue is still there.

I tried to set the target of the link, didn't work. After reading this thread I tried to add a class, didn't work either.

mehrpadin’s picture

Hoi,

Use the v1.9-beta4 please :)

h3rj4n’s picture

Version: 7.x-1.x-dev » 7.x-1.9-beta4

Still doesn't work.

I think the problem doesnt lay in this module. To populate the menu the function menu_tree_all_data is called. This function doesn't return the menu with attributes. I tried to trace back where the attribute value get's emptied but couldn't find it.

mehrpadin’s picture

Can someone try the development version please?

Amir Simantov’s picture

Version: 7.x-1.9-beta4 » 7.x-1.9-beta5

I second h3rj4n in #7 - does not work even in v1.9-beta5.

Michael Dajewski’s picture

Drupal core ver.: 7.22
Menu attributes: 7.x-1.0-rc2
Superfish: 7.x-1.9

Steps to duplicate:
1. For one of Main menu items select 'New window (_blank)' in 'Menu item attributes' section, which will add target attribute to the link.
2. Resize the browser window to to trigger smallscreen.js (may need for that responsive theme).

The menu html is changer from

  • ...

to
...

e.g.:
<a href="url" target="_blank" class="sf-depth-1">Menu item</a>
will get translated to:
<option value="url">Menu item</option>

The target attribute from the link is missing in the option, therefore the link opens in the same window/tab.

From little research I had time to do, in order to achieve opening new window/tab...
Instead of using window.location property it would be better to use the window.open() method.
See: sfsmallscreen.js and perhaps sftouchscreen.js.

As for storing target attribute inside one could use either class (global attribute).

Could someone wake-up and give it a thought, this bug has been filed over two years ago!!!

PS
While using <option> instead of <a> one should remember to somehow store following atributes that are valid for <a>:
Title
ID
Name
Relationship
Classes
Style
Target
Access Key

4fs’s picture

Just to my 2 cents.

I removed menu attributes and just used default description and this issue is still occurring, so nothing to do with menu attributes. This is rather a big deal as I am using the attributes for describing my links. The links are useless without a description. I have tested latest dev and v1.9 and both do the same. Thanks.

4fs’s picture

Any help would be appreciated here. :) I am having to manually update the title every day for the site I am using this feature. Thank you.

mehrpadin’s picture

Hey everybody,

Apologies for the late reply, terribly busy, I just read all the comments here again, looks like you are all talking about different issues!

  • Original issue has been fixed, this is for sure, I just tried Menu Attributes while testing something and I'm confident Superfish does not do anything to attributes; this however doesn't include the filter_xss that is unfortunately removing style="" attributes and some others (there's an issue for) but indeed not target="", etc.
  • sfSmallscreen doesn't affect those attributes in any way, it just doesn't use them.
  • 4fs, make sure "Insert hyperlink descriptions ("title" attribute) into hyperlink texts." is enabled (Block config > Advanced HTML settings > Hyperlinks > Hyperlink text)
mehrpadin’s picture

Issue summary: View changes
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

NaX’s picture

Version: 7.x-1.9-beta5 » 7.x-1.x-dev
Category: Bug report » Support request
Status: Closed (fixed) » Needs review

I solved this problem in my theme by adding the following to my template.php. Maybe this should be documented as a possible method of integration with other menu modules, like menu attributes.

This code is not perfect, I have not looked at each possible attribute for differences in how it should be merged. A space has been assumed for all.

/**
 * Returns HTML for a menu item.
 *
 * @param array $variables
 *   An associative array containing:
 *   - element: Structured array data for a menu item.
 *   - properties: Various properties of a menu item.
 *
 * @return string
 *   HTML string
 *
 * @ingroup themeable
 */
function mytheme_superfish_menu_item($variables) {
  if (!empty($variables['element']['item']['link']['options']['attributes'])) {
    $variables['element']['attributes'] = _lvsa_merge_attributes($variables['element']['attributes'], $variables['element']['item']['link']['options']['attributes']);
  }
  return theme_superfish_menu_item($variables);
}


function _mytheme_merge_attributes($existing, $new) {
  foreach($new as $key => $value) {
    // Add as is if not exist
    if (empty($existing[$key])) {
      $existing[$key] = $value;
      continue;
    }
    
    // create select operation string
    $op = gettype($existing[$key]) . '.' . gettype($value);
        
    // We wrongly assume all attributes are concatenated by a space    
    switch ($op) {
      case 'array.array':
        $existing[$key] = array_merge($existing[$key], $value);
        break;
        
      case 'string.array':
        $existing[$key] .= ' ' .  implode(' ', $value);
        break;
        
      default:
        $existing[$key] .= ' ' .  (string)$value;
    }
  }
  
  return $existing;
}

item

ron_s’s picture

Status: Needs review » Needs work

I'm using Superfish 7.x-1.9+33-dev and Menu Attributes 7.x-1.0-rc3. Menu attributes work correctly for menu links, but not for menu items. To replicate:

  1. Edit any menu item associated with a Superfish menu, and scroll to the bottom where the "Menu Item Attributes" fieldset is displayed (the Menu Attributes module needs to be enabled to do this)
  2. Open the fieldset, and enter a value for class
  3. Save the menu item and review the Superfish menu HTML -- no class is added to the menu item

If the same steps are taken and the Menu Link Attributes are modified, it works, but not the Menu Item Attributes.

vaccinemedia’s picture

I can confirm what @ron_s says - menu link attributes are being applied but menu item attributes are not when using the menu attributes module.

gmora2’s picture

Can confirm I am having the same issue with superfish overriding the item attribute from Menu Attribute module. Does anyone have a fix?

As a temporary fix, you are able to use JQuery to add a class to the list element in reference to targeting the anchor element.

jastraat’s picture

Sadly the code in 16 did not work for us. Even when a menu item had a class defined, $variables['element']['item']['link']['options']['attributes'] was empty, and the menu item class was nowhere in the item array.

(As others have mentioned, menu link classes work without a problem.)

jastraat’s picture

It looks like the menu item attributes are stored in $variables['element']['item']['link']['options']['item_attributes']

Geijutsuka’s picture

Confirmed that the menu list item classes are being overridden. As a temporary fix we are also using jQuery to add the needed class to menu items.

5n00py’s picture

Confirm, menu item attributes not working.

jeremypeter’s picture

I was having this issue with both Superfish v1.9 and Superfish v2.0, using Special Menu Items v7.x-2.0. So I was able to resolve this by using a preprocess function to modify the attributes array of the theme_superfish_menu_item() function. It will override the ID of the menu list item if provided, add classes to the existing Superfish classes and add the style attribute if values are provided.

/**
 * Implements theme_preprocess_superfish_menu_item()
 *
 * Fixes issue with Special Menu Items:
 *  - https://www.drupal.org/node/1104616
 */
function YOURTHEMENAME_preprocess_superfish_menu_item(&$variables) {

  $element      = $variables['element'];
  $item_options = $element['item']['link']['options'];

  if(isset($item_options['item_attributes'])){
    $sf_id          = $element['attributes']['id'];
    $sf_class       = $element['attributes']['class'];
    $smi_id         = $item_options['item_attributes']['id'];
    $smi_class      = $item_options['item_attributes']['class'];
    $smi_style      = $item_options['item_attributes']['style'];

    // Reset class string to an array so we can add
    // the Special Menu Item classes
    $element['attributes']['class']   = [];
    $element['attributes']['class'][] = $sf_class;
    $element['attributes']['class'][] = $smi_class;

    $element['attributes']['id'] =  empty($smi_id) ? $sf_id : $smi_id;

    if(!empty($smi_style)){
      $element['attributes']['style'] = $smi_style;
    }

    $variables['element'] = $element;
  }
}
Mykhailo.Levchenko’s picture

That's work! Thanks!

lubwn’s picture

I can confirm #24 works! Thanks a lot!

banoodle’s picture

#24 worked for me too (thank you!), but for anyone else who might try this, I did need to change the line that reads...

if(isset($item_options['item_attributes'])){

to

if(isset($item_options['attributes'])){

ivnish’s picture

Category: Support request » Bug report
Status: Needs work » Active