Add NULL check for $entity in simplify_form_alter

Created on 2 July 2025, 12 days ago

Problem/Motivation

Using the Simplify module with another custom module that use hook form alter trigger a crash from Simplify

TypeError : class_implements(): Argument #1 ($object_or_class) must be of type object|string, null given dans class_implements() (ligne 369 de *\modules\contrib\simplify\simplify.module).

Proposed resolution

Adding a null check for $entity

function simplify_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (!method_exists($form_state->getFormObject(), 'getEntity')) {
    return;
  }

  $entity = $form_state->getFormObject()->getEntity();
  if(!is_null($entity)) {
    if (in_array('Drupal\eck\EckEntityInterface', class_implements($entity))) {
      // Get array of fields to hide.
      $fields = _simplify_get_config_value('simplify_eck_global');
      // Hide fields.
      simplify_hide_fields($fields, $form);
    }
  }
}

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France damiendo

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