Skip to content
Snippets Groups Projects

Issue #3390701 by Shreya_th, jwilson3: getThirdPartySetting() returns null so form is not altered

Open Issue #3390701 by Shreya_th, jwilson3: getThirdPartySetting() returns null so form is not altered
2 unresolved threads
2 unresolved threads

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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)
  • Author Maintainer

    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
  • Please register or sign in to reply
  • 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 }
    • Comment on lines -287 to +305
      Author Maintainer

      I'm not entirely sure I'm okay with changing from a generic #entity_builder hook to a form submit. This needs a bit more investigation and explanation of what is going on with the #entity_builder.

    • Please register or sign in to reply
    Please register or sign in to reply
    Loading