? .git ? 371957_2.patch ? 371957_4.patch ? 371957_bdragon.patch ? project-371957_2.patch Index: project.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project/project.inc,v retrieving revision 1.147 diff -u -p -r1.147 project.inc --- project.inc 25 Nov 2009 16:38:15 -0000 1.147 +++ project.inc 18 Apr 2010 20:19:08 -0000 @@ -79,15 +79,27 @@ function project_project_form($node, $fo '#required' => TRUE, ); $select_size = max(5, 2*count($top_level)); - foreach ($options as $tid => $values) { - $form['project_taxonomy']["tid_$tid"] = array( - '#title' => t('!type categories', array('!type' => $top_level[$tid])), - '#type' => 'select', - '#multiple' => TRUE, - '#options' => $values, - '#default_value' => $current_options, - '#attributes' => array('size' => min($select_size, count($values))), - ); + foreach (array_keys($top_level) as $tid) { + if (isset($options[$tid])) { + $values = $options[$tid]; + $form['project_taxonomy']["tid_$tid"] = array( + '#title' => t('@type categories', array('@type' => $top_level[$tid])), + '#type' => 'select', + '#multiple' => TRUE, + '#options' => $values, + '#default_value' => $current_options, + '#attributes' => array('size' => min($select_size, count($values))), + ); + } + else { + // provide a div for all top-level terms so that outside elements + // (vocabularies) can be shifted into the project taxonomy fieldset + // in the same paradigm as the modules sub-terms + $form['project_taxonomy']["tid_$tid"] = array( + '#type' => 'form_element', + '#id' => 'edit-tid-' . $tid, + ); + } } } Index: project.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project/project.js,v retrieving revision 1.3 diff -u -p -r1.3 project.js --- project.js 12 Jan 2009 20:07:19 -0000 1.3 +++ project.js 18 Apr 2010 20:19:08 -0000 @@ -7,6 +7,7 @@ Drupal.behaviors.projectAuto = function if (this.checked) { tid = this.value; } + Drupal.projectMoveElement(this.value); }) .click(function () { Drupal.projectSetTaxonomy(this.value); @@ -14,20 +15,28 @@ Drupal.behaviors.projectAuto = function Drupal.projectSetTaxonomy(tid); } +Drupal.projectMoveElement = function(tid) { + // move all elements with a class linked to this tid into the + // project taxonomy fieldset (similar to module sub-terms) + $('.related-tid-' + tid).each(function() { + if ($(this).parent().siblings().size() == 1) { + $(this).parent().parent().remove(); + } + $('#edit-tid-' + tid + '-wrapper').append($(this).parent().remove()); + }); +} + Drupal.projectSetTaxonomy = function (tid) { $('div.project-taxonomy-element select').each(function () { - // If this is the selector for the currently selected - // term, show it (in case it was previously hidden). - if (this.id == 'edit-tid-' + tid) { + // If this is the selector for the currently selected term or a + // related element, show it (in case it was previously hidden). + if (this.id == 'edit-tid-' + tid || $(this).hasClass('related-tid-' + tid)) { // Hide not the select but its containing div (which also contains // the label). $(this).parents('div.form-item').show(); } - // Otherwise, empty it and hide it. + // Otherwise, hide it. else { - // In case terms were previously selected, unselect them. - // They are no longer valid. - this.selectedIndex = -1; $(this).parents('div.form-item').hide(); } }); Index: project.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project/project.module,v retrieving revision 1.356 diff -u -p -r1.356 project.module --- project.module 30 Jan 2010 02:43:23 -0000 1.356 +++ project.module 18 Apr 2010 20:19:08 -0000 @@ -333,6 +333,22 @@ function project_settings_form() { variable_set('project_enable_alias', FALSE); } + $vocabs = taxonomy_get_vocabularies('project_project'); + $tree = taxonomy_get_tree(_project_get_vid(), 0, -1, 1); + $top_level = array(''); + foreach ($tree as $i => $term) { + $top_level[$term->tid] = $term->name; + } + foreach ($vocabs as $vid => $vocab) { + $form['settings']['project_type_associated_tid_' . $vid] = array( + '#title' => t('Associated Project type taxonomy term'), + '#type' => 'select', + '#options' => $top_level, + '#default_value' => isset($form['vid']['#value']) ? variable_get('project_type_associated_tid_'. $form['vid']['#value'], NULL) : NULL, + '#description' => t('If this vocabulary is specific to a project type, set the term here to allow Project to automatically show and hide the form as necessary.'), + ); + } + return system_settings_form($form); } @@ -572,11 +588,23 @@ function project_form_alter(&$form, &$fo if (isset($form['taxonomy'][$vid])) { unset($form['taxonomy'][$vid]); } - // If there are no children elements, we should unset the entire - // thing so we don't end up with an empty fieldset. - if (!empty($form['taxonomy']) && (!element_children($form['taxonomy']))) { - unset($form['taxonomy']); + if (!empty($form['taxonomy'])) { + // If there are no children elements, we should unset the entire + // thing so we don't end up with an empty fieldset. + if (!element_children($form['taxonomy'])) { + unset($form['taxonomy']); + } + else { + foreach (array_keys($form['taxonomy']) as $vid) { + if (is_numeric($vid) && $tid = variable_get('project_type_associated_tid_'. $vid, NULL)) { + // If our vocabulary is related to a top-level project taxonomy term + // give it a related-tid value so we can shift it into the taxonomy fieldset + $form['taxonomy'][$vid]['#attributes']['class'] = 'related-tid-'. $tid; + } + } + } } + // In D6, FAPI changed in such a way that completely unsetting // $form['taxonomy'] causes warnings and errors when the project node is @@ -588,7 +616,9 @@ function project_form_alter(&$form, &$fo if (isset($form['buttons']['preview'])) { $form['buttons']['preview']['#submit'][] = 'project_project_form_preview_submit'; } - + + $form['#submit'][] = 'project_project_form_submit'; + // If the form has an element for specifying a URL alias, we want // to alter it, since we're just going to automatically override // the specified value. @@ -609,14 +639,13 @@ function project_form_alter(&$form, &$fo break; case 'taxonomy_form_vocabulary': + $project_type_vid = _project_get_vid(); // Add a validate handler to the vocabulary form if the // Project type vocabulary term is being edited so that its // possible to detect if this vocabulary was set to be // a free tagging vocabulary, and if so then throw an error. - $project_type_vid = _project_get_vid(); if (isset($project_type_vid) && !empty($form['vid']['#value']) && $form['vid']['#value'] == $project_type_vid) { $form['#validate'][] = 'project_project_type_vocabulary_validate'; - } break; } @@ -1133,6 +1162,20 @@ function project_project_form_preview_su } /** + * Remove terms from non-related vocabularies based on the current project type. + */ +function project_project_form_submit($form, &$form_state) { + if (isset($form_state['values']['taxonomy']) && isset($form_state['values']['project_type'])) { + foreach ($form_state['values']['taxonomy'] as $vid => $terms) { + $associated = variable_get('project_type_associated_tid_' . $vid, FALSE); + if ($associated && $associated != $form_state['values']['project_type']) { + unset ($form_state['values']['taxonomy'][$vid]); + } + } + } +} + +/** * Present a validation error if the user tries to make the * Project types vocabulary a free tagging vocabulary. */