function _hierarchical_select_process_render_flat_select in Hierarchical Select 5.3
Same name and namespace in other branches
- 6.3 hierarchical_select.module \_hierarchical_select_process_render_flat_select()
Render a flat select version of a hierarchical_select form element. This is necessary for backwards compatibility (together with some Javascript code) in case of GET forms.
Parameters
$hierarchy: A hierarchy object.
$dropbox: A dropbox object.
$config: A config array with at least the following settings:
- module
- params
- dropbox
- status
 
Return value
A structured array for use in the Forms API.
1 call to _hierarchical_select_process_render_flat_select()
- hierarchical_select_process in ./hierarchical_select.module 
- Hierarchical select form element type #process callback.
File
- ./hierarchical_select.module, line 1111 
- This module defines the "hierarchical_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.
Code
function _hierarchical_select_process_render_flat_select($hierarchy, $dropbox, $config) {
  $selection = array();
  if ($config['dropbox']['status']) {
    foreach ($dropbox->lineages_selections as $lineage_selection) {
      $selection = array_merge($selection, $lineage_selection);
    }
  }
  else {
    $selection = $hierarchy->lineage;
  }
  $options = array();
  foreach ($selection as $value) {
    $is_valid = module_invoke($config['module'], 'hierarchical_select_valid_item', $value, $config['params']);
    if ($is_valid) {
      $options[$value] = $value;
    }
  }
  $element = array(
    '#type' => 'select',
    '#multiple' => $config['save_lineage'] || $config['dropbox']['status'],
    '#options' => $options,
    '#default_value' => array_keys($options),
    // Use a #theme callback to prevent the select from being wrapped in a
    // div. This simplifies the CSS and JS code.
    '#theme' => 'hierarchical_select_select',
    '#attributes' => array(
      'class' => 'flat-select',
    ),
  );
  return $element;
}