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

Issue fork simplify-3533650

Command icon 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:

Comments

damiendo created an issue. See original summary.

damiendo’s picture

Issue summary: View changes
avpaderno’s picture

Version: 8.x-1.2 » 8.x-1.x-dev
dhruv.mittal’s picture

Assigned: Unassigned » dhruv.mittal
dhruv.mittal’s picture

Assigned: dhruv.mittal » Unassigned

I've checked .module file where simplify_form_alter hook present but it's empty.
Thank you

karavkars’s picture

Version: 8.x-1.x-dev » 2.x-dev
dhruv.mittal’s picture

Assigned: Unassigned » dhruv.mittal

Got it, providing MR for the same soon !

dhruv.mittal’s picture

Assigned: dhruv.mittal » Unassigned
Status: Active » Needs review
karavkars’s picture

Assigned: Unassigned » karavkars

Reviewing this.

karavkars’s picture

Assigned: karavkars » Unassigned

Hello @dhruv,
Reviewed your MR. applied patch on the module looks good.
Found coding standards issues, committed the same on this branch.
@Someone please review the same,

Regards,

kadamsubodh0619’s picture

Assigned: Unassigned » kadamsubodh0619
kadamsubodh0619’s picture

Status: Needs review » Reviewed & tested by the community

Hello @dhruv, @karavkars

I reviewed MR raised by @dhruv and PHPCS fixes done by @karavkars.
Its working fine for me post applying patch from MR.
Moving this issue to RTBC.

Thank you,
Subodh Kadam

astonvictor’s picture

Status: Reviewed & tested by the community » Fixed

thanks for the report.
merged to the dev branch

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

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

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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