protected ForumForm::forumParentSelect($tid, $title)
Returns a select box for available parent terms.
Parameters
int $tid: ID of the term that is being added or edited.
string $title: Title for the select box.
Return value
array A select form element.
File
- core/modules/forum/src/Form/ForumForm.php, line 126
Class
- ForumForm
- Base form for forum term edit forms.
Namespace
Drupal\forum\Form
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | protected function forumParentSelect( $tid , $title ) { $taxonomy_storage = $this ->entityManager->getStorage( 'taxonomy_term' ); $parents = $taxonomy_storage ->loadParents( $tid ); if ( $parents ) { $parent = array_shift ( $parents ); $parent = $parent ->id(); } else { $parent = 0; } $vid = $this ->config( 'forum.settings' )->get( 'vocabulary' ); $children = $taxonomy_storage ->loadTree( $vid , $tid , NULL, TRUE); // A term can't be the child of itself, nor of its children. foreach ( $children as $child ) { $exclude [] = $child ->tid; } $exclude [] = $tid ; $tree = $taxonomy_storage ->loadTree( $vid , 0, NULL, TRUE); $options [0] = '<' . $this ->t( 'root' ) . '>' ; if ( $tree ) { foreach ( $tree as $term ) { if (!in_array( $term ->id(), $exclude )) { $options [ $term ->id()] = str_repeat ( ' -- ' , $term ->depth) . $term ->getName(); } } } $description = $this ->t( 'Forums may be placed at the top (root) level, or inside another container or forum.' ); return array ( '#type' => 'select' , '#title' => $title , '#default_value' => $parent , '#options' => $options , '#description' => $description , '#required' => TRUE, ); } |
Please login to continue.