Problem/Motivation

The Event Logger module assumes that a form will provide the structure $form['#submit] and throws a PHP error when the $form['action']['submit] structure is used. This issue is being encountered by using the Context module.

See elogger.module line 87.

// Skip the elogger exposed form from elogging events triggering.
  if ($form['#id'] != $elogger_exposed_form) {
    array_unshift($form['#submit'], '_add_form_submit_log');
  }
}

Steps to reproduce

  1. Install the Context module.
  2. Add a Condition based on a URL Request.
  3. Add a Reaction to place a Block.
  4. Click the 'Place Block' button to place a block in a region.

Result:The "Place Button" form submit causes the Event Logger module to throw a PHP error:
TypeError: array_unshift(): Argument #1 ($array) must be of type array, null given in array_unshift() (line 87 of /Users/myuser/Sites/mysite/docroot/modules/contrib/elogger/elogger.module)

Proposed resolution

Review the Forms API and Forms AJAX API to determine the correct format, OR, modify the conditional statement to handle multiple form array formats.

https://www.drupal.org/docs/drupal-apis/form-api/introduction-to-form-api

https://www.drupal.org/docs/drupal-apis/javascript-api/ajax-forms

CommentFileSizeAuthor
#5 3310192-5.patch480 bytesnarendra.rajwar27

Issue fork elogger-3310192

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

kbaringer created an issue. See original summary.

smustgrave’s picture

Tried replicating this but wasn't able to generate the error.

Could you provide more specific steps? What version of Drupal are you on?

andrei.vesterli’s picture

Let me check it...

andrei.vesterli’s picture

Assigned: Unassigned » andrei.vesterli
Status: Active » Needs work
narendra.rajwar27’s picture

Status: Needs work » Needs review
StatusFileSize
new480 bytes

Adding patch.

andrei.vesterli’s picture

Hello @narendra.rajwar27

Good to see a patch here but it seems that it's not fixing the actual issue that was described. We need to focus on this line:
array_unshift($form['#submit'], '_add_form_submit_log');

I need to find some time to fix it...

We need to handle the case when there is no $form['#submit'] key, also when we have this key $form['action'] and maybe others.

Regards,
Andrei

andrei.vesterli’s picture

Status: Needs review » Needs work
smustgrave’s picture

Fixing credit

narendra.rajwar27’s picture

We need to handle the case when there is no $form['#submit'] key, also when we have this key $form['action'] and maybe others
@andrei.vesterli, sure. Thanks!!

Till the time the above patch can be used. As i have checked and tested that place block option is working with condition and reaction which was not working earlier.

andrei.vesterli’s picture

Status: Needs work » Needs review

  • andrei.vesterli committed 7b1ad1e3 on 1.x
    Issue #3310192 by andrei.vesterli, narendra.rajwar27: Ajax Form Callback...
andrei.vesterli’s picture

Status: Needs review » Fixed
andrei.vesterli’s picture

Status: Fixed » Closed (fixed)