You are here

function taxonomy_manager_tree_process_elements in Taxonomy Manager 7

Same name and namespace in other branches
  1. 5 taxonomy_manager.module \taxonomy_manager_tree_process_elements()
  2. 6.2 taxonomy_manager.module \taxonomy_manager_tree_process_elements()
  3. 6 taxonomy_manager.module \taxonomy_manager_tree_process_elements()

Processes the tree form element

Parameters

$element:

Return value

the tree element

1 string reference to 'taxonomy_manager_tree_process_elements'
taxonomy_manager_element_info in ./taxonomy_manager.module
Implements hook_elements().

File

./taxonomy_manager.module, line 271
Taxonomy Manager

Code

function taxonomy_manager_tree_process_elements($element) {
  global $_taxonomy_manager_existing_ids;

  //TEMP: seems like this functions gets called twice in preview and cause problem because of adding the settings to js twice
  $_taxonomy_manager_existing_ids = is_array($_taxonomy_manager_existing_ids) ? $_taxonomy_manager_existing_ids : array();
  $module_path = drupal_get_path('module', 'taxonomy_manager') . '/';
  $id = drupal_clean_css_identifier(implode('-', $element['#parents']));
  $element['#id'] = $id;
  $vid = $element['#vid'];
  if (!$element['#siblings_page'] && !in_array($id, $_taxonomy_manager_existing_ids)) {
    $_taxonomy_manager_existing_ids[$id] = $id;
    drupal_add_css($module_path . 'css/taxonomy_manager.css');
    drupal_add_js($module_path . 'js/tree.js');
    drupal_add_js(array(
      'siblingsForm' => array(
        'url' => url('admin/structure/taxonomy_manager/siblingsform'),
        'modulePath' => $module_path,
      ),
    ), 'setting');
    drupal_add_js(array(
      'childForm' => array(
        'url' => url('admin/structure/taxonomy_manager/childform'),
        'modulePath' => $module_path,
      ),
    ), 'setting');
    drupal_add_js(array(
      'taxonomytree' => array(
        array(
          'id' => $id,
          'vid' => $vid,
          'parents' => $element['#parents'],
        ),
      ),
    ), 'setting');
  }
  if (empty($element['#operations'])) {
    $opertions_callback = 'taxonomy_manager_' . implode('_', $element['#parents']) . '_operations';
    if (function_exists($opertions_callback)) {
      $element['#operations_callback'] = $opertions_callback;
    }
  }
  if (!isset($element['#link'])) {
    $link_callback = 'taxonomy_manager_' . implode('_', $element['#parents']) . '_link';
    if (function_exists($link_callback)) {
      $element['#link_callback'] = $link_callback;
    }
  }
  $element['#elements'] = array();
  $tree = _taxonomy_manager_tree_get_item($element['#vid'], $element['#parent'], $element['#pager'], $element['#siblings_page'], $element['#search_string'], $element['#language']);
  if (count($tree)) {
    if ($element['#pager'] && !($element['#parent'] || $element['#siblings_page'])) {
      $element['pager'] = array(
        '#value' => theme('pager'),
      );
    }
    $terms_to_expand = array();
    if (isset($element['#terms_to_expand'])) {

      // allow multiple terms to be expanded
      $requested_terms_to_expand = is_array($element['#terms_to_expand']) ? $element['#terms_to_expand'] : array(
        $element['#terms_to_expand'],
      );
      foreach ($requested_terms_to_expand as $term_to_expand) {

        // Multiple term version
        _taxonomy_manager_tree_get_first_path($term_to_expand, $tree, $terms_to_expand);
      }
      $terms_to_expand = taxonomy_manager_tree_get_terms_to_expand($tree, $requested_terms_to_expand, TRUE);
    }
    if (count($element['#default_value']) && !$element['#expand_all']) {
      $terms_to_expand = taxonomy_manager_tree_get_terms_to_expand($tree, $element['#default_value'], $element['#multiple']);
    }
    if (!empty($element['#language'])) {
      $element['#elements']['language'] = array(
        '#type' => 'hidden',
        '#value' => $element['#language'],
        '#attributes' => array(
          'class' => 'tree-lang',
        ),
      );
      _taxonomy_manager_tree_element_set_params($element['#parents'], $element['#elements']);
    }
    if (!is_array($element['#terms_to_highlight'])) {
      $element['#terms_to_highlight'] = array(
        $element['#terms_to_highlight'],
      );
    }
    $index = 0;
    taxonomy_manager_tree_build_form($index, $tree, $element['#elements'], $element, $element['#parents'], $element['#siblings_page'], $element['#default_value'], $element['#multiple'], $terms_to_expand, $element['#terms_to_highlight']);
  }
  return $element;
}