aryehraber / statamic-captcha

Statamic Addon that protects your Statamic forms using a Captcha service.
MIT License
11 stars 8 forks source link

Captcha blocks `EntrySaving` event from propagating #21

Closed edalzell closed 3 years ago

edalzell commented 3 years ago

Right now Captcha returns $entry and according to this code in EntrySaving::dispatch, the propagation stops on the first non-null value:

    /**
     * Dispatch the event with the given arguments, and halt on first non-null listener response.
     *
     * @return mixed
     */
    public static function dispatch()
    {
        return event(new static(...func_get_args()), [], true);
    }

This means if you have additional listeners, they don't get called when you return anything.

Confirmed that this code in handle fixes the issue, in the CP:

        if (Statamic::isCpRoute()) {
            return null;
        }
aryehraber commented 3 years ago

@edalzell Oh good find! Should we just stop returning the entry all together (outside of CP as well), don't think it's doing anything useful anyway?

edalzell commented 3 years ago

Yes return null so the propagation can continue. The return value is never used, for entries.

aryehraber commented 3 years ago

Version 1.5.2 has been released, thanks for your help on this!