/[drupal]/contributions/modules/special_menu_items/special_menu_items.module
ViewVC logotype

Diff of /contributions/modules/special_menu_items/special_menu_items.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3, Mon May 11 14:11:51 2009 UTC revision 1.4, Mon Jun 1 08:44:48 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  //$Id: special_menu_items.module,v 1.2 2009/05/10 07:14:55 tamerzg Exp $  //$Id: special_menu_items.module,v 1.3 2009/05/11 14:11:51 tamerzg Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 9  Line 9 
9   *  parent and grouping some children below it.   *  parent and grouping some children below it.
10   *  A separator menu item is something like "-------" which is also not linking anywhere but   *  A separator menu item is something like "-------" which is also not linking anywhere but
11   *  merely a mean to structure menus.   *  merely a mean to structure menus.
  *  This is how the module work:  
  *  - User can create a new menu item and place either "nolink" or "separator" to the URL  
  *  field, without quotes.  
  *  - When the menu is rendered the "nolink" item will be rendered similar to a normal menu link  
  *  item but there will be no link just the title.  
  *  - When the menu is rendered the "separator" item will be rendered to an item which is no link  
  *  and the title will always be "-------".  
12   *   *
13   *  Written by Tamir Al Zoubi and Karim Djelid - Servit Open Source Solutions - www.servit.ch   *  Written by Tamir Al Zoubi and Karim Djelid - Servit Open Source Solutions - www.servit.ch
14   */   */
# Line 41  function special_menu_items_menu() { Line 34  function special_menu_items_menu() {
34    'type' => MENU_CALLBACK,    'type' => MENU_CALLBACK,
35    );    );
36    
37      $items['admin/settings/special_menu_items'] = array(
38        'title' => 'Special Menu Items',
39        'description' => 'Configure Special Menu Items.',
40        'page callback' => 'drupal_get_form',
41        'page arguments' => array('special_menu_items_admin_settings_form'),
42        'access arguments' => array('administer site configuration'),
43        'type' => MENU_NORMAL_ITEM,
44      );
45    
46   return $items;   return $items;
47  }  }
48    
# Line 62  function special_menu_items_dummy() Line 64  function special_menu_items_dummy()
64   * overwriten menu_item_link function.   * overwriten menu_item_link function.
65   */   */
66  function special_menu_itemsoverwrite_menu_item_link($link) {  function special_menu_itemsoverwrite_menu_item_link($link) {
   //return theme('special_menu_items_menu_item_link', $link);  
67    $theme_overwrite=variable_get('oldtheme_menu_item_link',null);    $theme_overwrite=variable_get('oldtheme_menu_item_link',null);
68    
69    if (empty($link['localized_options'])) {    if (empty($link['localized_options'])) {
# Line 72  function special_menu_itemsoverwrite_men Line 73  function special_menu_itemsoverwrite_men
73    if(strpos($link['href'], 'nolink') === 0) {    if(strpos($link['href'], 'nolink') === 0) {
74      // Allow if the menu link is nolink:      // Allow if the menu link is nolink:
75      $link['localized_options']['html'] = TRUE;      $link['localized_options']['html'] = TRUE;
76    
77        //Retrieve tag for nolink menu item
78        $tag=variable_get('special_menu_items_nolink_tag','<span>');
79    
80        //Set class for nolink
81        $css='nolink';
82    
83      //Return HTML span instead of a link      //Return HTML span instead of a link
84      return '<span>'.$link['title'].'</span>';      return render_menu_item($tag,$link['title'],$css);
85    }    }
86    else if(strpos($link['href'], 'separator') === 0) {    else if(strpos($link['href'], 'separator') === 0) {
87      // Allow if the menu link is seperator      // Allow if the menu link is seperator
88      $link['localized_options']['html'] = TRUE;      $link['localized_options']['html'] = TRUE;
89      //Return -------- to serve as a separator  
90      return '<span>--------</span>';      //Retrieve tags and value for seperator menu item
91        $tag=variable_get('special_menu_items_seperator_tag','<span>');
92        $value=variable_get('special_menu_items_seperator_value','--------');
93    
94        //Set class for seperator
95        $css='seperator';
96    
97        //Return separator menu item
98        return render_menu_item($tag,$value,$css);
99    }    }
100    else    else
101       return call_user_func($theme_overwrite, $link);       return call_user_func($theme_overwrite, $link);
102  }  }
103    
104    /**
105     * Returns menu item rendered.
106     */
107    function render_menu_item($tag,$value,$css=null){
108    $length=strlen($tag);
109    
110        //Validate the tags
111          if($tag[0]=='<' && $tag[$length-1]=='>'){
112            $closingtag=str_replace('<','</',$tag);
113            if($css)
114                $tag=str_replace('>',' class="'.$css.'">',$tag);
115          }
116          else{
117            if($css){
118            $classtag='<'.$tag.' class="'.$css.'">';
119            $tag='<'.$tag.'>';
120            $closingtag=str_replace('<','</',$tag);
121            $tag=$classtag;
122            }
123            else{
124            $tag='<'.$tag.'>';
125            $closingtag=str_replace('<','</',$tag);
126            }
127          }
128      return $tag.$value.$closingtag;
129    }
130    
131  /**  /**
132   * Implementation of hook_theme_registry_alter()   * Implementation of hook_theme_registry_alter()
# Line 99  function special_menu_items_theme_regist Line 141  function special_menu_items_theme_regist
141    variable_set('oldtheme_menu_item_link', $theme_overwrite);    variable_set('oldtheme_menu_item_link', $theme_overwrite);
142    
143    // Replace theme_menu_item_link with our special_menu_itemsoverwrite_menu_item_link.    // Replace theme_menu_item_link with our special_menu_itemsoverwrite_menu_item_link.
144    $theme_registry['menu_item_link']['function'] = 'special_menu_itemsoverwrite_menu_item_link';     $theme_registry['menu_item_link']['function'] = 'special_menu_itemsoverwrite_menu_item_link';
145       $theme_registry['menu_item_link']['theme paths'] = 'sites/all/modules/special_menu_items';
146  }  }
147    
148  /**  /**
# Line 110  function special_menu_items_form_alter(& Line 153  function special_menu_items_form_alter(&
153    
154    if ($form_id=='menu_edit_item') {    if ($form_id=='menu_edit_item') {
155    $form['menu']['link_path']['#description']=  t('The path this menu item links to. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page, enter "nolink" to generate non-linkable item, enter "separator" to generate separator item.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org'));    $form['menu']['link_path']['#description']=  t('The path this menu item links to. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page, enter "nolink" to generate non-linkable item, enter "separator" to generate separator item.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org'));
156      }
157    }
158    
159    /**
160     * Implementation of hook_init().
161     */
162    function special_menu_items_init() {
163    
164      //Make breadcrumb of nolink menu item nonlinkable.
165      $breadcrumb = drupal_get_breadcrumb();
166    
167      foreach($breadcrumb as $key=>$crumb){
168    
169        if(strlen(strstr($crumb,'nolink'))>0) {
170          $crumb=strip_tags($crumb);
171          $tag=variable_get('special_menu_items_nolink_tag','<span>');
172          $breadcrumb[$key]=render_menu_item($tag,$crumb);
173        }
174    }    }
175      drupal_set_breadcrumb($breadcrumb);
176    }
177    
178    /**
179     * Special Menu Items admin settings form.
180     *
181     * @return
182     * The settings form used by Special Menu Items.
183     */
184    function special_menu_items_admin_settings_form() {
185      $form['special_menu_items_nolink_tag'] = array(
186        '#type' => 'textfield',
187        '#title' => t('HTML tag for "nolink"'),
188        '#description' => t('By default, Special Menu Items will use a span tag for the nolink menu item. Here you can specify your own tag.'),
189        '#default_value' => variable_get('special_menu_items_nolink_tag', '<span>'),
190    
191      );
192    
193      $form['special_menu_items_seperator_tag'] = array(
194        '#type' => 'textfield',
195        '#title' => t('HTML tag for "seperator"'),
196        '#description' => t('By default, Special Menu Items will use a span tag for the seperator menu item. Here you can specify your own tag.'),
197        '#default_value' => variable_get('special_menu_items_seperator_tag', '<span>'),
198    
199      );
200    
201        $form['special_menu_items_seperator_value'] = array(
202        '#type' => 'textfield',
203        '#title' => t('Value to be displayed for the "seperator"'),
204        '#description' => t('By default, Special Menu Items will use a "--------" value for the seperator. You can specify your own value for the seperator.'),
205        '#default_value' => variable_get('special_menu_items_seperator_value', '--------'),
206    
207      );
208    
209      return system_settings_form($form);
210  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.2