Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications service getFormNotificationByHandle method is broken #2249

Open
jedso opened this issue Jan 21, 2025 · 1 comment
Open

Notifications service getFormNotificationByHandle method is broken #2249

jedso opened this issue Jan 21, 2025 · 1 comment

Comments

@jedso
Copy link

jedso commented Jan 21, 2025

Describe the bug

I went to use getFormNotificationByHandle() for some custom module logic, i.e.
Formie::$plugin->getNotifications()->getFormNotificationByHandle($form, 'notificationHandle');

...but it was always returning null. This is due to the method always returning the 0 index of the whereMultiple array:

public function getFormNotificationByHandle(Form $form, string $handle): ?Notification
{
return ArrayHelper::whereMultiple($this->_notifications(), ['formId' => $form->id, 'handle' => $handle])[0] ?? null;
}

In my case, the ArrayHelper::whereMultiple($this->_notifications(), ['formId' => $form->id, 'handle' => $handle]) call by itself was returning a valid notification but it had an index of 9, and hence would never be returned:

Image

Steps to reproduce

  1. Make sure you have >1 notifications created
  2. Add a new notification to a form
  3. Grab the form, store in $form, and call Formie::$plugin->getNotifications()->getFormNotificationByHandle($form, 'newNotificationHandle'); with your new notification handle, and observe how it will always return null.

Form settings

  • Multi-page form: No
  • Submission Method: Ajax
  • Client-side Validation: Yes
  • Custom Form Templates: Yes

Craft CMS version

5.5.6.1

Plugin version

3.0.15

Multi-site?

No

Additional context

No response

@engram-design
Copy link
Member

Ah, a great point! Fixed for the next release. To get this early, run composer require verbb/formie:"dev-craft-5 as 3.0.15".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants