Projet

Général

Profil

Révision 56383c7f

Ajouté par Assos Assos il y a plus de 10 ans

Uninstall: hierarchical_select

Voir les différences:

htmltest/sites/all/modules/hierarchical_select/API.txt
1

  
2
Terminology
3
-----------
4
- item: an item in the hierarchy. A hierarchy can also be seen as a tree. In
5
        that case, an item can be either a parent or a child. However, if
6
        "multiple parents" are supported (i.e. a child can have multiple
7
        parents), then it's actually not a tree but a directed acyclic graph
8
        (see http://en.wikipedia.org/wiki/Directed_acyclic_graph), in which
9
        each case technically is a "node".
10
        An example: in the case of taxonomy, this is the term id (tid).
11
- label: the label associated with an item in the hierarchy. You may now it
12
         as "title" or something else similar.
13
         An example: in the case of taxonomy, this is the actual term.
14
- item type: a per-level, human-readable name that describes what kind of
15
             items that level contains.
16
- entity: an item is often associated with an entity. E.g. a term is usually
17
          associated with a node.
18
- form element: a form element allows the developer to assign a new value to
19
                a #type property in a form item. Examples of form elements
20
                supported by Drupal core are: select, checkboxes, textfield.
21
- form item: an instance of a form element, with various other properties
22
             defined, such as #title, #default_value and #description. These
23
             are used to define a form in Drupal.
24
- Hierarchical Select: this is the name of the module.
25
- hierarchical_select: this is the internal name of the Hierarchical Select
26
                       form element.
27
- hierarchical select: (note the difference in case) this is the part of the
28
                       widget with the multiple selects.
29
- dropbox: this is the part of the widget where the selections are stored when
30
           multiple selections are allowed.
31
           
32

  
33
Form API usage
34
--------------
35
You have to make sure your form item is using the "hierarchical_select" form
36
element type:
37

  
38
  $form['select_some_term'] = array(
39
    '#type' => 'hierarchical_select',
40
    '#title' => t('Select the tag you wish to use.'),
41
    '#size' => 1,
42
    '#config' => array(
43
      'module' => 'hs_taxonomy',
44
      'params' => array(
45
        'vid' => $vid,
46
      ),
47
      'save_lineage'    => 0,
48
      'enforce_deepest' => 0,
49
      'entity_count'    => 0,
50
      'require_entity'  => 0,
51
      'resizable'       => 1,
52
      'level_labels' => array(
53
        'status' => 0,
54
        'labels' => array(
55
          0 => t('Main category'),
56
          1 => t('Subcategory'),
57
          2 => t('Third level category'),
58
        ),
59
      ),
60
      'dropbox' => array(
61
        'status'   => 0,
62
        'title'    => t('All selections'),
63
        'limit'    => 0,
64
        'reset_hs' => 1,
65
      ),
66
      'editability' => array(
67
        'status'           => 0,
68
        'item_types'       => array(),
69
        'allowed_levels'   => array(
70
          0 => 0,
71
          1 => 0,
72
          2 => 1,
73
        ),
74
        'allow_new_levels' => 0,
75
        'max_levels'       => 3,
76
      ),
77
      // These settings cannot be configured through the UI: they can only be
78
      // overridden through code.
79
      'animation_delay'    => 400,
80
      'special_items'      => array(),
81
      'render_flat_select' => 0,
82
    ),
83
    '#default_value' => '83',
84
  ); 
85

  
86
Now, let's explain what we see here:
87
1) We've set the #type property to "hierarchical_select" instead of "select".
88
2) The #size property is inherited by the selects of the hierarchical select.
89
   You can use it to change a vertical size of the select (i.e. change how many
90
   items are displayed in the select, similar to a form select multiple).
91
3) There's a new property: #config. This must be an
92
array. These are the items it can contain:
93
 - module (required)
94
   This will be passed through in the AJAX requests, to let Hierarchical
95
   Select know which module's hooks should be used.
96

  
97
 - params (optional, may be necessary for some implementations)
98
   An array of parameters that will also be passed through in every AJAX
99
   request.
100
   e.g. In the case of taxonomy, this is the vocabulary id (vid). In case of
101
   content_taxonomy, there's three parameters: vid, tid and depth (tid allows
102
   one to define a new root, depth allows one to limit the depth of the
103
   displayed hierarchy).
104

  
105
 - save_lineage (optional, defaults to 0)
106
   Triggers the lineage saving functionality. If enabled, the selection can
107
   consist of multiple values.
108

  
109
 - enforce_deepest (optional, defaults to 0)
110
   Triggers the enforcing of a selection in the deepest level. If enabled, the
111
   selection will always be a single value.
112

  
113
 - entity_count (optional, defaults to 0)
114
   Enables the display of entity counts, between parentheses, for each item in
115
   the hierarchy.
116

  
117
 - require_entity (optional, defaults to 0)
118
   Whether an item should only be displayed if it has at least one associated
119
   entity.
120

  
121
 - resizable (optional, defaults to 1)
122
   Makes the hierarchical select resizable.
123

  
124
 - level_labels['status'] (optional, defaults to 0)
125
   Whether level labels should be enabled or not. When save_lineage is
126
   enabled, this will result in *empty* level labels.
127

  
128
 - level_labels['labels'] (optional)
129
   An array of labels, one per level. The label for the first level should be
130
   the value of key 0.
131
   When enforce_deepest is set to:
132
   - 0, then you can provide n level labels, with n the number of levels
133
   - 1, then you can provide only one level label.   
134

  
135
 - dropbox['status'] (optional, defaults to 0)
136
   Whether the dropbox is enabled or not (the dropbox allows the user to make
137
   multiple selections).
138

  
139
 - dropbox['title'] (optional, defaults to "All selections:")
140
   The title of the dropbox. The dropbox is the area where all selections are
141
   displayed when the dropbox is enabled.
142

  
143
 - dropbox['limit'] (optional, defaults to 0, which means "no limit")
144
   Limit the number of selection that can be added to the dropbox. So this
145
   allows you the restrict the number of items that can be selected when
146
   the dropbox has been enabled.
147
   
148
 - dropbox['reset_hs'] (optional, defaults to 1, which means "do reset")
149
   Determines what will happen to the hierarchical select when the user has
150
   added a selection to the dropbox.
151

  
152
 - editability['status] (optional, defaults to 0)
153
   Allow the user to create new items in the hierarchy.
154

  
155
 - editability['item_types'] (optional, defaults to the empty array)
156
   Only meaningful when editable is set to TRUE.
157
   Set the item type for each level. E.g.: "country" for the first level,
158
   "region" for the second and "city" for the third. When the user then wants
159
   to create a new item, the default label for the new item will be of the
160
   form "new <item type>", e.g. "new region".
161

  
162
 - editability['allowed_levels'] (optional, defaults to 1 for each level)
163
   Only meaningful when editable is set to TRUE.
164
   Specify in which levels the user is allowed to create new items. In the
165
   example, the user is only allowed to create new items in the third level.
166
   When a setting for a level is ommitted, it defaults to 1 (i.e. allowed for
167
   that level). This means you only have to specify in which levels the user
168
   is not allowed to create new items.
169
   This only applies to *existing* levels: it does not affect the
170
   allow_new_levels setting (the next setting).
171

  
172
 - editability['allow_new_levels'] (optional, defaults to 0)
173
   Only meaningful when editable is set to TRUE.
174
   Allow the user to create new levels, i.e. when a certain item does not yet
175
   have children, the user can create a first child for it (thus thereby
176
   creating a new level).
177

  
178
 - editability['max_levels'] (optional, defaults to 3)
179
   Only meaningful when editable_settings['allow_new_levels'] is set to TRUE.
180
   Limits the maximum number of levels. Don't set this too high or you'll end
181
   up with very deep hierarchies. This only affects how deep new levels can be
182
   created, it will not affect the existing hierarchy.
183

  
184
 - animation_delay (optional, defaults to 400)
185
   The delay of each animation (the drop in left and right animations), in ms.
186

  
187
 - special_items (optional, defaults to the empty array)
188
   Through this setting, you can mark each item with special properties it
189
   possesses. There currently are two special properties: 'exclusive' and
190
   'none'.
191
   Note: you should include these items in the hierarchy as if it were a
192
   normal item and then you can mark them as special through this property.
193
   * 'exclusive': Sometimes it's desirable to have exclusive lineages. When
194
                  such an option is selected, the user should not be able to
195
                  select anything else. This also means that  nothing else in
196
                  the dropbox can be selected: if the dropbox contains
197
                  anything, it will be reset.
198
                  Can be applied to multiple items.
199
                  e.g. an 'entire_tree' item:
200
                    'special_items' => array(
201
                      'entire_tree' => array('exclusive'),
202
                    )
203
   * 'none': Sometimes you want to replace the default '<none>' option by
204
             something else. This replacement should of course also exist in
205
             the root level.
206
             Can be applied to only one item.
207
             e.g. an 'any' item (used in hs_taxonomy_views):
208
               'special_items' => array(
209
                 'any' => array('none', 'exclusive'),
210
               )
211
   And a final example for a better overview:
212
    'special_items' => array(
213
      'entire_tree' => array('exclusive'),
214
      'any'         => array('none', 'exclusive'),
215
    )
216

  
217
 - render_flat_select (optional, defaults to 0)
218
   Because the hierarchical_select form element consists of multiple form
219
   items, it doesn't work well in GET forms. By enabling this setting, a flat
220
   select will also be rendered, that contains only the selected lineages.
221
   Combine that with Drupal.HierarchicalSelect.prepareGETSubmit in the JS code
222
   (or, alternatively, the 'prepare-GET-submit' event  that can be triggered,
223
   see the JavaScript events section for details) and you have a work-around
224
   (which, admittedly, only works when JS is enabled).
225

  
226
3) We *don't* specify a list of options: Hierarchical Select automatically
227
generates the options for us, thanks to the 'module' and 'params' settings.
228

  
229

  
230
Concepts
231
--------
232
- Item Unicity: each item in the hierarchy must be *unique*. It doesn't have
233
                to be numerical, it can also be a string.
234
                If your hierarchy does not have unique items by nature or by
235
                design (your items may be unique per level instead), that's
236
                not a problem. You can simply prepend the item's ancestors to
237
                get a unique item.
238
                e.g. you have an item "foobar" at the first, second and third
239
                levels. By prepending the ancestors using the dash as the
240
                separator, you'd get an item "foobar-foobar-foobar" at the
241
                third level.
242
                Also see the "Reserved item values" section.
243
- #options: it's gone, because it was the inherent cause for scalability
244
            problems: if a hierarchy consists of 10,000 or even 100,000 items,
245
            this results in huge HTML being generated. Huge HTML means more
246
            processing power necessary, and more bandwidth necessary. So where
247
            does Hierarchical Select get its "options"? It uses the hooks that
248
            every implementation has to implement to only get what it needs.
249
- The General Concept: you should think of Hierarchical Select as an abstract
250
                       widget that can represent *any* hierarchy. To be able
251
                       to display any hierarchy, you obviously  need some
252
                       universal way to "browse" a hierarchy.
253
                       If you are familiar with C++ or Java iterators, this
254
                       should come natural: the hooks you have to implement
255
                       is what allows Hierarchical Select to iterate over your
256
                       hierarchy. Then the heart of the iterator would be the
257
                       root_level() and children() hooks. params() allows you
258
                       to define which information is necessary before you can
259
                       determine *which* hierarchy or which *part* of the
260
                       hierarchy is being browsed. lineage() must return the
261
                       lineage, i.e. the item itself and all its ancestors,
262
                       this allows a hierarchy to be generated from just one
263
                       (selected) item.
264

  
265

  
266
Reserved item values
267
--------------------
268
- Ensure that your items don't have a "none", "all", "create_new_item" nor
269
  "label_\d+" values (the latter means "label_" followed by one or more
270
  digits). Your values should also not contain a pipe ("|"), since pipes are
271
  used to separate the selection of values that are sent back to the server
272
  in the callbacks.
273
- Valid 'empty' selections (i.e. if you want to set the #default_value
274
  property of your form item), are -1 and the empty array. The empty string is
275
  also considered valid, because Drupal core's Taxonomy module uses this as
276
  the empty selection.
277

  
278

  
279
Developer mode
280
--------------
281
When you are writing your implementation of the Hierarchical Select API, you
282
will often wonder what Hierarchical Select is doing internally with the data
283
you're feeding it. That's why there's a developer mode: it will show you this
284
data, even the data generated in AJAX callbacks. It'll also show you the time
285
it took to generate the lineage, to fill up the levels and to calculate the
286
child info, to track down badly performing code.
287
Also, when you're just creating a new HS config and it doesn't quite work
288
right, it can be helpful to enable the developer mode. It will perform some
289
basic diagnostics that might help you track down the cause.
290
To use this, you must have a browser with console.log() support. Install 
291
Firebug Lite (http://getfirebug.com/lite.html) if your browser does not
292
suport this. Next, go to Hierarchical Select's .module file and set the define
293
for the HS_DEVELOPER_MODE constant to TRUE.
294
When you now open Firebug (Firefox) or the Web Inspector (Safari), you'll see
295
the debug output. New output is added after each callback to the server.
296

  
297

  
298
Hierarchical Select implementations: gotcha's
299
---------------------------------------------
300
- "warning: Missing argument 1 for drupal_retrieve_form() …"
301
  This implies that your implementation's module weight is heavier than
302
  hierarchical_select.module. In that case, Hierarchical Select will not be
303
  able to detect hierarchical_select form items, preventing it from applying
304
  some magic, and AJAX updates won't work.
305

  
306

  
307
Hierarchical Select compatibility: gotcha's
308
-------------------------------------------
309
- "Invalid response from server"
310
  This typically means that some functions could not be found when
311
  Hierarchical Select does an AJAX callback to the server, which in turn means
312
  that some code (some PHP file) has not been included, while it should have
313
  been. Instead of using module_load_include() or even require_once, you
314
  should use form_load_include(). This function is new in Drupal 7 and will
315
  ensure that all required PHP files are included automatically.
316

  
317

  
318
Hierarchical Select API Tutorial
319
--------------------------------
320
Written by Stephen Barker of Digital Frontiers Media
321
(http://drupal.org/user/106070) and reviewed by Wim Leers:
322
  http://drupal.org/node/532724
323

  
324

  
325
Hierarchical Select Small Hierarchy
326
-----------------------------------
327
Hierarchical Select includes a Hierarchical Select API implementation that
328
allows one to use a hardcoded hierarchy. When it becomes to slow, you should
329
move the hierarchy into the database and write a proper implementation.
330
Below you can find an example of how to use the hs_smallhierarchy module. Just
331
change the $hierarchy array to suit your needs and off you go! Look at the
332
code of hs_smallhierarchy.module for full details, but this code example
333
should get you started.
334

  
335
  $hierarchy = array(
336
     'win' => array(
337
       'label' => 'Windows',
338
       'children' => array(
339
         'xp'    => array('label' => 'XP'),
340
         'vista' => array(
341
           'label' => 'Vista',
342
           'children' => array(
343
             'x86' => array('label' => '32-bits'),
344
             'x64' => array('label' => '64-bits'),
345
           ),
346
         ),
347
       ),
348
     ),
349
  );
350

  
351
  $form['select_some_term'] = array(
352
    '#type' => 'hierarchical_select',
353
    '#title' => t('Select the tag you wish to use.'),
354
    '#size' => 1,
355
    '#config' => array(
356
      'module' => 'hs_smallhierarchy',
357
      'params' => array(
358
        'hierarchy' => $hierarchy,
359
        'id' => 'my-hierarchy-about-windows',
360
        'separator' => '|',
361
      ),
362
      'save_lineage'    => 0,
363
      'enforce_deepest' => 0,
364
      'entity_count'    => 0,
365
      'resizable'       => 1,
366
      'level_labels' => array(
367
        'status' => 0,
368
        'labels' => array(
369
          0 => t('Main category'),
370
          1 => t('Subcategory'),
371
          2 => t('Third level category'),
372
        ),
373
      ),
374
      'dropbox' => array(
375
        'status'   => 0,
376
        'title'    => t('All selections'),
377
        'limit'    => 0,
378
        'reset_hs' => 1,
379
      ),
380
      'editability' => array(
381
        'status'           => 0,
382
        'item_types'       => array(),
383
        'allowed_levels'   => array(
384
          0 => 0,
385
          1 => 0,
386
          2 => 1,
387
        ),
388
        'allow_new_levels' => 0,
389
        'max_levels'       => 3,
390
      ),
391
      // These settings cannot be configured through the UI: they can only be
392
      // overridden through code.
393
      'animation_delay'    => 400,
394
      'exclusive_lineages' => array(),
395
      'render_flat_select' => 0,
396
    ),
397
    '#description' => 'Put your description here',
398
    '#default_value' => 'win|xp|x86',
399
  );
400

  
401

  
402
Hooks
403
-----
404
1) hook_hierarchical_select_params();
405
   Returns an array with the names of all parameters that are necessary for
406
   this implementation to work.
407

  
408
2) hook_hierarchical_select_root_level($params, $dropbox = FALSE);
409
   Returns the root level of the hierarchy: an array of (item, label) pairs.
410
   The $dropbox parameter can is optional and can even ommitted, as it's only
411
   necessary if you need the dropbox to influence your hierarchy.
412

  
413
3) hook_hierarchical_select_children($parent, $params, $dropbox = FALSE);
414
   Gets the children of $parent ($parent is an item in the hierarchy) and
415
   returns them: an array of (item, label) pairs, or the empty array if the
416
   given $parent has no children.
417
   The $dropbox parameter can is optional and can even ommitted, as it's only
418
   necessary if you need the dropbox to influence your hierarchy.
419

  
420
4) hook_hierarchical_select_lineage($item, $params);
421
   Calculates the lineage of $item (array of items, with $item the last) and
422
   returns it. Necessary when the "enforce_deepest" option is enabled.
423

  
424
5) hook_hierarchical_select_valid_item($item, $params);
425
   Validates an item, returns TRUE if valid, FALSE if invalid.
426

  
427
6) hook_hierarchical_select_item_get_label($item, $params);
428
   Given a valid item, returns the label. Is only used for rendering the
429
   selections in the dropbox.
430

  
431
7) hook_hierarchical_select_create_item($label, $parent, $params);
432
   Given a parent item and the label of a new item, create a new item as a
433
   child of the parent item. When $parent == 0, this means a new item is being
434
   created at the root level.
435
   Optional hook. When this hook is not implemented, this functionality will
436
   never be used, even when you configure it that way in code.
437

  
438
8) hook_hierarchical_select_entity_count($item, $params);
439
   Given a item, get the number of entities (most of the time the entity type
440
   is 'node') that are related to the given item. Used for the entity_count
441
   and require_entity settings.
442
   Optional hook. When this hook is not implemented, this functionality will
443
   never be used, even when you configure it that way (i.e. when you enable
444
   the entity_count and require_entity settings).
445

  
446
9) hook_hierarchical_select_implementation_info();
447
   Return metadata about this implementation.
448
   This information is used to generate the implementations overview at
449
   admin/settings/hierarchical_select/implementations. The expected format is:
450

  
451
      array(
452
        'hierarchy type' => t('Taxonomy'),
453
        'entity type'    => t('Node'),
454
        'entity'         => t('Story'),
455
        'context type'   => t('Node form'),
456
        'context'        => '',
457
      );
458
    
459
    another example:
460

  
461
      array(
462
        'hierarchy type' => t('Taxonomy'),
463
        'entity type'    => t('Node'),
464
        'entity'         => '',
465
        'context type'   => t('Views exposed filter'),
466
        'context'        => t('some view'),
467
      );
468

  
469
10) hook_hierarchical_select_config_info();
470
    Return metadata about each available user-editable configuration for this
471
    implementation.
472
    Optional hook. This information is used to generate the configurations
473
    overview at admin/settings/hierarchical_select/configs. The expected
474
    format is:
475

  
476
      $config_info[$config_id] = array(
477
        'config_id'      => $config_id,
478
        'hierarchy type' => t('Taxonomy'),
479
        'hierarchy'      => t($vocabulary->name),
480
        'entity type'    => t('Node'),
481
        'entity'         => implode(', ', array_map('t', $entities)),
482
        'edit link'      => "admin/content/taxonomy/edit/vocabulary/$vid",
483
      );
484

  
485

  
486
Standardized configuration form
487
-------------------------------
488
Hierarchical Select 3 comes with a standardized configuration form: 
489
hierarchical_select_common_config_form(). This function accepts a lot of
490
parameters, which allows you to use names typical to your module's hierarchy
491
(e.g. 'leaf' instead of 'term' and 'tree' instead of 'vocabulary'). A submit
492
handler is also provided, of course.
493
An example:
494

  
495
  // I'm not configuring all parameters here. For an example of that, see one
496
  // of the included modules.
497
  $form['foobar_hierarchical_select_config'] = hierarchical_select_common_config_form($module, $params, $config_id, $defaults, $strings, $max_hierarchy_depth, $preview_is_required);
498

  
499
  // Add the the submit handler for the Hierarchical Select config form.
500
  $parents = array('foobar_hierarchical_select_config');
501
  $form['#submit'][] = 'hierarchical_select_common_config_form_submit';
502
  $form['#hs_common_config_form_parents'] = $parents;
503

  
504

  
505
Configuration management
506
------------------------
507
It's now possible to export Hierarchical Select configurations, and there is a
508
function to set the configuration of a certain Hierarchical Select. Combine
509
the two and you can manage your Hierarchical Select configurations in code!
510
An example:
511

  
512
  // The exported configuration.
513
  $config = array( … );
514
  $config_id = $config['config_id];
515

  
516
  // Apply the configuration.
517
  require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');
518
  hierarchical_select_common_config_set($config_id, $config);
519

  
520

  
521
JavaScript events
522
-----------------
523
The Hierarchical Select module's JavaScript code triggers several events, to
524
allow for advanced interactions.
525

  
526
You can find all hierarchical_select form items using this selector:
527

  
528
  $('.hierarchical-select-wrapper');
529

  
530
You can find a *specific* hierarchical_select form item using this selector:
531

  
532
  $('#hierarchical-select-x-wrapper');
533

  
534
where x is a number, or more accurately: a hsid (hierarchical select id).
535
Retrieving all hsids in the current document can be done like this:
536

  
537
  for (var hsid in Drupal.settings.HierarchicalSelect.settings) {
538
    // …
539
  }
540

  
541
Alternatively, you can use one of the transliterated class names. A wrapper
542
for Hierarchical Select looks like this:
543
  <div class="hierarchical-select-wrapper
544
              hierarchical-select-level-labels-style-none
545
              hierarchical-select-wrapper-for-name-edit-taxonomy-1
546
              hierarchical-select-wrapper-for-config-taxonomy-1
547
              hierarchical-select-wrapper-processed"
548
       id="hierarchical-select-35-wrapper">
549
550
  </div>
551
Hence, you could also use selectors such as these, to achieve the same effect,
552
but with more robust code:
553
  $('.hierarchical-select-wrapper-for-config-taxonomy-1:first')
554
  .trigger('enforce-update');
555
  $('.hierarchical-select-wrapper-for-name-edit-taxonomy-1:first')
556
  .trigger('enforce-update');
557

  
558
The following events are triggered:
559
  - change-hierarchical-select
560
  - update-hierarchical-select
561
  - create-new-item
562
  - cancel-new-item
563
  - add-to-dropbox
564
  - remove-from-dropbox
565
  - enforced-update
566
  - prepared-GET-submit
567
All events are triggered *after* the animations have completed.
568

  
569
However, it's often useful to do something *before* an event (especially
570
because all of the above events perform an AJAX request to the server). So,
571
the equivalent "before" events exist as well:
572
  - before-update-hierarchical-select
573
  - before-create-new-item
574
  - before-cancel-new-item
575
  - before-add-to-dropbox
576
  - before-remove-from-dropbox
577
  - before-enforced-update
578
There is one exception: when the cache is enabled, the "before update
579
hierarchical select" event will not be triggered. This makes sense, because
580
updates from the cache are instantaneous.
581

  
582
An example of binding a function to the 'create-new-item' event of the second
583
(hsid == 1) hierarchical_select form item on the page:
584

  
585
  $('#hierarchical-select-1-wrapper')
586
  .bind('create-new-item', function() {
587
    // …
588
  });
589

  
590
And finally, you can trigger a special event to enforce an update (this can be
591
useful when you have changed a hierarchy through another form item, or for
592
live previews, or …). You can then also pass additional information that will
593
be POSTed. You can even disable normal updates, to manage that completely
594
yourself via enforced updates. This allows you to write a Hierarchical Select
595
implementation that gets some of its information ($params) from another form
596
item!
597
Suppose you'd like to enforce an update of the first (hsid == 0)
598
hierarchical_select form item on the page:
599

  
600
  $('#hierarchical-select-0-wrapper')
601
  .trigger('enforce-update');
602

  
603
Now let's move on to a more advanced example, in which we will disable normal
604
updates and let another form item (here a select) provide a part of the
605
information that will be used to render the Hierarchical Select. Effectively,
606
this other form item will *influence* the hierarchy that will be presented by
607
Hierarchical Select!
608

  
609
  $(document).ready(function() {
610
    Drupal.settings.specialfilter = {};
611

  
612
    // .specialfilter-first: a select form item
613
    // .specialfilter-second: a hierarchical_select form item
614

  
615
    update = function() {
616
      var selection = Drupal.settings.specialfilter.currentSelection;
617

  
618
      // Send an extra parameter via POST: dynamicParameter. This is the stored
619
      // selection.
620
      $('.specialfilter-second')
621
      .trigger('enforce-update',
622
        [
623
          { name : 'dynamicParameter', value : selection }
624
        ]
625
      );
626
    };
627

  
628
    attachHSBindings = function() {
629
      // When a user navigates the hierarchical_select form item, we still want to
630
      // POST the the extra dynamicParameter, or otherwise we will no longer have
631
      // a hierarchy in the hierarchical_select form item that really depends on
632
      // the select.
633
      $('.specialfilter-second .hierarchical-select > select')
634
      .change(function() { update(); });
635

  
636
      $('.specialfilter-second')
637
      .unbind('enforced-update').bind('enforced-update', function() { return attachHSBindings(); });
638
    };
639

  
640
    // Initialize after 25 ms, because otherwise the event binding of HS will
641
    // not yet be ready, and hence this won't have any effect
642
    setTimeout(function() {
643
      // Get the initial selection (before the user has changed anything).
644
      Drupal.settings.specialfilter.currentSelection = $('.specialfilter-first').attr('value');
645

  
646
      // When the select form item changes, we want to *store* that selection, and
647
      // update the hierarchical_select form item.
648
      $('.specialfilter-first')
649
      .change(function() {
650
        // Store the current selection.
651
        Drupal.settings.specialfilter.currentSelection = $(this).attr('value');
652
    
653
        update();
654
      });
655

  
656
      $('.specialfilter-second')
657
      .trigger('disable-updates');
658

  
659
      attachHSBindings();
660
    }, 25);
661
  });
662

  
663
The 'enforced-update' (notice the past tense!) event is triggered upon
664
completion.
665
An even more rarely used special event can be triggered to prepare the
666
hierarchical_select form element for a get submit: the 'prepare GET submit'
667
event. To use this event, the 'render_flat_select' setting should be enabled
668
in the config.
htmltest/sites/all/modules/hierarchical_select/LICENSE.txt
1
                    GNU GENERAL PUBLIC LICENSE
2
                       Version 2, June 1991
3

  
4
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
 Everyone is permitted to copy and distribute verbatim copies
7
 of this license document, but changing it is not allowed.
8

  
9
                            Preamble
10

  
11
  The licenses for most software are designed to take away your
12
freedom to share and change it.  By contrast, the GNU General Public
13
License is intended to guarantee your freedom to share and change free
14
software--to make sure the software is free for all its users.  This
15
General Public License applies to most of the Free Software
16
Foundation's software and to any other program whose authors commit to
17
using it.  (Some other Free Software Foundation software is covered by
18
the GNU Lesser General Public License instead.)  You can apply it to
19
your programs, too.
20

  
21
  When we speak of free software, we are referring to freedom, not
22
price.  Our General Public Licenses are designed to make sure that you
23
have the freedom to distribute copies of free software (and charge for
24
this service if you wish), that you receive source code or can get it
25
if you want it, that you can change the software or use pieces of it
26
in new free programs; and that you know you can do these things.
27

  
28
  To protect your rights, we need to make restrictions that forbid
29
anyone to deny you these rights or to ask you to surrender the rights.
30
These restrictions translate to certain responsibilities for you if you
31
distribute copies of the software, or if you modify it.
32

  
33
  For example, if you distribute copies of such a program, whether
34
gratis or for a fee, you must give the recipients all the rights that
35
you have.  You must make sure that they, too, receive or can get the
36
source code.  And you must show them these terms so they know their
37
rights.
38

  
39
  We protect your rights with two steps: (1) copyright the software, and
40
(2) offer you this license which gives you legal permission to copy,
41
distribute and/or modify the software.
42

  
43
  Also, for each author's protection and ours, we want to make certain
44
that everyone understands that there is no warranty for this free
45
software.  If the software is modified by someone else and passed on, we
46
want its recipients to know that what they have is not the original, so
47
that any problems introduced by others will not reflect on the original
48
authors' reputations.
49

  
50
  Finally, any free program is threatened constantly by software
51
patents.  We wish to avoid the danger that redistributors of a free
52
program will individually obtain patent licenses, in effect making the
53
program proprietary.  To prevent this, we have made it clear that any
54
patent must be licensed for everyone's free use or not licensed at all.
55

  
56
  The precise terms and conditions for copying, distribution and
57
modification follow.
58

  
59
                    GNU GENERAL PUBLIC LICENSE
60
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61

  
62
  0. This License applies to any program or other work which contains
63
a notice placed by the copyright holder saying it may be distributed
64
under the terms of this General Public License.  The "Program", below,
65
refers to any such program or work, and a "work based on the Program"
66
means either the Program or any derivative work under copyright law:
67
that is to say, a work containing the Program or a portion of it,
68
either verbatim or with modifications and/or translated into another
69
language.  (Hereinafter, translation is included without limitation in
70
the term "modification".)  Each licensee is addressed as "you".
71

  
72
Activities other than copying, distribution and modification are not
73
covered by this License; they are outside its scope.  The act of
74
running the Program is not restricted, and the output from the Program
75
is covered only if its contents constitute a work based on the
76
Program (independent of having been made by running the Program).
77
Whether that is true depends on what the Program does.
78

  
79
  1. You may copy and distribute verbatim copies of the Program's
80
source code as you receive it, in any medium, provided that you
81
conspicuously and appropriately publish on each copy an appropriate
82
copyright notice and disclaimer of warranty; keep intact all the
83
notices that refer to this License and to the absence of any warranty;
84
and give any other recipients of the Program a copy of this License
85
along with the Program.
86

  
87
You may charge a fee for the physical act of transferring a copy, and
88
you may at your option offer warranty protection in exchange for a fee.
89

  
90
  2. You may modify your copy or copies of the Program or any portion
91
of it, thus forming a work based on the Program, and copy and
92
distribute such modifications or work under the terms of Section 1
93
above, provided that you also meet all of these conditions:
94

  
95
    a) You must cause the modified files to carry prominent notices
96
    stating that you changed the files and the date of any change.
97

  
98
    b) You must cause any work that you distribute or publish, that in
99
    whole or in part contains or is derived from the Program or any
100
    part thereof, to be licensed as a whole at no charge to all third
101
    parties under the terms of this License.
102

  
103
    c) If the modified program normally reads commands interactively
104
    when run, you must cause it, when started running for such
105
    interactive use in the most ordinary way, to print or display an
106
    announcement including an appropriate copyright notice and a
107
    notice that there is no warranty (or else, saying that you provide
108
    a warranty) and that users may redistribute the program under
109
    these conditions, and telling the user how to view a copy of this
110
    License.  (Exception: if the Program itself is interactive but
111
    does not normally print such an announcement, your work based on
112
    the Program is not required to print an announcement.)
113

  
114
These requirements apply to the modified work as a whole.  If
115
identifiable sections of that work are not derived from the Program,
116
and can be reasonably considered independent and separate works in
117
themselves, then this License, and its terms, do not apply to those
118
sections when you distribute them as separate works.  But when you
119
distribute the same sections as part of a whole which is a work based
120
on the Program, the distribution of the whole must be on the terms of
121
this License, whose permissions for other licensees extend to the
122
entire whole, and thus to each and every part regardless of who wrote it.
123

  
124
Thus, it is not the intent of this section to claim rights or contest
125
your rights to work written entirely by you; rather, the intent is to
126
exercise the right to control the distribution of derivative or
127
collective works based on the Program.
128

  
129
In addition, mere aggregation of another work not based on the Program
130
with the Program (or with a work based on the Program) on a volume of
131
a storage or distribution medium does not bring the other work under
132
the scope of this License.
133

  
134
  3. You may copy and distribute the Program (or a work based on it,
135
under Section 2) in object code or executable form under the terms of
136
Sections 1 and 2 above provided that you also do one of the following:
137

  
138
    a) Accompany it with the complete corresponding machine-readable
139
    source code, which must be distributed under the terms of Sections
140
    1 and 2 above on a medium customarily used for software interchange; or,
141

  
142
    b) Accompany it with a written offer, valid for at least three
143
    years, to give any third party, for a charge no more than your
144
    cost of physically performing source distribution, a complete
145
    machine-readable copy of the corresponding source code, to be
146
    distributed under the terms of Sections 1 and 2 above on a medium
147
    customarily used for software interchange; or,
148

  
149
    c) Accompany it with the information you received as to the offer
150
    to distribute corresponding source code.  (This alternative is
151
    allowed only for noncommercial distribution and only if you
152
    received the program in object code or executable form with such
153
    an offer, in accord with Subsection b above.)
154

  
155
The source code for a work means the preferred form of the work for
156
making modifications to it.  For an executable work, complete source
157
code means all the source code for all modules it contains, plus any
158
associated interface definition files, plus the scripts used to
159
control compilation and installation of the executable.  However, as a
160
special exception, the source code distributed need not include
161
anything that is normally distributed (in either source or binary
162
form) with the major components (compiler, kernel, and so on) of the
163
operating system on which the executable runs, unless that component
164
itself accompanies the executable.
165

  
166
If distribution of executable or object code is made by offering
167
access to copy from a designated place, then offering equivalent
168
access to copy the source code from the same place counts as
169
distribution of the source code, even though third parties are not
170
compelled to copy the source along with the object code.
171

  
172
  4. You may not copy, modify, sublicense, or distribute the Program
173
except as expressly provided under this License.  Any attempt
174
otherwise to copy, modify, sublicense or distribute the Program is
175
void, and will automatically terminate your rights under this License.
176
However, parties who have received copies, or rights, from you under
177
this License will not have their licenses terminated so long as such
178
parties remain in full compliance.
179

  
180
  5. You are not required to accept this License, since you have not
181
signed it.  However, nothing else grants you permission to modify or
182
distribute the Program or its derivative works.  These actions are
183
prohibited by law if you do not accept this License.  Therefore, by
184
modifying or distributing the Program (or any work based on the
185
Program), you indicate your acceptance of this License to do so, and
186
all its terms and conditions for copying, distributing or modifying
187
the Program or works based on it.
188

  
189
  6. Each time you redistribute the Program (or any work based on the
190
Program), the recipient automatically receives a license from the
191
original licensor to copy, distribute or modify the Program subject to
192
these terms and conditions.  You may not impose any further
193
restrictions on the recipients' exercise of the rights granted herein.
194
You are not responsible for enforcing compliance by third parties to
195
this License.
196

  
197
  7. If, as a consequence of a court judgment or allegation of patent
198
infringement or for any other reason (not limited to patent issues),
199
conditions are imposed on you (whether by court order, agreement or
200
otherwise) that contradict the conditions of this License, they do not
201
excuse you from the conditions of this License.  If you cannot
202
distribute so as to satisfy simultaneously your obligations under this
203
License and any other pertinent obligations, then as a consequence you
204
may not distribute the Program at all.  For example, if a patent
205
license would not permit royalty-free redistribution of the Program by
206
all those who receive copies directly or indirectly through you, then
207
the only way you could satisfy both it and this License would be to
208
refrain entirely from distribution of the Program.
209

  
210
If any portion of this section is held invalid or unenforceable under
211
any particular circumstance, the balance of the section is intended to
212
apply and the section as a whole is intended to apply in other
213
circumstances.
214

  
215
It is not the purpose of this section to induce you to infringe any
216
patents or other property right claims or to contest validity of any
217
such claims; this section has the sole purpose of protecting the
218
integrity of the free software distribution system, which is
219
implemented by public license practices.  Many people have made
220
generous contributions to the wide range of software distributed
221
through that system in reliance on consistent application of that
222
system; it is up to the author/donor to decide if he or she is willing
223
to distribute software through any other system and a licensee cannot
224
impose that choice.
225

  
226
This section is intended to make thoroughly clear what is believed to
227
be a consequence of the rest of this License.
228

  
229
  8. If the distribution and/or use of the Program is restricted in
230
certain countries either by patents or by copyrighted interfaces, the
231
original copyright holder who places the Program under this License
232
may add an explicit geographical distribution limitation excluding
233
those countries, so that distribution is permitted only in or among
234
countries not thus excluded.  In such case, this License incorporates
235
the limitation as if written in the body of this License.
236

  
237
  9. The Free Software Foundation may publish revised and/or new versions
238
of the General Public License from time to time.  Such new versions will
239
be similar in spirit to the present version, but may differ in detail to
240
address new problems or concerns.
241

  
242
Each version is given a distinguishing version number.  If the Program
243
specifies a version number of this License which applies to it and "any
244
later version", you have the option of following the terms and conditions
245
either of that version or of any later version published by the Free
246
Software Foundation.  If the Program does not specify a version number of
247
this License, you may choose any version ever published by the Free Software
248
Foundation.
249

  
250
  10. If you wish to incorporate parts of the Program into other free
251
programs whose distribution conditions are different, write to the author
252
to ask for permission.  For software which is copyrighted by the Free
253
Software Foundation, write to the Free Software Foundation; we sometimes
254
make exceptions for this.  Our decision will be guided by the two goals
255
of preserving the free status of all derivatives of our free software and
256
of promoting the sharing and reuse of software generally.
257

  
258
                            NO WARRANTY
259

  
260
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
262
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
266
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
267
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
REPAIR OR CORRECTION.
269

  
270
  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
POSSIBILITY OF SUCH DAMAGES.
279

  
280
                     END OF TERMS AND CONDITIONS
281

  
282
            How to Apply These Terms to Your New Programs
283

  
284
  If you develop a new program, and you want it to be of the greatest
285
possible use to the public, the best way to achieve this is to make it
286
free software which everyone can redistribute and change under these terms.
287

  
288
  To do so, attach the following notices to the program.  It is safest
289
to attach them to the start of each source file to most effectively
290
convey the exclusion of warranty; and each file should have at least
291
the "copyright" line and a pointer to where the full notice is found.
292

  
293
    <one line to give the program's name and a brief idea of what it does.>
294
    Copyright (C) <year>  <name of author>
295

  
296
    This program is free software; you can redistribute it and/or modify
297
    it under the terms of the GNU General Public License as published by
298
    the Free Software Foundation; either version 2 of the License, or
299
    (at your option) any later version.
300

  
301
    This program is distributed in the hope that it will be useful,
302
    but WITHOUT ANY WARRANTY; without even the implied warranty of
303
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
304
    GNU General Public License for more details.
305

  
306
    You should have received a copy of the GNU General Public License along
307
    with this program; if not, write to the Free Software Foundation, Inc.,
308
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309

  
310
Also add information on how to contact you by electronic and paper mail.
311

  
312
If the program is interactive, make it output a short notice like this
313
when it starts in an interactive mode:
314

  
315
    Gnomovision version 69, Copyright (C) year name of author
316
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
    This is free software, and you are welcome to redistribute it
318
    under certain conditions; type `show c' for details.
319

  
320
The hypothetical commands `show w' and `show c' should show the appropriate
321
parts of the General Public License.  Of course, the commands you use may
322
be called something other than `show w' and `show c'; they could even be
323
mouse-clicks or menu items--whatever suits your program.
324

  
325
You should also get your employer (if you work as a programmer) or your
326
school, if any, to sign a "copyright disclaimer" for the program, if
327
necessary.  Here is a sample; alter the names:
328

  
329
  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
  `Gnomovision' (which makes passes at compilers) written by James Hacker.
331

  
332
  <signature of Ty Coon>, 1 April 1989
333
  Ty Coon, President of Vice
334

  
335
This General Public License does not permit incorporating your program into
336
proprietary programs.  If your program is a subroutine library, you may
337
consider it more useful to permit linking proprietary applications with the
338
library.  If this is what you want to do, use the GNU Lesser General
339
Public License instead of this License.
htmltest/sites/all/modules/hierarchical_select/README.txt
1

  
2
Description
3
-----------
4
This module defines the "hierarchical_select" form element, which is a greatly
5
enhanced way for letting the user select items in a hierarchy.
6

  
7
Hierarchical Select has the ability to save the entire lineage of a selection
8
or only the "deepest" selection. You can configure it to force the user to
9
make a selection as deep as possible in the tree, or allow the user to select
10
an item anywhere in the tree. Levels can be labeled, you can configure limit
11
the number of items that can be selected, configure a title for the dropbox,
12
choose a site-wide animation delay, and so on. You can even create new items
13
and levels through Hierarchical Select!
14

  
15

  
16
Integrates with
17
---------------
18
* Taxonomy (Drupal core)
19

  
20

  
21
Installation
22
------------
23
1) Place this module directory in your "modules" folder (this will usually be
24
"sites/all/modules/"). Don't install your module in Drupal core's "modules"
25
folder, since that will cause problems and is bad practice in general. If
26
"sites/all/modules" doesn't exist yet, just create it.
27

  
28
2) Enable the Hierarchical Select and Hierarchical Select Taxonomy modules.
29

  
30
3) If you want to use it for one or more of your vocabularies, go to
31
admin/structure/types and click the "manage fields" link for a content type on
32
which you're using a Term reference field. Click the "edit" link for this Term
33
reference field and then go to the "widget type" tab in the upper right corner.
34
There, you can choose the "Hierarchical Select" widget type, and when you do,
35
the entire Hierarchical Select configuration UI will appear: here you'll find
36
a whole range of Hierarchical Select settings. All settings are explained
37
there as well!
38

  
39

  
40
Troubleshooting
41
---------------
42
If you ever have problems, make sure to go through these steps:
43

  
44
1) Go to admin/reports/status (i.e. the Status Report). Ensure that the status
45
   of the Hierarchical Select module is ok.
46

  
47
2) Ensure that the page isn't being served from your browser's cache. Use
48
   CTRL+R in Windows/Linux browsers, CMD+R in Mac OS X browsers to enforce the
49
   browser to reload everything, preventing it from using its cache.
50

  
51
3) When you're getting a JS alert with the following message: "Received an
52
   invalid response from the server.", ensure that the page (of which this
53
   form is a part) is *not* being cached.
54

  
55
4) When Hierarchical Select seems to be misbehaving in a certain use case in
56
   which terms with multiple parents are being used, make sure to enable the
57
   "Save term lineage" setting.
58
   Note: you may have to repeat this for every configuration in which the
59
   vocabulary with terms that have multiple parents are being used. E.g. if
60
   such a vocabulary is called "A", then go to 
61
      admin/config/content/hierarchical_select/configs
62
   and edit all configuration that have "A" in the "Hierarchy" column.
63

  
64
In case of problems, don't forget to try a hard refresh in your browser!
65

  
66

  
67
Limitations
68
-----------
69
- Creating new items in the hierarchy in a multiple parents hierarchy (more
70
  scientifically: a directed acyclic graph) is *not* supported.
71
- Not the entire scalability problem can be solved by installing this set of
72
  modules; read the maximum scalability section for details.
73
- The child indicators only work in Firefox. This *cannot* be supported in
74
  Safari or IE. See http://drupal.org/node/180691#comment-1044691.
75
- The special [save-lineage-termpath] token only works with content_taxonomy
76
  fields as long as you have the "Save option" set to either "Tag" or "Both".
77
- In hierarchies where items can have multiple parent items and where you have
78
  enabled Hierarchical Select's "save lineage" setting, it is impossible to
79
  remember individual hierarchies, unless the underlying module supports it.
80
  So far, no module supports this. Hierarchical Select is just a form element,
81
  not a system for storing hierarchies.
82
  For example, if you have created a multiple parent vocabulary through the
83
  Taxonomy module, and you have terms like this:
84
   A -> C
85
   A -> D
86
   B -> C
87
   B -> D
88
  If you then save any two lineages in which all four terms exist, all four
89
  lineages will be rendered by Hierarchical Select, because only the four
90
  terms are stored and thus there is no way to recover the originally selected
91
  two lineages.
92
- You can NOT expect the Hierarchical Select Taxonomy module to automagically
93
  fix all existing nodes when you enable or disable the "save lineage" setting
94
  and neither can you expect it to keep working properly when you reorganize
95
  the term hierarchy. There's nothing I can do about this. Hierarchical Select
96
  is merely a form element, it can't be held responsible for features that
97
  Drupal core lacks or supports poorly.
98
  See the following issues:
99
  * http://drupal.org/node/1023762#comment-4054386
100
  * http://drupal.org/node/976394#comment-4054456
101

  
102

  
103
Rendering hierarchy lineages when viewing content
104
-------------------------------------------------
105
Hierarchical Select is obviously only used for input. Hence it is only used on
106
the create/edit forms of content.
107
Combine that with the fact that Hierarchical Select is the only module capable
108
of restoring the lineage of saved items (e.g. Taxonomy terms). None of the
109
Drupal core modules is capable of storing the lineage, but Hierarchical Select
110
can reconstruct it relatively efficiently. However, this lineage is only
111
visible when creating/editing content, not when viewing it.
112
To allow you to display the lineages of stored items, I have provided a
113
theming function that you can call from within e.g. your node.tpl.php file:
114
the theme_hierarchical_select_selection_as_lineages($selection, $config)
115
function.
116

  
117
Sample usage (using Taxonomy and Hierarchical Select Taxonomy):
118
  <?php if ($taxonomy):
119
    require_once(drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc');
120
    $vid = 2;                                                    // Vocabulary ID. CHANGE THIS!
121
    $config_id = "taxonomy-$vid";                                // Generate the config ID.
122
    $config = hierarchical_select_common_config_get($config_id); // Get the Hierarchical Select configuration through the config ID.
123
    $config['module'] = 'hs_taxonomy';                           // Set the module.
124
    $config['params']['vid'] = $vid;                             // Set the parameters.
125
  ?>
126
    <div class="terms"><?php print theme('hierarchical_select_selection_as_lineages', $node->taxonomy, $config); ?></div>
127
  <?php endif; ?>
128

  
129
This will automatically render all lineages for vocabulary 2 (meaning that if
130
you want to render the lineages of multiple vocabularies, you'll have to clone
131
this piece of code once for every vocabulary). It will also automatically get
132
the current Hierarchical Select configuration for that vocabulary.
133

  
134
Alternatively, you could provide the $config array yourself. Only three keys
135
are required: 1) module, 2) params, 3) save_lineage. For example:
136
  <?php if ($taxonomy):
137
    $vid = 2;                          // Vocabulary ID. CHANGE THIS!
138
    $config['module'] = 'hs_taxonomy'; // Set the module.
139
    $config['params']['vid'] = $vid;   // Set the parameters.
140
    $config['save_lineage'] = 1;       // save_lineage setting is enabled. CHANGE THIS!
141
  ?>
142
    <div class="terms"><?php print theme('hierarchical_select_selection_as_lineages', $node->taxonomy, $config); ?></div>
143
  <?php endif; ?>
144

  
145
If you don't like how the lineage is displayed, simply override the
146
theme_hierarchical_select_selection_as_lineages() function from within your
147
theme, create e.g. garland_hierarchical_select_selection_as_lineages().
148

  
149

  
150
Setting a fixed size
151
--------------------
152
When you don't want users to be able to resize a hierarchical select
153
themselves, you can set a fixed size in advance yourself
154
Setting #size to >1 does *not* generate #multiple = TRUE selects! And the
155
opposite is also true. #multiple sets the "multiple" HTML attribute. This
156
enables the user to select multiple options of a select. #size just controls
157
the "size" HTML attribute. This increases the vertical size of selects,
158
thereby showing more options.
159
See http://www.w3.org/TR/html401/interact/forms.html#adef-size-SELECT.
160

  
161

  
162
Sponsors
163
--------
164
* Initial development:
165
   Paul Ektov of http://autobin.ru.
166
* Abstraction, to let other modules than taxonomy hook in:
167
   Etienne Leers of http://creditcalc.biz.
168
* Support for saving the term lineage:
169
   Paul Ektov of http://autobin.ru.
170
* Multiple select support:
171
   Marmaladesoul, http://marmaladesoul.com.
172
* Taxonomy Subscriptions support:
173
   Mr Bidster Inc.
174
* Ability to create new items/levels:
175
   The Worx Company, http://www.worxco.com.
176
* Ability to only show items that are associated with at least one entity:
177
   Merge, http://merge.nl.
178
* Views 2 support:
179
   Merge, http://merge.nl.
180
* Initial Drupal 7 port + folow-up fixes:
181
   PingV, http://pingv.com.
182
* Port of "save lineage" functionality to Drupal 7:
183
   Bancard Data Service
184

  
185

  
186
Author
187
------
188
Wim Leers
189

  
190
* website: http://wimleers.com/
191
* contact: http://wimleers.com/contact
192

  
193
The author can be contacted for paid development on this module. This can vary
194
from new features to Hierarchical Select itself, to new implementations (i.e.
195
support for new kinds of hierarchies).
htmltest/sites/all/modules/hierarchical_select/TODO.txt
1
HS core:
2
✓ port: initial port
3
✓ fix: JS code cleanup (remove hardcoded hacks)
4
✓ fix: title + description (i.e. something's off with the theme wrapper)
5
✓ fix: #value_callback may be necessary? (see file.module) OR: ensure #return_value works
6
✓ fix: #element_validate callback: _hierarchical_select_validate() — verify this still works
7
✓ port: support multiple HS on the same page
8
✓ port: admin UI
9
✓ port: "dropbox" support
10
✓ upgrade path: delete cache_hierarchical_select
11
✓ upgrade path: documentation
12
✓ port: "create new item" support — see http://drupal.org/node/1087620
13
✓ port: status report
14
- port: render_flat_select support
15
- port: client-side caching (use _hierarchical_select_json_convert_hierarchy_to_cache())
16
- feature: live preview of HS on the common config form
17
- refactor: use the proper #value_callback -> #process callback -> #after_build callback pipeline as described in the documentation for form_builder() in form.inc
18

  
19
Taxonomy:
20
✓ port: admin UI
21
✓ port: "dropbox" support
22
✓ port: "save lineage" support (i.e. support multiple parents, automatic warning shown through hs_taxonomy_hierarchical_select_root_level())
23
✓ port: field formatters (from content_taxonomy)
24
✓ port: taxonomy term (create/edit) form should be altered to include HS
25
✓ upgrade path: migrate settings (no migration necessary)
26
✓ upgrade path: documentation (no migration, no docs)
27
✓ port: "create new item" support — see http://drupal.org/node/1087620
28
- port: "entity_count" support — see http://drupal.org/node/1068462
29
- refactor: use the vocabulary machine name internally instead of the vid
30
- port: token support — see http://drupal.org/node/1248908
31
- port: forum support
32
- refactor: optimize HS API implementation: take advantage of improvements in Taxonomy
33

  
34
HS Taxonomy Views: 
35
- everything — see http://drupal.org/node/1170192
36

  
37
Menu: 
38
✓ everything
39

  
40
Flat List:
41
✓ everything
42

  
43
Small Hierarchy:
44
✓ everything
htmltest/sites/all/modules/hierarchical_select/UPGRADE.txt
1
# Upgrading (from Drupal 6 to 7)
2

  
3
1. **BE WARE THAT NOT ALL FUNCTIONALITY HAS BEEN PORTED!**
4

  
5
	Make sure that you know if the part of Hierarchical Select's functionality
6
	that you want to use has been ported. Otherwise, you may be in for a
7
	frustrating upgrade experience.
8

  
9
	See the included TODO.txt file for details. In a nutshell:
10

  
11
	- Taxonomy support is almost complete, only "create new item", "entity count" and token support are missing
12
	- Forum support has **not** yet been ported (but relies on Taxonomy, so this is trivial)
13
	- Taxonomy Views support has **not** yet been ported
14
	- Menu support has **not** yet been ported
15

  
16
2. Upgrade this module just like any other: delete the old module, copy the
17
	files of the new module and run update.php.  
18
	For details, see <http://drupal.org/node/570162>.
19

  
20
3. That's it! :)
htmltest/sites/all/modules/hierarchical_select/hierarchical_select-rtl.css
1

  
2

  
3
/* The hierarchical select. */
4
.hierarchical-select-wrapper .hierarchical-select .selects {
5
  float: right; /* If a block is floated, it won't consume as much width as
6
                   available, only just enough. This allows the grippie to
7
                   perfectly scale with the with consumed by the selects. */ 
8
}
9

  
10
.hierarchical-select-wrapper .hierarchical-select .selects .grippie {
11
  clear: right; /* clear: left; */
12
  height: 9px;
13
  overflow: hidden;
14
  background: #eee url(images/grippie.png) no-repeat center 2px;
15
  border: 1px solid #ddd;
16
  border-top-width: 0;
17
  cursor: s-resize;
18
  margin-left: 0.5em; /* margin-right: 0.5em; */ /* Give the grippie the same margin as each select. */
19
  min-width: 70px; /* Hack for IE, makes the grip usable, but not yet the same as in other browsers. */
20
}
21

  
22
.hierarchical-select-wrapper .hierarchical-select select,
23
.hierarchical-select-wrapper .hierarchical-select .add-to-dropbox,
24
.hierarchical-select-wrapper .hierarchical-select .create-new-item {
25
  margin-left: .5em;
26
  float: right;
27
}
28

  
29

  
30
/* The pseudo-modal window for creating a new item or new level. */
31
.hierarchical-select-wrapper .hierarchical-select .create-new-item-create,
32
.hierarchical-select-wrapper .hierarchical-select .create-new-item-cancel {
33
  float: left;
34
  margin-right: .4em;
35
}
36

  
37
.hierarchical-select-wrapper .hierarchical-select .create-new-item-input {
38
  float: right;
39
  clear: left;
40
}
41

  
42

  
43
/* Child level indicator. */
44
.hierarchical-select-wrapper .hierarchical-select option.has-children {
45
  background: url(images/arrow-rtl.png) no-repeat left center;
46
}
47

  
48

  
49
/* Dropbox limit warning.*/
50
p.hierarchical-select-dropbox-limit-warning {
51
  padding-right: .5em;
52
}
htmltest/sites/all/modules/hierarchical_select/hierarchical_select.admin.inc
1
<?php
2

  
3

  
4
/**
5
 * @file
6
 * Module settings and configuration administration UI.
7
 */
8

  
9

  
10
/**
11
 * Form definition; admin settings.
12
 */
13
function hierarchical_select_admin_settings($form, &$form_state) {
14
  $form['description'] = array(
15
    '#markup' => t('All settings below will be used as site-wide defaults.'),
16
    '#prefix' => '<div>',
17
    '#suffix' => '</div>',
18
  );
19
  $form['hierarchical_select_animation_delay'] = array(
20
    '#type' => 'textfield',
21
    '#title' => t('Animation delay'),
22
    '#description' => t(
23
      'The delay that will be used for the "drop in/out" effect when a
24
      hierarchical select is being updated (in milliseconds).'
25
    ),
26
    '#size' => 5,
27
    '#maxlength' => 5,
28
    '#default_value' => variable_get('hierarchical_select_animation_delay', 400),
29
  );
30
  $form['hierarchical_select_level_labels_style'] = array(
31
    '#type' => 'select',
32
    '#title' => t('Level labels style'),
33
    '#description' => t(
34
      'The style that will be used for level labels. This is not supported by
35
      all browsers! If you want a consistent interface, choose to use no
36
      style.'
37
    ),
38
    '#options' => array(
39
      'none' => t('No style'),
40
      'bold' => t('Bold'),
41
      'inversed' => t('Inversed'),
42
      'underlined' => t('Underlined'),
43
    ),
44
    '#default_value' => variable_get('hierarchical_select_level_labels_style', 'none'),
45
  );
46
  // TODO: port the HS client-side cache system to Drupal 7.
47
  /*
48
  $form['hierarchical_select_js_cache_system'] = array(
49
    '#type' => 'radios',
50
    '#title' => t('Cache in a HTML 5 client-side database'),
51
    '#description' => t(
52
      'This feature only works in browsers that support the
53
      <a href="!spec-url">HTML 5 client-side database storage specification
54
      </a>.</br>
55
      After enabling this, you will notice (in supporting browsers) that
56
      refreshing the hierarchical select will not require a request to the
57
      server when a part is being requested that has been requested before.',
58
      array('!spec-url' => url('http://www.whatwg.org/specs/web-apps/current-work/multipage/section-sql.html'))
59
    ),
60
    '#options' => array(
61
      0 => t('Disabled'),
62
      1 => t('Enabled'),
63
    ),
64
    '#default_value' => variable_get('hierarchical_select_js_cache_system', 0),
65
  );
66
  */
67

  
68
  return system_settings_form($form);
69
}
70

  
71
/**
72
 * Menu callback; a table that lists all Hierarchical Select configs.
73
 */
74
function hierarchical_select_admin_configs() {
75
  $header = array(t('Hierarchy type'), t('Hierarchy'), t('Entity type'), t('Bundle'), t('Context type'), t('Context'), t('Actions'));
76

  
77
  // Retrieve all information items
78
  $info_items = array();
79
  foreach (module_implements('hierarchical_select_config_info') as $module) {
80
    $info_items = array_merge_recursive($info_items, module_invoke($module, 'hierarchical_select_config_info'));
81
  }
82

  
83
  // Process the retrieved information into rows.
84
  $rows = array();
85
  foreach ($info_items as $id => $item) {
86
    $config_id = $item['config_id'];
87

  
88
    $rows[$id] = array(
89
      $item['hierarchy type'],
90
      $item['hierarchy'],
91
      $item['entity type'],
92
      $item['bundle'],
93
      $item['context type'],
94
      $item['context'],
95
      theme('links', array('links' => array(
96
          array(
97
            'title' => t('Edit'),
98
            'href' => $item['edit link'],
99
            'fragment' => "hierarchical-select-config-form-$config_id",
100
          ),
101
          array(
102
            'title' => t('Export'),
103
            'href' => "admin/config/content/hierarchical_select/export/$config_id",
104
          ),
105
          array(
106
            'title' => t('Import'),
107
            'href' => "admin/config/content/hierarchical_select/import/$config_id",
108
          ),
109
        ))),
110
    );
111
  }
112

  
113
  return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array(), 'caption' => t('Overview of all Hierarchical Select configurations.')));
114
}
115

  
116
/**
117
 * Menu callback; a table that lists all Hierarchical Select implementations
118
 * and the features they support.
119
 */
120
function hierarchical_select_admin_implementations() {
121
  $output = '';
122
  $header = array(t('Implementation (module)'), t('Hierarchy type'), t('Entity type'), t('Create new items'), t('Entity count'));
123

  
124
  // Retrieve all information items
125
  $rows = array();
126
  foreach (module_implements('hierarchical_select_root_level') as $module) {
127
    $filename = db_query("SELECT filename FROM {system} WHERE type = :type AND name = :name", array(':type' => 'module', ':name' => $module))->fetchField();
128
    $module_info = drupal_parse_info_file(dirname($filename) . "/$module.info");
129
    // Try to extract the hierarchy type from the optional hook_hierarchical_select_config_info().
130
    $hierarchy_type = $entity_type = t('unknown');
131
    if (module_hook($module, 'hierarchical_select_implementation_info')) {
132
      $implementation = module_invoke($module, 'hierarchical_select_implementation_info');
133
      $hierarchy_type = $implementation['hierarchy type'];
134
      $entity_type    = $implementation['entity type'];
135
    }
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff