public ReorderDisplays::buildForm(array $form, FormStateInterface $form_state)
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- core/modules/views_ui/src/Form/Ajax/ReorderDisplays.php, line 31
Class
- ReorderDisplays
- Displays the display reorder form.
Namespace
Drupal\views_ui\Form\Ajax
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | public function buildForm( array $form , FormStateInterface $form_state ) { /** @var $view \Drupal\views\ViewEntityInterface */ $view = $form_state ->get( 'view' ); $display_id = $form_state ->get( 'display_id' ); $form [ '#title' ] = $this ->t( 'Reorder displays' ); $form [ '#section' ] = 'reorder' ; $form [ '#action' ] = $this ->url( 'views_ui.form_reorder_displays' , [ 'js' => 'nojs' , 'view' => $view ->id(), 'display_id' => $display_id , ]); $form [ 'view' ] = array ( '#type' => 'value' , '#value' => $view ); $displays = $view ->get( 'display' ); $count = count ( $displays ); // Sort the displays. uasort( $displays , function ( $display1 , $display2 ) { if ( $display1 [ 'position' ] != $display2 [ 'position' ]) { return $display1 [ 'position' ] < $display2 [ 'position' ] ? -1 : 1; } return 0; }); $form [ 'displays' ] = array ( '#type' => 'table' , '#id' => 'reorder-displays' , '#header' => array ( $this ->t( 'Display' ), $this ->t( 'Weight' ), $this ->t( 'Remove' )), '#empty' => $this ->t( 'No displays available.' ), '#tabledrag' => array ( array ( 'action' => 'order' , 'relationship' => 'sibling' , 'group' => 'weight' , ) ), '#tree' => TRUE, '#prefix' => '<div class="scroll" data-drupal-views-scroll>' , '#suffix' => '</div>' , ); foreach ( $displays as $id => $display ) { $form [ 'displays' ][ $id ] = array ( '#display' => $display , '#attributes' => array ( 'id' => 'display-row-' . $id , ), '#weight' => $display [ 'position' ], ); // Only make row draggable if it's not the default display. if ( $id !== 'default' ) { $form [ 'displays' ][ $id ][ '#attributes' ][ 'class' ][] = 'draggable' ; } $form [ 'displays' ][ $id ][ 'title' ] = array ( '#markup' => $display [ 'display_title' ], ); $form [ 'displays' ][ $id ][ 'weight' ] = array ( '#type' => 'weight' , '#value' => $display [ 'position' ], '#delta' => $count , '#title' => $this ->t( 'Weight for @display' , array ( '@display' => $display [ 'display_title' ])), '#title_display' => 'invisible' , '#attributes' => array ( 'class' => array ( 'weight' ), ), ); $form [ 'displays' ][ $id ][ 'removed' ] = array ( 'checkbox' => array ( '#title' => t( 'Remove @id' , array ( '@id' => $id )), '#title_display' => 'invisible' , '#type' => 'checkbox' , '#id' => 'display-removed-' . $id , '#attributes' => array ( 'class' => array ( 'views-remove-checkbox' ), ), '#default_value' => ! empty ( $display [ 'deleted' ]), ), 'link' => array ( '#type' => 'link' , '#title' => SafeMarkup::format( '<span>@text</span>' , array ( '@text' => $this ->t( 'Remove' ))), '#url' => Url::fromRoute( '<none>' ), '#attributes' => array ( 'id' => 'display-remove-link-' . $id , 'class' => array ( 'views-button-remove' , 'display-remove-link' ), 'alt' => $this ->t( 'Remove this display' ), 'title' => $this ->t( 'Remove this display' ), ), ), '#access' => ( $id !== 'default' ), ); if (! empty ( $display [ 'deleted' ])) { $form [ 'displays' ][ $id ][ 'deleted' ] = array ( '#type' => 'value' , '#value' => TRUE, ); $form [ 'displays' ][ $id ][ '#attributes' ][ 'class' ][] = 'hidden' ; } } $view ->getStandardButtons( $form , $form_state , 'views_ui_reorder_displays_form' ); return $form ; } |
Please login to continue.