Can we please add an onclick attribute to this module?

Files: 
CommentFileSizeAuthor
#1 onclick-1923740-1.patch2.79 KBalbertski
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch onclick-1923740-1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

albertski’s picture

StatusFileSize
new2.79 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch onclick-1923740-1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Here is a patch that implements this:

Mołot’s picture

Status:Needs review» Reviewed & tested by the community

Works for me and mines.

Stephanie_42’s picture

This patch does works for me, I've got an issues with my onclick quotes getting encoded (javascript based click tracking), but this may not be the patch - I'mnot sure yet.
Thanks!

Status:Reviewed & tested by the community» Needs work

The last submitted patch, 1: onclick-1923740-1.patch, failed testing.

Diane Bryan’s picture

Issue summary:View changes

Very interested to see this fixed! I'll ask our Tom to look into it.

joelpittet’s picture

Considering adding this feature if it was disabled by default, and maybe add a tests for the encoding that @Stephanie_42 mentioned in #3

Would turning it off by default, and then just allowing people to enable it through the menu settings work for you?
admin/structure/menu/settings

@Stephanie_42 is it the double quote or single quote encoding that is not working? I would assume that double quotes would be encoded because you'd break the attribute. Also a bit concerned for security here... but discuss that later unless some one can speak to that?

limonazzo’s picture

4 drupal 6 i use Menu attributes and modify:

menu_attributes.admin.inc

function menu_attributes_admin() {

  // onclick Attribute
  $form['menu_attributes_onclick'] = array(
    '#type' => 'fieldset',
    '#title' => t('Onclick Attribute'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE
  );
  $form['menu_attributes_onclick']['menu_attributes_onclick_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable setting the onclick attribute'),
    '#default_value' => variable_get('menu_attributes_onclick_enable', 1)
  );
  $form['menu_attributes_onclick']['menu_attributes_onclick_default'] = array(
    '#type' => 'textfield',
    '#title' => t('Onclick Attribute Default'),
    '#default_value' => variable_get('menu_attributes_onclick_default', NULL),
    '#required' => FALSE
  );
......

and

function menu_attributes_form_alter(&$form, $form_state, $form_id) {
  if ((isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) || ('menu_edit_item' == $form_id)) {
    if ($form['#node']->type .'_node_form' == $form_id) { // It's the node edit form
      $item = $form['#node']->menu;
    }
    else {
      $item = $form['menu']['#item'];
    }
   
    if (isset($form['menu'])) { // Check to see whether the menu form exists
      $form['menu']['options'] = array(
          '#type' => 'fieldset',
          '#title' => t('Menu item attributes'),
          '#access' => user_access('administer menu attributes'),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#tree' => TRUE,
          '#weight' => 50,
      );

    //  ->     
      if (variable_get('menu_attributes_onclick_enable', 1)) {
        $form['menu']['options']['attributes']['onclick'] = array(
          '#type' => 'textfield',
          '#title' => t('Onclick attribute'),
          '#description' => t('Enter onclick methods'),
          '#default_value' => isset($item['options']['attributes']['onclick']) ? $item['options']['attributes']['onclick'] : ($item['mlid'] ? NULL : variable_get('menu_attributes_onclick_default', NULL)),
          '#required' => FALSE,
        );
      }
    // <-

..... code

on menu_attributes.module.