diff --git a/src/Root.php b/src/Root.php index bec9d18e..9d42d673 100644 --- a/src/Root.php +++ b/src/Root.php @@ -21,7 +21,7 @@ class Root * * @var string */ - public const VERSION = '2.1.0'; + public const VERSION = '2.1.1'; /** * The registered booting callbacks. diff --git a/src/Traits/ResolvesActions.php b/src/Traits/ResolvesActions.php index 30e8fcd8..45222d9d 100644 --- a/src/Traits/ResolvesActions.php +++ b/src/Traits/ResolvesActions.php @@ -5,6 +5,7 @@ use Closure; use Cone\Root\Actions\Action; use Cone\Root\Actions\Actions; +use Cone\Root\Support\Filters; use Illuminate\Http\Request; use Illuminate\Support\Arr; @@ -44,14 +45,16 @@ public function withActions(Closure $callback): static public function resolveActions(Request $request): Actions { if (is_null($this->actions)) { - $this->actions = new Actions($this->actions($request)); + $actions = new Actions($this->actions($request)); - $this->actions->when(! is_null($this->actionsResolver), function (Actions $actions) use ($request): void { + $actions->when(! is_null($this->actionsResolver), function (Actions $actions) use ($request): void { $actions->register( Arr::wrap(call_user_func_array($this->actionsResolver, [$request])) ); }); + $this->actions = Filters::apply(static::class.'.actions', $actions, $this); + $this->actions->each(function (Action $action) use ($request): void { $this->resolveAction($request, $action); }); diff --git a/src/Traits/ResolvesFields.php b/src/Traits/ResolvesFields.php index cfb4ec94..38231f59 100644 --- a/src/Traits/ResolvesFields.php +++ b/src/Traits/ResolvesFields.php @@ -7,6 +7,7 @@ use Cone\Root\Fields\Fields; use Cone\Root\Fields\File; use Cone\Root\Fields\Media; +use Cone\Root\Support\Filters; use Illuminate\Http\Request; use Illuminate\Support\Arr; @@ -60,14 +61,16 @@ public function hasFileField(Request $request): bool public function resolveFields(Request $request): Fields { if (is_null($this->fields)) { - $this->fields = new Fields($this->fields($request)); + $fields = new Fields($this->fields($request)); - $this->fields->when(! is_null($this->fieldsResolver), function (Fields $fields) use ($request): void { + $fields->when(! is_null($this->fieldsResolver), function (Fields $fields) use ($request): void { $fields->register( Arr::wrap(call_user_func_array($this->fieldsResolver, [$request])) ); }); + $this->fields = Filters::apply(static::class.'.fields', $fields, $this); + $this->fields->each(function (Field $field) use ($request): void { $this->resolveField($request, $field); }); diff --git a/src/Traits/ResolvesFilters.php b/src/Traits/ResolvesFilters.php index ee75c0de..743562a6 100644 --- a/src/Traits/ResolvesFilters.php +++ b/src/Traits/ResolvesFilters.php @@ -5,6 +5,7 @@ use Closure; use Cone\Root\Filters\Filter; use Cone\Root\Filters\Filters; +use Cone\Root\Support\Filters as ValueFilters; use Illuminate\Http\Request; use Illuminate\Support\Arr; @@ -46,14 +47,16 @@ public function withFilters(Closure $callback): static public function resolveFilters(Request $request): Filters { if (is_null($this->filters)) { - $this->filters = new Filters($this->filters($request)); + $filters = new Filters($this->filters($request)); - $this->filters->when(! is_null($this->filtersResolver), function (Filters $filters) use ($request): void { + $filters->when(! is_null($this->filtersResolver), function (Filters $filters) use ($request): void { $filters->register( Arr::wrap(call_user_func_array($this->filtersResolver, [$request])) ); }); + $this->filters = ValueFilters::apply(static::class.'.filters', $filters, $this); + $this->filters->each(function (Filter $filter) use ($request): void { $this->resolveFilter($request, $filter); }); diff --git a/src/Traits/ResolvesWidgets.php b/src/Traits/ResolvesWidgets.php index 0e0ff9f5..737f4e93 100644 --- a/src/Traits/ResolvesWidgets.php +++ b/src/Traits/ResolvesWidgets.php @@ -2,6 +2,7 @@ namespace Cone\Root\Traits; +use Cone\Root\Support\Filters; use Cone\Root\Widgets\Widget; use Cone\Root\Widgets\Widgets; use Illuminate\Http\Request; @@ -27,7 +28,9 @@ public function widgets(Request $request): array public function resolveWidgets(Request $request): Widgets { if (is_null($this->widgets)) { - $this->widgets = new Widgets($this->widgets($request)); + $widgets = new Widgets($this->widgets($request)); + + $this->widgets = Filters::apply(static::class.'.widgets', $widgets, $this); $this->widgets->each(function (Widget $widget) use ($request): void { $this->resolveWidget($request, $widget);