source: sipes/0.3-modules/hs_content_taxonomy_description/hs_content_taxonomy_description.admin.inc @ dc8ba62

stableversion-3.0
Last change on this file since dc8ba62 was 303fae2, checked in by José Gregorio Puentes <jpuentes@…>, 9 años ago

se agregaron los modulos

  • Propiedad mode establecida a 100755
File size: 3.8 KB
Línea 
1<?php
2
3/**
4 * Form definition; configuration form for Hierarchical Select as the widget
5 * for a content_taxonomy field.
6 *
7 * @param $content_type_name
8 *   Name of a content type. Provides necessary context.
9 * @param $field_name
10 *   Name of a field. Provides necessary context.
11 */
12function hs_content_taxonomy_description_config_form($form_state, $content_type_name, $field_name) {
13  require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');
14
15  drupal_add_css(drupal_get_path('module', 'hs_content_taxonomy_description') .'/hs_content_taxonomy_description.css');
16
17  $content_type = content_types($content_type_name);
18
19  $field = $content_type['fields'][$field_name];
20
21  // Extract the necessary context from the $field array.
22  $vid = $field['vid'];
23  $tid = (isset($field['tid'])) ? $field['tid'] : NULL;
24  $depth = (empty($field['depth'])) ? 0 : $field['depth'];
25
26  // Add the Hierarchical Select config form.
27  $module = 'hs_content_taxonomy_description';
28  $params = array(
29    'vid'   => $vid,
30    'tid'   => $tid,
31    'depth' => $depth,
32  );
33  $config_id = "content-taxonomy-$field_name";
34  $vocabulary = taxonomy_vocabulary_load($vid);
35  $defaults = array(
36  // Enable the save_lineage setting by default if the multiple parents
37  // vocabulary option is enabled.
38    'save_lineage' => (int) ($vocabulary->hierarchy == 2),
39    'editability' => array(
40      'max_levels' => min($depth, _hs_taxonomy_hierarchical_select_get_depth($vid)),
41    ),
42  );
43  // If this config is being created (not edited), then enable the dropbox if
44  // this is a "multiple values" field. This allows for an intuitive
45  // transition to a Hierarchical Select widget.
46  if (variable_get('hsd_config_'. $config_id, FALSE) === FALSE) {
47    $defaults['dropbox']['status'] = $field['multiple'];
48  }
49  $strings = array(
50    'hierarchy'   => t('vocabulary'),
51    'hierarchies' => t('vocabularies'),
52    'item'        => t('term'),
53    'items'       => t('terms'),
54    'item_type'   => t('term type'),
55    'entity'      => t('node'),
56    'entities'    => t('nodes'),
57  );
58  $max_hierarchy_depth = min(($depth == 0) ? 9 : $depth, _hs_taxonomy_hierarchical_select_get_depth($vid));
59  $preview_is_required = $field['required'];
60  $form['hierarchical_select_config'] = hierarchical_select_common_config_form($module, $params, $config_id, $defaults, $strings, $max_hierarchy_depth, $preview_is_required);
61
62  $form['link'] = array(
63    '#value' => l('Back to the field configuration', 'admin/content/node-type/'. str_replace('_', '-', $content_type['type']) .'/fields/'. $field_name),
64    '#prefix' => '<div class="cck-hierarchical-select-back-link">',
65    '#suffix' => '</div>',
66    '#weight' => -5,
67  );
68
69  $form['save'] = array(
70    '#type' => 'submit',
71    '#value' => t('Save'),
72  );
73  $form['#content_type_name'] = $content_type_name;
74  $form['#field_name'] = $field_name;
75
76  // Add the the submit handler for the Hierarchical Select config form.
77  $parents = array('hierarchical_select_config');
78  $form['#submit'][] = 'hierarchical_select_common_config_form_submit';
79  $form['#hs_common_config_form_parents'] = $parents;
80
81  $form['#submit'][] = 'hs_content_taxonomy_description_common_config_form_submit';
82
83  return $form;
84}
85
86/**
87 * Additional submit callback to update the multiple values field setting.
88 */
89function hs_content_taxonomy_description_common_config_form_submit( &$form, &$form_state) {
90  $config = $form_state['values']['hierarchical_select_config'];
91  $multiple_values = ($config['save_lineage'] | $config['dropbox']['status']);
92  require_once(drupal_get_path('module', 'content') . '/includes/content.crud.inc');
93  $fields = content_field_instance_read(array('type_name' => $form['#content_type_name'], 'field_name' => $form['#field_name']));
94  foreach ($fields as $field) {
95    $field['multiple'] = $multiple_values;
96    content_field_instance_update($field);
97  }
98}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.