array( 'function' => 'aw_phototheque_hierarchical_select_select', 'arguments' => array('element' => NULL), ), ); } /** * Override of theme_hierarchical_select_select($element) * This is called 100% of time when aw_phototheque module weight is > hierarchical_select module weight. */ function aw_phototheque_hierarchical_select_select($element) { //dd($element,'$element IS'); // Guess current form context... Do not apply any theme overriding for other vocabularies than AW_PHOTOTHEQUE vocabulary $phototheque_edit_context = FALSE; // ... are we in AW_PHOTOTHEQUE vocabulary term edit form ? $matches = array(); if (preg_match('/^.*taxonomy\/edit\/term\/([0-9]+)/', $_GET['q'], $matches)) { $family = $matches[1]; $vocabulary = (int) db_result(db_query('SELECT vid FROM {term_data} WHERE tid = %d',$family)); dd($vocabulary,'$VOCABULARY HERE'); if($vocabulary == AW_PHOTOTHEQUE_VID) { $phototheque_edit_context = 'term'; } } // ... are we in AW_PHOTOTHEQUE node edit form ? elseif (strstr($element['#name'],'taxonomy['.AW_PHOTOTHEQUE_VID.']') !== FALSE) { $phototheque_edit_context = 'node'; } dd($phototheque_edit_context,'$phototheque_edit_context'); // If not in some AW_PHOTOTHEQUE edit form context, hand HTML select rendering back to native hierarchical_select theme if(empty($phototheque_edit_context)) { dd('empty context, handing to native theme function'); return theme_hierarchical_select_select($element); } // Hacked HTML select rendering $select = ''; $size = $element['#size'] ? ' size="'. $element['#size'] .'"' : ''; $class = array('form-select'); if (form_get_error($element) === '') { $class = array_merge($class, array('error')); } _form_set_class($element, $class); $multiple = isset($element['#multiple']) && $element['#multiple']; // Never display 3rd-level select boxes (node edit + term edit contexts) if(($phototheque_edit_context == 'node' && strstr($element['#name'], '[selects][2]') !== FALSE) || // Never display 2nd-level select boxes (term edit contexts), this limits vocabulary to max 2 levels ($phototheque_edit_context == 'term' && (strstr($element['#name'], '[selects][1]') !== FALSE || strstr($element['#name'], '[selects][2]') !== FALSE ))) { dd('empty select for #name='.$element['#name']); $select = ''; } else { $select = ''; } return $select; } /** * Override of _hierarchical_select_options($element) */ function _aw_phototheque_hierarchical_select_options($element) { if (!isset($choices)) { $choices = $element['#options']; } // array_key_exists() accommodates the rare event where $element['#value'] is NULL. // isset() fails in this situation. $value_valid = isset($element['#value']) || array_key_exists('#value', $element); $value_is_array = is_array($element['#value']); $options = ''; foreach ($choices as $key => $choice) { $key = (string)$key; if ($value_valid && (!$value_is_array && (string)$element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) { $selected = ' selected="selected"'; } else { $selected = ''; } // If an option DOES NOT have child info, then it's a special option: // - label_\d+ (level label) // - none ("") // - create_new_item ("") // Only when it's a level label, we have to add a class to this option. if (!isset($element['#childinfo'][$key])) { $class = (preg_match('/label_\d+/', $key)) ? ' level-label' : ''; } else { $class = ($element['#childinfo'][$key] == 0) ? 'has-no-children' : 'has-children'; } $options .= ''; } return $options; } //===== File: aw_phototheque.install ==== define('MODULE_NAME', 'AW Phototheque'); function aw_phototheque_install() { _aw_phototheque_setup_module_weight(); } function aw_phototheque_update_6106() { aw_phototheque_install(); } function _aw_phototheque_setup_module_weight() { //Always run after hierarchical_select in order $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'hierarchical_select'")); $weight = max($weight, 20); // Set the weight one higher than the highest weight we've encountered, so that this module runs after it. $weight++; db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight, 'aw_phototheque'); drupal_set_message(t(MODULE_NAME.' Increased module weight so it runs always after hierarchical_select.'), 'status'); }