diff --git a/menu_attributes.module b/menu_attributes.module index 3b659fc..38cb86d 100644 --- a/menu_attributes.module +++ b/menu_attributes.module @@ -21,7 +21,7 @@ function menu_attributes_permission() { /** * Implements hook_menu_link_alter(). */ -function menu_attributes_menu_link_alter(&$item, $menu) { +function menu_attributes_menu_link_alter(&$item) { if (isset($item['options']['attributes']) && is_array($item['options']['attributes'])) { // Filter out blank attributes. foreach ($item['options']['attributes'] as $key => $value) { @@ -34,6 +34,16 @@ function menu_attributes_menu_link_alter(&$item, $menu) { if (isset($item['options']['attributes']['class']) && is_string($item['options']['attributes']['class'])) { $item['options']['attributes']['class'] = array_filter(explode(' ', $item['options']['attributes']['class'])); } + + // Allow html rendering of the menu link title. + if (isset($item['options']['attributes']['title_html']) && $item['options']['attributes']['title_html']) { + $item['options']['html'] = $item['options']['attributes']['title_html']; + } else { + if (isset($item['options']['html'])) { + unset($item['options']['html']); + } + } + } } @@ -90,6 +100,13 @@ function menu_attributes_menu_attribute_info() { '#size' => 1, ), ); + $info['title_html'] = array( + 'label' => t('HTML in menu link title'), + 'description' => t('If you want to add html tags to the menu link title, enable this. This should only be accessible to trusted users.'), + 'form' => array( + '#type' => 'checkbox', + ), + ); return $info; } diff --git a/menu_attributes.test b/menu_attributes.test index 4cabdfd..d03c16f 100644 --- a/menu_attributes.test +++ b/menu_attributes.test @@ -40,6 +40,7 @@ class MenuAttributesTestHelper extends DrupalWebTestCase { 'style' => $this->randomName(10), 'target' => '_top', 'accesskey' => $this->randomName(1), + 'title_html' => 1, ); $this->menu_attributes_edit = array( @@ -51,6 +52,7 @@ class MenuAttributesTestHelper extends DrupalWebTestCase { 'style' => $this->randomName(10), 'target' => '_self', 'accesskey' => $this->randomName(1), + 'title_html' => 1, ); } @@ -91,6 +93,7 @@ class MenuAttributesTestHelper extends DrupalWebTestCase { 'options[attributes][style]' => $menu_attributes['style'], 'options[attributes][target]' => $menu_attributes['target'], 'options[attributes][accesskey]' => $menu_attributes['accesskey'], + 'options[attributes][title_html]' => $menu_attributes['title_html'], ); // Add menu link. @@ -225,6 +228,7 @@ class MenuAttributesNodeTestCase extends MenuAttributesTestHelper { 'menu[options][attributes][style]' => $this->menu_attributes_new['style'], 'menu[options][attributes][target]' => $this->menu_attributes_new['target'], 'menu[options][attributes][accesskey]' => $this->menu_attributes_new['accesskey'], + 'menu[options][attributes][title_html]' => $this->menu_attributes_new['title_html'], ); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); // Assert that the link exists. @@ -248,6 +252,7 @@ class MenuAttributesNodeTestCase extends MenuAttributesTestHelper { 'menu[options][attributes][style]' => $this->menu_attributes_edit['style'], 'menu[options][attributes][target]' => $this->menu_attributes_edit['target'], 'menu[options][attributes][accesskey]' => $this->menu_attributes_edit['accesskey'], + 'menu[options][attributes][title_html]' => $this->menu_attributes_edit['title_html'], ); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));