public SetCustomize::form(array $form, FormStateInterface $form_state)
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- core/modules/shortcut/src/Form/SetCustomize.php, line 24
Class
- SetCustomize
- Builds the shortcut set customize form.
Namespace
Drupal\shortcut\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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | public function form( array $form , FormStateInterface $form_state ) { $form = parent::form( $form , $form_state ); $form [ 'shortcuts' ] = array ( '#tree' => TRUE, '#weight' => -20, ); $form [ 'shortcuts' ][ 'links' ] = array ( '#type' => 'table' , '#header' => array (t( 'Name' ), t( 'Weight' ), t( 'Operations' )), '#empty' => $this ->t( 'No shortcuts available. <a href=":link">Add a shortcut</a>' , array ( ':link' => $this ->url( 'shortcut.link_add' , array ( 'shortcut_set' => $this ->entity->id())))), '#attributes' => array ( 'id' => 'shortcuts' ), '#tabledrag' => array ( array ( 'action' => 'order' , 'relationship' => 'sibling' , 'group' => 'shortcut-weight' , ), ), ); foreach ( $this ->entity->getShortcuts() as $shortcut ) { $id = $shortcut ->id(); $url = $shortcut ->getUrl(); if (! $url ->access()) { continue ; } $form [ 'shortcuts' ][ 'links' ][ $id ][ '#attributes' ][ 'class' ][] = 'draggable' ; $form [ 'shortcuts' ][ 'links' ][ $id ][ 'name' ] = array ( '#type' => 'link' , '#title' => $shortcut ->getTitle(), ) + $url ->toRenderArray(); unset( $form [ 'shortcuts' ][ 'links' ][ $id ][ 'name' ][ '#access_callback' ]); $form [ 'shortcuts' ][ 'links' ][ $id ][ '#weight' ] = $shortcut ->getWeight(); $form [ 'shortcuts' ][ 'links' ][ $id ][ 'weight' ] = array ( '#type' => 'weight' , '#title' => t( 'Weight for @title' , array ( '@title' => $shortcut ->getTitle())), '#title_display' => 'invisible' , '#default_value' => $shortcut ->getWeight(), '#attributes' => array ( 'class' => array ( 'shortcut-weight' )), ); $links [ 'edit' ] = array ( 'title' => t( 'Edit' ), 'url' => $shortcut ->urlInfo(), ); $links [ 'delete' ] = array ( 'title' => t( 'Delete' ), 'url' => $shortcut ->urlInfo( 'delete-form' ), ); $form [ 'shortcuts' ][ 'links' ][ $id ][ 'operations' ] = array ( '#type' => 'operations' , '#links' => $links , '#access' => $url ->access(), ); } return $form ; } |
Please login to continue.