protected EntityDisplayFormBase::buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state)
Builds the table row structure for a single field.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.
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 A table row array.
File
- core/modules/field_ui/src/Form/EntityDisplayFormBase.php, line 265
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | protected function buildFieldRow(FieldDefinitionInterface $field_definition , array $form , FormStateInterface $form_state ) { $field_name = $field_definition ->getName(); $display_options = $this ->entity->getComponent( $field_name ); $label = $field_definition ->getLabel(); // Disable fields without any applicable plugins. if ( empty ( $this ->getApplicablePluginOptions( $field_definition ))) { $this ->entity->removeComponent( $field_name )->save(); $display_options = $this ->entity->getComponent( $field_name ); } $regions = array_keys ( $this ->getRegions()); $field_row = array ( '#attributes' => array ( 'class' => array ( 'draggable' , 'tabledrag-leaf' )), '#row_type' => 'field' , '#region_callback' => array ( $this , 'getRowRegion' ), '#js_settings' => array ( 'rowHandler' => 'field' , 'defaultPlugin' => $this ->getDefaultPlugin( $field_definition -> getType ()), ), 'human_name' => array ( '#plain_text' => $label , ), 'weight' => array ( '#type' => 'textfield' , '#title' => $this ->t( 'Weight for @title' , array ( '@title' => $label )), '#title_display' => 'invisible' , '#default_value' => $display_options ? $display_options [ 'weight' ] : '0' , '#size' => 3, '#attributes' => array ( 'class' => array ( 'field-weight' )), ), 'parent_wrapper' => array ( 'parent' => array ( '#type' => 'select' , '#title' => $this ->t( 'Label display for @title' , array ( '@title' => $label )), '#title_display' => 'invisible' , '#options' => array_combine ( $regions , $regions ), '#empty_value' => '' , '#attributes' => array ( 'class' => array ( 'js-field-parent' , 'field-parent' )), '#parents' => array ( 'fields' , $field_name , 'parent' ), ), 'hidden_name' => array ( '#type' => 'hidden' , '#default_value' => $field_name , '#attributes' => array ( 'class' => array ( 'field-name' )), ), ), ); $field_row [ 'plugin' ] = array ( 'type' => array ( '#type' => 'select' , '#title' => $this ->t( 'Plugin for @title' , array ( '@title' => $label )), '#title_display' => 'invisible' , '#options' => $this ->getPluginOptions( $field_definition ), '#default_value' => $display_options ? $display_options [ 'type' ] : 'hidden' , '#parents' => array ( 'fields' , $field_name , 'type' ), '#attributes' => array ( 'class' => array ( 'field-plugin-type' )), ), 'settings_edit_form' => array (), ); // Get the corresponding plugin object. $plugin = $this ->entity->getRenderer( $field_name ); // Base button element for the various plugin settings actions. $base_button = array ( '#submit' => array ( '::multistepSubmit' ), '#ajax' => array ( 'callback' => '::multistepAjax' , 'wrapper' => 'field-display-overview-wrapper' , 'effect' => 'fade' , ), '#field_name' => $field_name , ); if ( $form_state ->get( 'plugin_settings_edit' ) == $field_name ) { // We are currently editing this field's plugin settings. Display the // settings form and submit buttons. $field_row [ 'plugin' ][ 'settings_edit_form' ] = array (); if ( $plugin ) { // Generate the settings form and allow other modules to alter it. $settings_form = $plugin ->settingsForm( $form , $form_state ); $third_party_settings_form = $this ->thirdPartySettingsForm( $plugin , $field_definition , $form , $form_state ); if ( $settings_form || $third_party_settings_form ) { $field_row [ 'plugin' ][ '#cell_attributes' ] = array ( 'colspan' => 3); $field_row [ 'plugin' ][ 'settings_edit_form' ] = array ( '#type' => 'container' , '#attributes' => array ( 'class' => array ( 'field-plugin-settings-edit-form' )), '#parents' => array ( 'fields' , $field_name , 'settings_edit_form' ), 'label' => array ( '#markup' => $this ->t( 'Plugin settings' ), ), 'settings' => $settings_form , 'third_party_settings' => $third_party_settings_form , 'actions' => array ( '#type' => 'actions' , 'save_settings' => $base_button + array ( '#type' => 'submit' , '#button_type' => 'primary' , '#name' => $field_name . '_plugin_settings_update' , '#value' => $this ->t( 'Update' ), '#op' => 'update' , ), 'cancel_settings' => $base_button + array ( '#type' => 'submit' , '#name' => $field_name . '_plugin_settings_cancel' , '#value' => $this ->t( 'Cancel' ), '#op' => 'cancel' , // Do not check errors for the 'Cancel' button, but make sure we // get the value of the 'plugin type' select. '#limit_validation_errors' => array ( array ( 'fields' , $field_name , 'type' )), ), ), ); $field_row [ '#attributes' ][ 'class' ][] = 'field-plugin-settings-editing' ; } } } else { $field_row [ 'settings_summary' ] = array (); $field_row [ 'settings_edit' ] = array (); if ( $plugin ) { // Display a summary of the current plugin settings, and (if the // summary is not empty) a button to edit them. $summary = $plugin ->settingsSummary(); // Allow other modules to alter the summary. $this ->alterSettingsSummary( $summary , $plugin , $field_definition ); if (! empty ( $summary )) { $field_row [ 'settings_summary' ] = array ( '#type' => 'inline_template' , '#template' => '<div class="field-plugin-summary">{{ summary|safe_join("<br />") }}</div>' , '#context' => array ( 'summary' => $summary ), '#cell_attributes' => array ( 'class' => array ( 'field-plugin-summary-cell' )), ); } // Check selected plugin settings to display edit link or not. $settings_form = $plugin ->settingsForm( $form , $form_state ); $third_party_settings_form = $this ->thirdPartySettingsForm( $plugin , $field_definition , $form , $form_state ); if (! empty ( $settings_form ) || ! empty ( $third_party_settings_form )) { $field_row [ 'settings_edit' ] = $base_button + array ( '#type' => 'image_button' , '#name' => $field_name . '_settings_edit' , '#src' => 'core/misc/icons/787878/cog.svg' , '#attributes' => array ( 'class' => array ( 'field-plugin-settings-edit' ), 'alt' => $this ->t( 'Edit' )), '#op' => 'edit' , // Do not check errors for the 'Edit' button, but make sure we get // the value of the 'plugin type' select. '#limit_validation_errors' => array ( array ( 'fields' , $field_name , 'type' )), '#prefix' => '<div class="field-plugin-settings-edit-wrapper">' , '#suffix' => '</div>' , ); } } } return $field_row ; } |
Please login to continue.