Skip to content

Commit

Permalink
hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Mar 4, 2024
1 parent 9ab3c73 commit d4da958
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Root
*
* @var string
*/
public const VERSION = '2.1.0';
public const VERSION = '2.1.1';

/**
* The registered booting callbacks.
Expand Down
7 changes: 5 additions & 2 deletions src/Traits/ResolvesActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
});
Expand Down
7 changes: 5 additions & 2 deletions src/Traits/ResolvesFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
});
Expand Down
7 changes: 5 additions & 2 deletions src/Traits/ResolvesFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
});
Expand Down
5 changes: 4 additions & 1 deletion src/Traits/ResolvesWidgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit d4da958

Please sign in to comment.