public EntityDisplayFormBase::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/field_ui/src/Form/EntityDisplayFormBase.php, line 136
Class
- EntityDisplayFormBase
- Base class for EntityDisplay edit forms.
Namespace
Drupal\field_ui\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 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 115 | public function form( array $form , FormStateInterface $form_state ) { $form = parent::form( $form , $form_state ); $field_definitions = $this ->getFieldDefinitions(); $extra_fields = $this ->getExtraFields(); $form += array ( '#entity_type' => $this ->entity->getTargetEntityTypeId(), '#bundle' => $this ->entity->getTargetBundle(), '#fields' => array_keys ( $field_definitions ), '#extra' => array_keys ( $extra_fields ), ); if ( empty ( $field_definitions ) && empty ( $extra_fields ) && $route_info = FieldUI::getOverviewRouteInfo( $this ->entity->getTargetEntityTypeId(), $this ->entity->getTargetBundle())) { drupal_set_message( $this ->t( 'There are no fields yet added. You can add new fields on the <a href=":link">Manage fields</a> page.' , array ( ':link' => $route_info ->toString())), 'warning' ); return $form ; } $table = array ( '#type' => 'field_ui_table' , '#header' => $this ->getTableHeader(), '#regions' => $this ->getRegions(), '#attributes' => array ( 'class' => array ( 'field-ui-overview' ), 'id' => 'field-display-overview' , ), '#tabledrag' => array ( array ( 'action' => 'order' , 'relationship' => 'sibling' , 'group' => 'field-weight' , ), array ( 'action' => 'match' , 'relationship' => 'parent' , 'group' => 'field-parent' , 'subgroup' => 'field-parent' , 'source' => 'field-name' , ), ), ); // Field rows. foreach ( $field_definitions as $field_name => $field_definition ) { $table [ $field_name ] = $this ->buildFieldRow( $field_definition , $form , $form_state ); } // Non-field elements. foreach ( $extra_fields as $field_id => $extra_field ) { $table [ $field_id ] = $this ->buildExtraFieldRow( $field_id , $extra_field ); } $form [ 'fields' ] = $table ; // Custom display settings. if ( $this ->entity->getMode() == 'default' ) { // Only show the settings if there is at least one custom display mode. $display_mode_options = $this ->getDisplayModeOptions(); // Unset default option. unset( $display_mode_options [ 'default' ]); if ( $display_mode_options ) { $form [ 'modes' ] = array ( '#type' => 'details' , '#title' => $this ->t( 'Custom display settings' ), ); // Prepare default values for the 'Custom display settings' checkboxes. $default = array (); if ( $enabled_displays = array_filter ( $this ->getDisplayStatuses())) { $default = array_keys ( array_intersect_key ( $display_mode_options , $enabled_displays )); } $form [ 'modes' ][ 'display_modes_custom' ] = array ( '#type' => 'checkboxes' , '#title' => $this ->t( 'Use custom display settings for the following @display_context modes' , [ '@display_context' => $this ->displayContext]), '#options' => $display_mode_options , '#default_value' => $default , ); // Provide link to manage display modes. $form [ 'modes' ][ 'display_modes_link' ] = $this ->getDisplayModesLink(); } } // In overviews involving nested rows from contributed modules (i.e // field_group), the 'plugin type' selects can trigger a series of changes // in child rows. The #ajax behavior is therefore not attached directly to // the selects, but triggered by the client-side script through a hidden // #ajax 'Refresh' button. A hidden 'refresh_rows' input tracks the name of // affected rows. $form [ 'refresh_rows' ] = array ( '#type' => 'hidden' ); $form [ 'refresh' ] = array ( '#type' => 'submit' , '#value' => $this ->t( 'Refresh' ), '#op' => 'refresh_table' , '#submit' => array ( '::multistepSubmit' ), '#ajax' => array ( 'callback' => '::multistepAjax' , 'wrapper' => 'field-display-overview-wrapper' , 'effect' => 'fade' , // The button stays hidden, so we hide the Ajax spinner too. Ad-hoc // spinners will be added manually by the client-side script. 'progress' => 'none' , ), '#attributes' => array ( 'class' => array ( 'visually-hidden' )) ); $form [ 'actions' ] = array ( '#type' => 'actions' ); $form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#button_type' => 'primary' , '#value' => $this ->t( 'Save' ), ); $form [ '#attached' ][ 'library' ][] = 'field_ui/drupal.field_ui' ; return $form ; } |
Please login to continue.