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

Contents of /contributions/modules/edit_term/edit_term.module

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


Revision 1.3 - (show annotations) (download) (as text)
Sat Sep 27 06:08:54 2008 UTC (14 months ago) by dman
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +32 -191 lines
File MIME type: text/x-php
Drupal 6 compatable version.
Removed menu widget for now.
1 <?php
2 // $Id: edit_term.module,v 1.1.2.4 2008/08/19 00:10:34 dman Exp $
3 /**
4 * @file
5 *
6 * Enhancements to the Drupal admin interface - make term management easier.
7 *
8 * This module adds a few usability elements to the Drupal term management
9 * screens:
10 *
11 * Direct link to 'edit term' page when viewing taxonomy/term/n pages
12 * This enables quick acces right to the term description and heirarchy
13 * position, returning the admin user to where they were on save.
14 * Also works for 'gallery' management pages from the image_gallery.module
15 *
16 ******** REMOVED for D6 DEV version. May come back ******
17 * An edit form for menu placement for the term on the term edit page. Create
18 * and position a menu link to taxonomy/term/n as needed. No need to trust
19 * taxonomy_menu, go through the admin - menu screens and juggle weights, or try
20 * or other strange navigations. Just add a menu item the same as you do for a
21 * node.
22 *************
23 *
24 * An edit form for term aliases. Again, like editing a node, just give your
25 * term page a path. Should co-operate with pathauto also.
26 *
27 * The UI additions integrate with image_gallery.module to display the term edit
28 * tab on gallery pages also, and to edit gallery paths and menus the same as
29 * term pages ... taking care to redirect to image/tid/n pages, not
30 * taxonomy/term/n pages.
31 *
32 * Requires permissions:
33 * "administer taxonomy", "administer images" as needed.
34 *
35 * Credits:
36 * --------
37 *
38 * Original edit_term 'block' feature
39 * @author Benjamin Melan�on of Agaric Design Collective, October 2007. http:
40 * //AgaricDesign.com
41 *
42 * Usability additions
43 * - edit tabs
44 * - menu editor
45 * - alias editor
46 * @author Dan morrison (dman) http://coders.co.nz/ February 2008
47 *
48 * @version $Id: edit_term.module,v 1.1.2.4 2008/08/19 00:10:34 dman Exp $
49 */
50
51 /**
52 * Return help text describing this module
53 *
54 * Implementation of hook_help().
55 */
56 function edit_term_help($path, $arg) {
57 switch ($path) {
58 case 'admin/modules#description' :
59 return t("Enhancements to make term editing easier.");
60 case 'admin/help#edit_term':
61 return ' '; // Show me on the help menu, but don't execute all the time
62 case 'admin/help/edit_term':
63 return edit_term_about();
64 }
65 return false;
66 }
67
68 /**
69 * Hook Implimentation
70 *
71 * Adds edit tab to taxonomy pages.
72 */
73 function edit_term_menu() {
74 $items = array();
75
76 // Add an edit tab to taxonomy pages for easy access
77 // Need two dummy default items - parent and default - for the advanced tab to show :-/
78 // There may be an easier way
79 $items['taxonomy/term/%'] = array(
80 'title' => t('View'),
81 'type' => MENU_CALLBACK,
82 'page callback' => 'taxonomy_term_page',
83 'page arguments' => array(2),
84 'access arguments' => array('access content'),
85 'file' => 'taxonomy.pages.inc',
86 'file path' => drupal_get_path('module', 'taxonomy'),
87 );
88 $items['taxonomy/term/%/view'] = array(
89 'title' => t('View'),
90 'type' => MENU_DEFAULT_LOCAL_TASK,
91 'weight' => 0,
92 );
93 $items['taxonomy/term/%/edit-term'] = array(
94 'title' => t('Edit Term'),
95 'page callback' => 'edit_term_edit_taxonomy_term',
96 'page arguments' => array(2),
97 'access arguments' => array('administer taxonomy'),
98 'file' => 'taxonomy.admin.inc',
99 'file path' => drupal_get_path('module', 'taxonomy'),
100 'weight' => 1,
101 'type' => MENU_LOCAL_TASK,
102 );
103
104 // Add an edit tab to gallery pages for easy access
105 // Needs default view tabs for the advanced tab to show :-/
106 $items['image/tid/%'] = array(
107 'type' => MENU_CALLBACK,
108 );
109 $items['image/tid/%/view'] = array(
110 'title' => t('View'),
111 'weight' => 0,
112 'type' => MENU_DEFAULT_LOCAL_TASK
113 );
114 $items['image/tid/%/edit-term'] = array(
115 'title' => t('Edit Gallery'),
116 'page callback' => 'edit_term_edit_taxonomy_term',
117 'page arguments' => array(1),
118 'access callback' => 'node_access',
119 'access arguments' => 'administer images',
120 'weight' => 1,
121 'type' => MENU_LOCAL_TASK
122 );
123
124 return $items;
125 }
126
127
128
129 /**
130 * Redirect the extra tab to the taxonomy edit page.
131 */
132 function edit_term_edit_taxonomy_term($tid) {
133 $term = taxonomy_get_term($tid);
134
135 $termpath = 'taxonomy/term/'. $tid;
136 if ( ($gvid = variable_get('image_gallery_nav_vocabulary', '')) && ($term->vid == $gvid)) {
137 $termpath = 'image/tid/'. $tid;
138 }
139
140 $_REQUEST['destination'] = $termpath;
141
142 if ($term) {
143 drupal_set_title(t("Editing %term", array('%term' => $term->name)));
144 return taxonomy_admin_term_edit($tid);
145 }
146 else {
147 return t("Failed to load term");
148 }
149 }
150
151 /**
152 * Implementation of hook_form_alter().
153 * Add menu item fields to the term form.
154 *
155 * copied from menu_form_alter()
156 */
157 function edit_term_form_alter(&$form, $form_state, $form_id) {
158 if ($form_id == 'taxonomy_form_term') {
159 $term = taxonomy_get_term($form['tid']['#value']);
160 // Default form has no useful weighting on it.
161 // Add some
162 $form['submit']['#weight'] = 10;
163 $form['delete']['#weight'] = 11;
164
165 // Add the alias editor
166 if (module_exists('path')) {
167 edit_term_path_form($term, $form);
168 }
169 }
170 }
171
172 /**
173 * Adds the path alias edit function to term pages
174 *
175 * Helper to edit_term_form_alter
176 *
177 * extension under hook_form_alter().
178 */
179 function edit_term_path_form($term, &$form) {
180 $path = "";
181 if ($term->tid) {
182 $system_paths = array(
183 'taxonomy/term/'. $term->tid,
184 'image/tid/'. $term->tid,
185 );
186 foreach ($system_paths as $system_path) {
187 $found_path = drupal_get_path_alias($system_path);
188 if ($found_path != $system_path) {
189 // Found an alias
190 $path = $found_path;
191 }
192 }
193 if ($path) {
194 $form['path']['pid'] = array(
195 '#type' => 'value',
196 '#value' => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $path))
197 );
198 }
199 }
200 $form['path']['path'] = array(
201 '#type' => 'textfield',
202 '#title' => t('URL path settings'),
203 '#default_value' => $path,
204 '#access' => user_access('create url aliases'),
205 '#maxlength' => 250,
206 '#weight' => 3,
207 );
208 if ($path) {
209 $form['path']['pid'] = array(
210 '#type' => 'value',
211 '#value' => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $path))
212 );
213 }
214 }
215
216 /**
217 * Implementation of hook_taxonomy().
218 *
219 * Capture the editing of a term from term edit form.
220 * Get the additional fields we added to the form.
221 * Make out own updates as needed.
222 */
223 function edit_term_taxonomy($op, $type, $form_values = NULL) {
224 if ($type == "term" && user_access('administer menu')) {
225 $term = (object) $form_values;
226 $termpath = 'taxonomy/term/'. $term->tid;
227 if ( ($gvid = variable_get('image_gallery_nav_vocabulary', '')) && ($term->vid == $gvid)) {
228 $termpath = 'image/tid/'. $term->tid;
229 }
230
231 switch ($op) {
232 case 'insert':
233 case 'update':
234 // Update term alias
235 if (module_exists('path')) {
236 if ($term->path) {
237 path_set_alias($termpath, $term->path);
238 }
239 else {
240 path_set_alias($termpath);
241 }
242 }
243 break;
244
245 case 'delete':
246 if (module_exists('path')) {
247 path_set_alias($termpath);
248 }
249 break;
250 }
251 }
252 }
253
254 /**
255 * Self-documenting help page.
256 * Return my own page header
257 */
258 function edit_term_about() {
259 // Render this file header as the readme available under admin/help
260 $chunks = preg_split( '/(@file)|(\*\/)/', file_get_contents(__FILE__) );
261 $readme = preg_replace('|\n\s*\*|', "\n", $chunks[1]);
262 $readme = preg_replace('|\n\s*@|', "\n<br/>\n@", $readme);
263 $readme = preg_replace('|\n\s*\n|', "\n<br/><br/>\n", $readme);
264 return $readme;
265 }

  ViewVC Help
Powered by ViewVC 1.1.2