awcodes / filament-curator

A media picker plugin for Filament Panels.
MIT License
324 stars 86 forks source link

shouldRegisterNavigation Closure type missing #381

Closed WilliamPinto-Olmos closed 9 months ago

WilliamPinto-Olmos commented 9 months ago

Filament Version

v2.17.55

Plugin Version

v2.10.2

PHP Version

PHP 8.2

Problem description

the registerNavigation() method in Curator.php Facade is expected to receive a bool|Closure|null types, but the actual variable $shoudlRegisterNavigation is typed only as bool.

public function registerNavigation(bool|Closure|null $condition = true): static
{
    $this->shouldRegisterNavigation = $condition;

    return $this;
}

This ends up in an error when passing a closure to the registerNavigation() in the Curator facade, as I need to determine the registerNavigation using the authenticated user, that's why I needed to be evaluated in the closure.

Expected behavior

You should be able to pass a Closure to the registerNavigation() to determine whether register the navigation.

Steps to reproduce

In any service provider using the Curator facade, use the method registerNavigation() passing a Closure as a parameter.

Curator::registerNavigation(static fn () => auth()->user()->hasRole('some-role'));

You will see the following error.

image

This is caused by the property $shouldRegisterNavigation being declared only as bool type.

protected bool $shouldRegisterNavigation = true;

If you change the vendor and type it as bool|Closure it works fine as the shouldRegisterNavigation() method evaluates the variable using evaluate() function.

Reproduction repository

No response

Relevant log output

No response

awcodes commented 9 months ago

Fixed in v2.10.3