public ModerationStateTransitionListBuilder::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 DraggableListBuilder::buildForm
File
- core/modules/content_moderation/src/ModerationStateTransitionListBuilder.php, line 109
Class
- ModerationStateTransitionListBuilder
- Provides a listing of Moderation state transition entities.
Namespace
Drupal\content_moderation
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 | public function buildForm( array $form , FormStateInterface $form_state ) { $this ->entities = $this ->load(); // Get all the moderation states and sort them by weight. $states = $this ->stateStorage->loadMultiple(); uasort( $states , array ( $this ->entityType->getClass(), 'sort' )); /** @var \Drupal\content_moderation\ModerationStateTransitionInterface $entity */ $groups = array_fill_keys( array_keys ( $states ), []); foreach ( $this ->entities as $entity ) { $groups [ $entity ->getFromState()][] = $entity ; } foreach ( $groups as $group_name => $entities ) { $form [ $group_name ] = [ '#type' => 'details' , '#title' => $this ->t( 'From @state to...' , [ '@state' => $states [ $group_name ]->label()]), // Make sure that the first group is always open. '#open' => $group_name === array_keys ( $groups ) [0], ]; $form [ $group_name ][ $this ->entitiesKey] = array ( '#type' => 'table' , '#header' => $this ->buildHeader(), '#empty' => t( 'There is no @label yet.' , array ( '@label' => $this ->entityType->getLabel())), '#tabledrag' => array ( array ( 'action' => 'order' , 'relationship' => 'sibling' , 'group' => 'weight' , ), ), ); $delta = 10; // Change the delta of the weight field if have more than 20 entities. if (! empty ( $this ->weightKey)) { $count = count ( $this ->entities); if ( $count > 20) { $delta = ceil ( $count / 2); } } foreach ( $entities as $entity ) { $row = $this ->buildRow( $entity ); if (isset( $row [ 'label' ])) { $row [ 'label' ] = array ( '#markup' => $row [ 'label' ]); } if (isset( $row [ 'weight' ])) { $row [ 'weight' ][ '#delta' ] = $delta ; } $form [ $group_name ][ $this ->entitiesKey][ $entity ->id()] = $row ; } } $form [ 'actions' ][ '#type' ] = 'actions' ; $form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t( 'Save order' ), '#button_type' => 'primary' , ); return $form ; } |
Please login to continue.