'Custom Active Menu Item', 'description' => 'Configure Custom Active Menu Item', 'page callback' => 'drupal_get_form', 'page arguments' => array('cami_settings_form'), 'access arguments' => array('administer cami'), ); return $items; } /** * Implements hook_permission(). */ function cami_permission() { return array( 'administer cami' => array( 'title' => t('Administer Custom Active Menu Item'), 'description' => t('Allows to users edit the menu item to indicate when is active.'), ), ); } /** * Settings form configuration. */ function cami_settings_form($form_state) { $form = array(); $form['cami_li_classes'] = array( '#type' => 'textfield', '#title' => t('List classes'), '#description' => t('Classes applied to li element (separate classes with spaces)'), '#default_value' => variable_get('cami_li_classes', 'active-trail'), ); $form['cami_a_classes'] = array( '#type' => 'textfield', '#title' => t('Link classes'), '#description' => t('Classes applied to a element (separate classes with spaces)'), '#default_value' => variable_get('cami_a_classes', 'active'), ); return system_settings_form($form); } /** * Implements hook_menu_edit_item_alter(). */ function cami_form_menu_edit_item_alter(&$form, &$form_state) { if (user_access('administer cami')) { $form['options'] = array( '#tree' => TRUE, '#weight' => 50, ); $form['options']['cami'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Custom Active Menu Item'), '#weight' => 0, ); $form['options']['cami']['pages'] = array( '#type' => 'textarea', '#title' => t('Pages'), '#description' => t("Pages where the menu item will be active, Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are blog for the blog page and blog/* for every personal blog."), '#default_value' => isset($form['original_item']['#value']['options']['cami']['pages']) ? $form['original_item']['#value']['options']['cami']['pages'] : '', ); } } /** * Implements hook_preprocess_menu_link(). */ function cami_preprocess_menu_link(&$variables) { if (isset($variables['element']['#localized_options']['cami']['pages'])) { $pages = $variables['element']['#localized_options']['cami']['pages']; $path = drupal_get_path_alias(current_path()); // Compare with the internal and path alias (if any). $page_match = drupal_match_path($path, $pages); if ($path != current_path()) { $page_match = $page_match || drupal_match_path(current_path(), $pages); } } if (isset($page_match) && $page_match) { $variables['element']['#attributes']['class'][] = variable_get('cami_li_classes', 'active-trail'); $variables['element']['#localized_options']['attributes']['class'][] = variable_get('cami_a_classes', 'active'); } }