Issue #3390701 by Shreya_th, jwilson3: getThirdPartySetting() returns null so form is not altered
Open
requested to merge issue/label_help-3390701:3390701-getthirdpartysetting-returns-null into 2.0.x
2 unresolved threads
Reroll of patch in comment 3 https://www.drupal.org/files/issues/2023-10-03/label_help-3390701.patch
Closes #3390701
Merge request reports
Activity
304 } 305 } 306 307 /** 308 * Submit handler to save label_help_description. 309 */ 310 function label_help_form_field_config_edit_form_submit($form, FormStateInterface $form_state) { 311 // Check if the field config is being edited. 312 if (isset($form_state->getFormObject()->getEntity()->field_name)) { 313 $field_name = $form_state->getFormObject()->getEntity()->field_name; 314 315 // Get the label_help_description from the submitted form values. 316 $label_help_description = $form_state->getValue(['settings', 'label_help_description']); 317 318 // Set the label_help_description as a third-party setting for the field. 319 field_config('field.storage.node.' . $field_name) phpstan turned up the following error:
------ --------------------------------------------------------------------- Line label_help.module ------ --------------------------------------------------------------------- 319 Function field_config not found. ------ ---------------------------------------------------------------------
Additionally, the approach of hardcoding
field.storage.node.' . $field_name
into the module will not work at all. This must be refactored to permit any fieldable entity type.Edited by James Wilson
297 $form['#entity_builders'][] = 'label_help_form_field_config_edit_form_builder'; 291 function label_help_form_field_config_edit_form_alter(&$form, FormStateInterface &$form_state, $form_id) { 292 if (isset($form['#entity_type']) && $form['#entity_type'] == 'field_config') { 293 $fieldConfig = $form_state->getFormObject()->getEntity(); 294 295 // Add settings for file upload widgets. 296 $form['settings']['label_help_description'] = [ 297 '#type' => 'textarea', 298 '#rows' => 2, 299 '#title' => t('Label help message'), 300 '#default_value' => $fieldConfig->getThirdPartySetting('label_help', 'label_help_description', ''), 301 '#description' => t('Help text to insert below the label and above the input form element.'), 302 ]; 303 $form['actions']['submit']['#submit'][] = 'label_help_form_field_config_edit_form_submit'; 304 } 305 }
Please register or sign in to reply