Problem/Motivation
In some circumstances within the ui_patterns_field_group_field_group_field_overview_submit function in the ui_patterns_field_group.module file, an error occurs indicating that the value passed as the first argument to the method_exists function is null. The method_exists function requires an object or a string (the class name), but in your code, it seems that $plugin_definition['class'] may not be correctly defined or could be null.
Proposed resolution
To resolve this issue, I added a check to ensure that $plugin_definition['class'] is not null before calling method_exists. Here is how the updated code might look:
function ui_patterns_field_group_field_group_field_overview_submit(array $form, FormStateInterface $form_state) {
$field_group_form_state = $form_state->get('field_group');
if (!empty($field_group_form_state)) {
foreach ($form['#fieldgroups'] as $group_name) {
// Only save updated groups.
if (!isset($field_group_form_state[$group_name])) {
continue;
}
if (isset($field_group_form_state[$group_name]->format_settings)) {
// Retrieve the plugin definition.
$plugin_definition = \Drupal::service('plugin.manager.field_group.formatters')->getDefinition($field_group_form_state[$group_name]->format_type, FALSE);
// Ensure that $plugin_definition is not null and that the class exists.
if ($plugin_definition && isset($plugin_definition['class']) && method_exists($plugin_definition['class'], 'processFormStateValues')) {
call_user_func_array([
$plugin_definition['class'],
'processFormStateValues',
], [&$field_group_form_state[$group_name]->format_settings]);
}
}
}
// Set the form_state so that the submit hook of field_groups can work.
$form_state->set('field_group', $field_group_form_state);
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | Value_passed_as_the_first_argument_to_the_method_existsfunction_is_null-3469106-2.patch | 1.35 KB | yasmeensalah |
Comments
Comment #2
yasmeensalah commentedThe proposed resolution to the issue is working perfectly in my case.
Making it as patch to be able to apply it using composer
Comment #4
duaelfrI've never seen this issue happen but that kind of condition cannot hurt.
Thank you both!