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

Diff of /contributions/modules/bones/bones.module

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

revision 1.1.4.2, Wed Dec 31 20:22:55 2008 UTC revision 1.1.4.3, Thu Jan 1 16:09:17 2009 UTC
# Line 1  Line 1 
1  <?php //$Id  <?php //$Id: $
2    
3  /**  /**
4   * Implementation of hook_menu().   * Implementation of hook_menu().
# Line 111  function bones_form() { Line 111  function bones_form() {
111     '#type' => 'file',     '#type' => 'file',
112     '#size' => '20',     '#size' => '20',
113     '#title' => t('YAML file to import'),     '#title' => t('YAML file to import'),
114     '#description' => t('Select a YAML file representing an outline of the page structure you wish to import.')     '#description' => t('Select a YAML file representing an outline of the page structure you wish to import.'),
115    );    );
116    
117    $form['menu'] = array(    $form['menu'] = array(
# Line 152  function bones_form() { Line 152  function bones_form() {
152      '#suffix' => '</div>'      '#suffix' => '</div>'
153    );    );
154    
155    $form['menu']['new']['newmenu'] = array(    $form['menu']['new']['menu_name'] = array(
156        '#type' => 'textfield',
157        '#title' => t('Menu name'),
158        '#maxsize' => MENU_MAX_MENU_NAME_LENGTH_UI,
159        '#description' => t('The machine-readable name of this menu. This text will be used for constructing the URL of the <em>menu overview</em> page for this menu. This name must contain only lowercase letters, numbers, and hyphens, and must be unique.'),
160      );
161    
162      $form['menu']['new']['title'] = array(
163      '#type' => 'textfield',      '#type' => 'textfield',
164          '#size' => '20',          '#size' => '20',
165      '#title' => t('New Menu Name'),      '#title' => t('New Menu Name'),
166    );    );
167    
168    $form['menu']['new']['newmenu_description'] = array(    $form['menu']['new']['description'] = array(
169      '#type' => 'textarea',      '#type' => 'textarea',
170      '#title' => t('Description'),      '#title' => t('Description'),
171    );    );
# Line 228  function bones_form_submit($form, &$form Line 235  function bones_form_submit($form, &$form
235    //Include menu admin functions    //Include menu admin functions
236    require_once(drupal_get_path('module', 'menu') .'/menu.admin.inc');    require_once(drupal_get_path('module', 'menu') .'/menu.admin.inc');
237    
238    if ($form_state['values']['option'] == 'createnew'  && !empty($form_state['values']['newmenu'])) {    if ($form_state['values']['option'] == 'createnew'  && !empty($form_state['values']['title'])) {
239      $add_menu_items = TRUE;      $add_menu_items = TRUE;
240    
241      //Create the new menu and store its ID      //Create the new menu and store its ID
     $menu_name = drupal_strtolower(preg_replace('`[^a-z0-9]`i', '-', $form_state['values']['newmenu']));  
242      $menu = array(      $menu = array(
243        'title' => $form_state['values']['newmenu'],        'title' => $form_state['values']['title'],
244        'menu_name' => $menu_name,        'menu_name' => $form_state['values']['menu_name'],
245        'description' => $form_state['values']['newmenu_description']        'description' => $form_state['values']['description']
246      );      );
247      $form_state = array('values' => $menu);      $form_state = array('values' => $menu);
248      drupal_execute('menu_edit_menu', $form_state, '');      drupal_execute('menu_edit_menu', $form_state, '');
249    
250      $menu_name = 'menu-'. $menu_name; //(The system prepends menu- to custom menu names)      $menu_name = 'menu-'. $form_state['values']['menu_name']; //(The system prepends menu- to custom menu names)
251      $plid = 0;      $plid = 0;
252    
253    }    }
# Line 265  function bones_form_submit($form, &$form Line 271  function bones_form_submit($form, &$form
271  }  }
272    
273  /**  /**
274     * Validation function for the Bones form. Mostly borrowed from menu_edit_menu_validate() in menu.admin.inc
275     *
276     * @param array $form
277     * @param array $form_state
278     */
279    function bones_form_validate($form, &$form_state) {
280      //TODO: Add validation to make sure a file was uploaded (http://api.drupal.org/api/file/developer/topics/forms_api_reference.html#file)
281      //TODO: Write conditional blocks to validate new menu/existing menu selections as appropriate (If user wants a new menu, validate the menu_name and title fields, etc)
282      //TODO: Add logic to alter the form state to make the appropriate fieldsets visible based on menu option selections
283    
284      $item = $form_state['values'];
285      if (preg_match('/[^a-z0-9-]/', $item['menu_name'])) {
286        form_set_error('new][menu_name', t('The menu name may only consist of lowercase letters, numbers, and hyphens.'));
287      }
288      if (strlen($item['menu_name']) > MENU_MAX_MENU_NAME_LENGTH_UI) {
289        form_set_error('new][menu_name', format_plural(MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters."));
290      }
291      $count = db_result(db_query("SELECT COUNT(menu_name) AS name_exists FROM {menu_custom} WHERE menu_name = '%s'", $item['menu_name']));
292      if($count) {
293        form_set_error('new][menu_name', t("A menu with the name @menu_name already exists.  Please use a different menu name.", array('@menu_name' => $item['menu_name'])));
294      }
295    
296    }
297    
298    
299    /**
300   * Recursively parse the data structure and create new Page nodes and Menu items   * Recursively parse the data structure and create new Page nodes and Menu items
301   *   *
302   * @param Array $input   * @param Array $input

Legend:
Removed from v.1.1.4.2  
changed lines
  Added in v.1.1.4.3

  ViewVC Help
Powered by ViewVC 1.1.2