public Overview::buildForm(array $form, FormStateInterface $form_state)
Form constructor.
Display a tree of all the terms in a vocabulary, with options to edit each one. The form is made drag and drop by the theme function.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
\Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary: The vocabulary to display the overview form for.
Return value
array The form structure.
Overrides OverviewTerms::buildForm
File
- core/modules/forum/src/Form/Overview.php, line 48
Class
- Overview
- Provides forum overview form for the forum vocabulary.
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 | public function buildForm( array $form , FormStateInterface $form_state ) { $forum_config = $this ->config( 'forum.settings' ); $vid = $forum_config ->get( 'vocabulary' ); $vocabulary = $this ->entityManager->getStorage( 'taxonomy_vocabulary' )->load( $vid ); if (! $vocabulary ) { throw new NotFoundHttpException(); } // Build base taxonomy term overview. $form = parent::buildForm( $form , $form_state , $vocabulary ); foreach (Element::children( $form [ 'terms' ]) as $key ) { if (isset( $form [ 'terms' ][ $key ][ '#term' ])) { $term = $form [ 'terms' ][ $key ][ '#term' ]; $form [ 'terms' ][ $key ][ 'term' ][ '#url' ] = Url::fromRoute( 'forum.page' , [ 'taxonomy_term' => $term ->id()]); unset( $form [ 'terms' ][ $key ][ 'operations' ][ '#links' ][ 'delete' ]); $route_parameters = $form [ 'terms' ][ $key ][ 'operations' ][ '#links' ][ 'edit' ][ 'url' ]->getRouteParameters(); if (! empty ( $term ->forum_container->value)) { $form [ 'terms' ][ $key ][ 'operations' ][ '#links' ][ 'edit' ][ 'title' ] = $this ->t( 'edit container' ); $form [ 'terms' ][ $key ][ 'operations' ][ '#links' ][ 'edit' ][ 'url' ] = Url::fromRoute( 'entity.taxonomy_term.forum_edit_container_form' , $route_parameters ); } else { $form [ 'terms' ][ $key ][ 'operations' ][ '#links' ][ 'edit' ][ 'title' ] = $this ->t( 'edit forum' ); $form [ 'terms' ][ $key ][ 'operations' ][ '#links' ][ 'edit' ][ 'url' ] = Url::fromRoute( 'entity.taxonomy_term.forum_edit_form' , $route_parameters ); } // We don't want the redirect from the link so we can redirect the // delete action. unset( $form [ 'terms' ][ $key ][ 'operations' ][ '#links' ][ 'edit' ][ 'query' ][ 'destination' ]); } } // Remove the alphabetical reset. unset( $form [ 'actions' ][ 'reset_alphabetical' ]); // Use the existing taxonomy overview submit handler. $form [ 'terms' ][ '#empty' ] = $this ->t( 'No containers or forums available. <a href=":container">Add container</a> or <a href=":forum">Add forum</a>.' , array ( ':container' => $this ->url( 'forum.add_container' ), ':forum' => $this ->url( 'forum.add_forum' ) )); return $form ; } |
Please login to continue.