| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: path.inc,v 1.4 2009/01/20 20:05:03 quicksketch Exp $ 3 4 /** 5 * @file 6 * Form builder implementation for path.module. 7 */ 8 9 /** 10 * Implementation of hook_form_builder_types(). 11 */ 12 function path_form_builder_types() { 13 $fields = array(); 14 15 // Make a default path settings to pass into the path form. 16 $settings = module_invoke('path', 'node_form_default_settings'); 17 18 $fields['path_settings'] = array( 19 'title' => t('Path'), 20 'properties' => array( 21 'collapsible', 22 'collapsed', 23 ), 24 'default' => path_fieldset('', $settings['path']), 25 'unique' => TRUE, 26 'removable' => TRUE, 27 'configurable' => TRUE, 28 'palette_group' => 'special', 29 ); 30 31 return array( 32 'node' => $fields, 33 'example' => $fields, 34 ); 35 } 36 37 /** 38 * Implementation of hook_form_builder_load_alter(). 39 */ 40 function path_form_builder_load_alter(&$form, $form_type, $form_id) { 41 if ($form_type == 'node') { 42 $settings = node_get_form_settings($form_id, 'path'); 43 if ($settings['enabled']) { 44 $form['path'] = path_fieldset('', $settings); 45 $form['path']['#form_builder'] = array( 46 'element_id' => 'path_settings', 47 'element_type' => 'path_settings', 48 ); 49 } 50 } 51 } 52 53 /** 54 * Implementation of hook_form_builder_save(). 55 */ 56 function path_form_builder_save(&$form, $form_type, $form_id) { 57 if ($form_type == 'node') { 58 $element = form_builder_get_element($form, 'path_settings'); 59 $node_type = $form_id; 60 61 if ($element) { 62 $settings = array( 63 'enabled' => TRUE, 64 'collapsible' => $element['#collapsible'], 65 'collapsed' => $element['#collapsed'], 66 'weight' => $element['#weight'], 67 ); 68 } 69 else { 70 $settings = array( 71 'enabled' => FALSE, 72 ); 73 } 74 75 node_set_form_settings($form_id, 'path', 'path', $settings); 76 } 77 } 78 79 /** 80 * Implementation of hook_form_alter(). 81 * 82 * @todo Merge this into path_form_alter(). 83 */ 84 function path_node_form_alter(&$form, &$form_state, $form_id) { 85 // Set properties of the path form item based on the path node form settings. 86 if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) { 87 $settings = node_get_form_settings($form['#node']->type, 'path'); 88 89 if ($settings['enabled']) { 90 $path = isset($form['#node']->path) ? $form['#node']->path : ''; 91 $form['path'] = path_fieldset($path, $settings); 92 } 93 else { 94 $form['path']['#access'] = FALSE; 95 } 96 } 97 } 98 99 /** 100 * Implementation of hook_node_form_default_settings(). 101 * 102 * Get the settings for the path fieldset on the node form. 103 */ 104 function path_node_form_default_settings($type = NULL) { 105 $defaults = array(); 106 $defaults['path'] = array( 107 'enabled' => TRUE, 108 'collapsible' => TRUE, 109 'collapsed' => TRUE, 110 'weight' => 30, 111 ); 112 return $defaults; 113 } 114 115 116 /** 117 * A straight copy/paste of path_form_alter(). Get the path node form. 118 * 119 * @param $path 120 * The contents of $node->path. 121 * @param $path_settings 122 * An array with configuring properties of the path fieldset. 123 * 124 * @todo Put this function directly in path.module, abstracting it from 125 * path_form_alter(). 126 */ 127 function path_fieldset($path, $path_settings) { 128 $form = array( 129 '#type' => 'fieldset', 130 '#title' => t('URL path settings'), 131 '#collapsible' => $path_settings['collapsible'], 132 '#collapsed' => $path_settings['collapsed'], 133 '#access' => user_access('create url aliases'), 134 '#weight' => $path_settings['weight'], 135 ); 136 $form['path'] = array( 137 '#type' => 'textfield', 138 '#default_value' => $path, 139 '#maxlength' => 250, 140 '#collapsible' => TRUE, 141 '#collapsed' => TRUE, 142 '#description' => t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'), 143 ); 144 if ($path) { 145 $form['pid'] = array( 146 '#type' => 'value', 147 '#value' => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s' AND language = '%s'", $path, $form['#node']->language)) 148 ); 149 } 150 151 return $form; 152 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |