Admin Tooltips breaks form ajax on Manage Form Display page

Created on 14 September 2022, over 2 years ago
Updated 19 August 2024, 8 months ago

Problem/Motivation

With Admin Tooltips, it's impossible to edit widget settings due to ajax errors. The reason behind this is that ::afterBuild() supposed to run the the whole form is also attached to admin_tooltips element, causing some PHP notices and warnings. And why it happens is because the admin_tooltips_field_widget_third_party_settings_form is not properly attaching form elements - it uses the original $form array instead of returning a brand-new array with provided elements only as suggested in the documentation:

function hook_field_widget_third_party_settings_form(\Drupal\Core\Field\WidgetInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $element = [];
  // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field
  // widgets.
  if ($plugin->getPluginId() == 'foo_widget') {
    $element['my_setting'] = [
      '#type' => 'checkbox',
      '#title' => t('My setting'),
      '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'),
    ];
  }
  return $element;
}

Steps to reproduce

1) Enable "Admin Tooltips" module;
2) Go to "Manage Form Display" page of any configurable bundle;
3) Open field widget settings of any field (gear icon);

Proposed resolution

Do not use the existing $form array to attach additional fields.

πŸ“Œ Task
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine Matroskeen πŸ‡ΊπŸ‡¦ Ukraine, Lutsk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024