Skip to content

Error when passing Closure as view to EventCoreRegistry::getLocalizedView() [Laravel 10] #759

@mplodowski

Description

@mplodowski

When a Closure is passed as the $view parameter to RainLab\Translate\Classes\EventCoreRegistry::getLocalizedView(), the following error occurs:

Error: Object of class Closure could not be converted to string in EventCoreRegistry.php:344

This is due to a sprintf() call that assumes $view can be converted to a string:

sprintf('%s-%s', $view, $locale);

Closures cannot be cast to string, which causes the exception. A type check should be added to handle closures differently and avoid this fatal error.

I’m using a Laravel package that sends notifications via Laravel’s native notification system. One of the notifications uses a Closure as the view, which causes an exception inside the RainLab Translate plugin and prevents the notification from being sent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions