Prepopulate does not work when Hierarchical Select is enabled for taxonomy.

http://drupal.org/project/hierarchical_select

Is there any way to get it working in tandem with Hierarchical Select? If not, are there any plans to add support for Hierarchical Select?

Comments

mark.’s picture

subscribed.

jbrauer’s picture

Status: Active » Postponed (maintainer needs more info)

I don't see a way offhand to make these work well together. I'm leaving this open, however in case someone else has ideas/patches.

seemas’s picture

>>> SOLVED
http://drupal.org/node/637998#comment-2298950 prepopulate version worked for me with latest hierarchical select 6.x-3.6 on http://drupal.org/project/hierarchical_select
url that i used:
http://yourdomain.com/node/add/page?edit[taxonomy][7][hierarchical_selec...
This selects 2nd level term (tid:38->tid:42)

jbrauer’s picture

Status: Postponed (maintainer needs more info) » Fixed

Great! Thanks for the update.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ordually’s picture

Status: Closed (fixed) » Active

I'm unable to duplicate the results of #3. I'm using the current dev version of Prepopulate-6.x-2.x-dev (2011-Feb-25) and the current release of Hierarchical Select (6.x-3.7). From what I can see inspecting the DOM, for hierarchical select (HS), the DOM is not populated with the child taxonomy elements until the user has chosen a parent element and performed a form_submit. For instance, on initial load a node-add page may have a HS vocab addressable with prepopulate syntax of:

edit[taxonomy][3][hierarchical_select][selects][0]=<parent-tid>

In the above, if I substitute
with an actual, top level vocab term ID, Prepopulate will select it. Moving a level deeper, though, is the goal using Hierarchical Select. My vocabulary has child terms, but only after I perform a manual submit of the above do I then get a DOM that this prepopulate syntax would find:

edit[taxonomy][3][hierarchical_select][selects][1]=<child-tid>

Without that manual submit my DOM simply doesn't have the data for Prepulate to find, ie. there is nothing in the DOM for the child terms, just the parent terms.

Marking this 'active' since I don't see any way this is happening right now. If anyone has other suggestions please reply!

srsbl’s picture

Version: » 7.x-2.x-dev

Hi,

I'm using drupal 7 and I was able to prepopulate the parent of a term reference field (field_category) using:
node/add/contenttype?edit[field_category][und][hierarchical_select][selects][0]=<parent-tid>

I couldn't, however, find a solution for selecting the parent and the child terms. I've tried

node/add/contenttype?edit[field_category][und][hierarchical_select][selects][1]=<child-tid>

and

node/add/contenttype?edit[field_category][und][hierarchical_select][selects][0]=<parent-tid>&edit[field_category][und][hierarchical_select][selects][1]=<child-tid>

but none worked.

Is there any other suggestions?

Thanks,

treehacker’s picture

I had the same problem on drupal 6 and finally I did a workarround by changing the taxonomy field on node save.
since I don't need the taxonomy list to show up on node creation it works for me.

Here my little module function:

function MYMODULE_nodeapi(&$node, $op, $teaser, $page) {
  
  if($node->type == 'issue') {
   switch ($op) {
       case 'insert':
         
          if(isset($_REQUEST['regionid']) && is_numeric($_REQUEST['regionid'])) {
            $regionid = $_REQUEST['regionid'];
          }
          
          if($regionid){
            $newterm = taxonomy_get_parents_all($regionid);
            $node->taxonomy = $newterm;
            node_save($node);
          }
      }
    }
} 

On the page where I have the node creation link I just append the taxonomy ID to the URL via node/add ?regionid=1234

Hope this helps a bit, even if it may not be very correct.... :-)

maximpodorov’s picture

A simple solution which replaces hierarchical select widget by simple select widget and disables it:

/**
 * Implements hook_field_widget_properties_ENTITY_TYPE_alter().
 */
function MYMODULE_field_widget_properties_node_alter(&$widget, $context) {
  if (in_array($context['field']['field_name'], _MYMODULE_field_list())) {
    if ($widget['type'] == 'taxonomy_hs') {
      $widget['module'] = 'options';
      $widget['type'] = 'options_select';
    }
  }
}

/**
 * Implements hook_field_widget_form_alter().
 */
function MYMODULE_field_widget_form_alter(&$element, &$form_state, $context) {
  if (in_array($context['field']['field_name'], _MYMODULE_field_list())) {
    if ($element['#type'] == 'select') {
      $element['#disabled'] = TRUE;
    }
  }
}

/**
 * Returns list of prepopulated fields.
 */
function _MYMODULE_field_list() {
  $prepopulate_fields = &drupal_static(__FUNCTION__);
  if (!isset($prepopulate_fields)) {
    $prepopulate_fields = array();
    if ((isset($_GET['edit'])) && is_array($_GET['edit'])) {
      $prepopulate_fields = array_keys($_GET['edit']);
    }
  }
  return $prepopulate_fields;
}
gmario’s picture

Hi to all,

sorry for my english - maybe will not so clear :)

I too have been faced with this problem, and I've wrote a little patch. I have a node with a "hierarchical_select" that must being pre populate in some circumstances. I have only changed this function like that:

function prepopulate_form_alter(&$form, $form_state, $form_id) {
  // Provide for accepting base64 encoded fields.
  if (isset($_REQUEST['pp'])) {
    parse_str(base64_decode($_REQUEST['pp']), $_REQUEST);
  }
  if (isset($_REQUEST['edit'])) {
    $request = (array)$_REQUEST['edit'];
    foreach (array_keys($request) as $fe){
      if (isset($form[$fe])) {
        watchdog('prepopulate', 'il field @field esiste', array('@field' => $fe), WATCHDOG_NOTICE);
        foreach ($request[$fe] as $fe_lang => $fe_value){
          if(isset($form[$fe][$fe_lang]['#type']) && ($form[$fe][$fe_lang]['#type'] == 'hierarchical_select')){
            $form[$fe][$fe_lang]['#default_value'] = $request[$fe][$fe_lang]['default_value'];
            watchdog('prepopulate', "il field @field e' di tipo hierarchical_select -> imposto il default value", array('@field' => $fe), WATCHDOG_NOTICE);
          }
        }
      }
    }
    $form['#after_build'][] = 'prepopulate_after_build';
  }
}

to set a field named field_apply_to use this sintax:

edit[field_apply_to][und][default_value][0]=VALUE

hope this helps someone.

a presto
gmario

gangaloo’s picture

Issue summary: View changes

I'm interested in this feature.
Just wondering if there might be a consideration for this feature request?

lincolnbergeson’s picture

I too couldn't replicate #3, even after following instructions here: https://www.drupal.org/node/228167

Any comments from the developers?