Problem/Motivation
Since the flood gates are open for multiple implementations of the same hook in the same modules, the hooks field_widget_third_party_settings_form and field_formatter_third_party_settings_form don't support that since they expects each module to have only one implementation
Steps to reproduce
Use the Hook attribute twice in the same module
#[Hook('field_widget_third_party_settings_form')]
public function fieldWidgetThirdPartySettingsForm(WidgetInterface $plugin, FieldDefinitionInterface $field_definition, $form_mode, $form, FormStateInterface $form_state) {
adding different form elements.
Both form elements are expected but only one of them show up, the last one to be processed.
Proposed resolution
Merge all elements of the same module in the same form array
Remaining tasks
Code solution.
Add tests.
User interface changes
None
Issue fork drupal-3489707
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3489707-support-multiple-implementations
changes, plain diff MR !10332
Comments
Comment #3
rodrigoaguileraWeird. The tests are not failing where they are supposed to.
The solution to fixing the test should be in core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php protected function thirdPartySettingsForm().
Adding:
$settings_form[$module] = ($settings_form[$module] ?? []) + $hook(
Comment #4
ghost of drupal pastdon't forget field_formatter_third_party_settings_form as well
Comment #5
rodrigoaguileraComment #6
rodrigoaguileraSeems like trying to fail the test on purpose, changing assertNotEmpty for assertEmpty, also passes the test so I'm clueless about what is happening with that test :(
Comment #7
rodrigoaguileraSeems like it was an issue with not declaring the schema for the new third party setting field.
I also squashed the experiments that I did while I didn't have a proper dev enviroment.
In the last two commits I add just the test, failing in the correct place and then the simple fix that fixes those tests.
The test only checks widgets, not formatters but since it was the same fix for both I didn't find it very useful to duplicate testing there.
Comment #8
ghost of drupal pastThanks for the rapid fix, I like it but I can't RTBC it because I suggested the heart of the change so it would be somewhat RTBC'ing my own code. Maybe others don't quite like the succinct version and want core to elaborate on it? I dunno.
Comment #9
nicxvan commentedSorry since this is one of two exceptions I think we need a test for both to prevent a regression more than prove the fix works.
Comment #10
rodrigoaguileraSure. Added tests for the formatters as well
Comment #11
nicxvan commentedLooks great now thanks!
Comment #12
acbramley commentedPHPStan basline has conflicts
Comment #13
rodrigoaguileraThe phpstan issues were solved in other commits so no need to modify the baseline anymore. Back to RTBC
Comment #14
quietone commentedI read the IS, comments and the MR. There are no unanswered questions and I updated credit.
I did leave suggestions in the MR for to improve the comments. But I think they are minor and should not block commit, unless, of course, another committer wants those comments changed.
Leaving at RTBC
Comment #15
rodrigoaguileraThanks. I applied the suggestions from the MR
Comment #17
catchphpcs fails after a rebase.
Comment #18
rodrigoaguileraThanks for the rebase. I added some $this->t() to other string to be consistent.
Plase review again
Comment #19
nicxvan commentedComment #20
catchCommitted/pushed to 11.x, thanks!
Comment #23
catchComment #25
berdirThis results in a fatal error if a field_widget_third_party_settings_form hook doesn't return an array, such as entity_browser_entity_form_field_widget_third_party_settings_form(), which conditionally adds something only for a certain plugin.
created a follow-up: #3514262: entity_browser_entity_form_field_widget_third_party_settings_form hooks can no longer return NULL