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);
  }
}

Comments

braintec created an issue. See original summary.

yasmeensalah’s picture

The proposed resolution to the issue is working perfectly in my case.
Making it as patch to be able to apply it using composer

  • duaelfr committed b2e027e8 on 8.x-1.x authored by yasmeensalah
    fix: #3469106 Value passed as the first argument to the method_exists...
duaelfr’s picture

Version: 8.x-1.8 » 8.x-1.x-dev
Status: Active » Fixed

I've never seen this issue happen but that kind of condition cannot hurt.
Thank you both!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.