diff --git a/menu_attributes.module b/menu_attributes.module index db21bb7..cddf0ba 100644 --- a/menu_attributes.module +++ b/menu_attributes.module @@ -7,6 +7,18 @@ */ /** + * Implements hook_permission(). + */ +function menu_attributes_permission() { + return array( + 'administer menu attributes' => array( + 'title' => t('Administer menu attributes'), + 'description' => t('Administer menu attributes.'), + ), + ); +} + +/** * Implements hook_menu_link_alter(). */ function menu_attributes_menu_link_alter(&$item, $menu) { @@ -116,8 +128,10 @@ function menu_attributes_get_menu_attribute_info() { * @see menu_attributes_form_menu_edit_item_submit() */ function menu_attributes_form_menu_edit_item_alter(&$form, $form_state) { - $item = $form['original_item']['#value']; - _menu_attributes_form_alter($form, $item, $form); + if (user_access('administer menu attributes')) { + $item = $form['original_item']['#value']; + _menu_attributes_form_alter($form, $item, $form); + } } /** @@ -128,7 +142,7 @@ function menu_attributes_form_menu_edit_item_alter(&$form, $form_state) { * @see _menu_attributes_form_alter() */ function menu_attributes_form_node_form_alter(&$form, $form_state) { - if (isset($form['menu'])) { + if (user_access('administer menu attributes') && isset($form['menu'])) { $item = $form['#node']->menu; _menu_attributes_form_alter($form['menu']['link'], $item, $form); $form['menu']['link']['options']['attributes']['#type'] = 'container'; @@ -235,35 +249,37 @@ function _menu_attributes_form_submit($form, &$form_state) { * @see menu_configure_form() */ function menu_attributes_form_menu_configure_alter(&$form, $form_state) { - $form['attributes_title'] = array( - '#type' => 'item', - '#title' => t('Menu item attribute options'), - ); - $form['attributes_vertical_tabs'] = array( - '#type' => 'vertical_tabs', - ); - - $attributes = menu_attributes_get_menu_attribute_info(); - foreach ($attributes as $attribute => $info) { - $form['attributes'][$attribute] = array( - '#type' => 'fieldset', - '#title' => $info['label'], - '#group' => 'attributes_vertical_tabs', - '#description' => $info['form']['#description'], + if (user_access('administer menu attributes')) { + $form['attributes_title'] = array( + '#type' => 'item', + '#title' => t('Menu item attribute options'), ); - $form['attributes'][$attribute]["menu_attributes_{$attribute}_enable"] = array( - '#type' => 'checkbox', - '#title' => t('Enable the @attribute attribute.', array('@attribute' => drupal_strtolower($info['label']))), - '#default_value' => $info['enabled'], + $form['attributes_vertical_tabs'] = array( + '#type' => 'vertical_tabs', ); - $form['attributes'][$attribute]["menu_attributes_{$attribute}_default"] = array( - '#title' => t('Default'), - '#description' => '', - '#states' => array( - 'invisible' => array( - 'input[name="menu_attributes_' . $attribute . '_enable"]' => array('checked' => FALSE), + + $attributes = menu_attributes_get_menu_attribute_info(); + foreach ($attributes as $attribute => $info) { + $form['attributes'][$attribute] = array( + '#type' => 'fieldset', + '#title' => $info['label'], + '#group' => 'attributes_vertical_tabs', + '#description' => $info['form']['#description'], + ); + $form['attributes'][$attribute]["menu_attributes_{$attribute}_enable"] = array( + '#type' => 'checkbox', + '#title' => t('Enable the @attribute attribute.', array('@attribute' => drupal_strtolower($info['label']))), + '#default_value' => $info['enabled'], + ); + $form['attributes'][$attribute]["menu_attributes_{$attribute}_default"] = array( + '#title' => t('Default'), + '#description' => '', + '#states' => array( + 'invisible' => array( + 'input[name="menu_attributes_' . $attribute . '_enable"]' => array('checked' => FALSE), + ), ), - ), - ) + $info['form']; + ) + $info['form']; + } } }