You are here

function _image_gallery_parent_select in Image 5

Same name and namespace in other branches
  1. 5.2 contrib/image_gallery/image_gallery.module \_image_gallery_parent_select()
  2. 6 contrib/image_gallery/image_gallery.admin.inc \_image_gallery_parent_select()
  3. 7 contrib/image_gallery/image_gallery.admin.inc \_image_gallery_parent_select()
1 call to _image_gallery_parent_select()
image_gallery_admin_form in contrib/image_gallery/image_gallery.module

File

contrib/image_gallery/image_gallery.module, line 289

Code

function _image_gallery_parent_select($tid, $title) {
  $parents = taxonomy_get_parents($tid);
  if ($parents) {
    $parent = array_shift($parents);
    $parent = $parent->tid;
  }
  else {
    $parent = 0;
  }
  $children = taxonomy_get_tree(_image_gallery_get_vid(), $tid);

  // A term can't be the child of itself, nor of its children.
  foreach ($children as $child) {
    $exclude[] = $child->tid;
  }
  $exclude[] = $tid;
  $tree = taxonomy_get_tree(_image_gallery_get_vid());
  $options[0] = '<' . t('root') . '>';
  if ($tree) {
    foreach ($tree as $term) {
      if (!in_array($term->tid, $exclude)) {
        $options[$term->tid] = str_repeat(' -- ', $term->depth) . ' ' . $term->name;
      }
    }
  }
  return array(
    '#type' => 'select',
    '#title' => $title,
    '#default_value' => $parent,
    '#options' => $options,
    '#description' => t('Image galleries may be nested below other galleries.'),
    '#required' => TRUE,
  );
}