Skip to content

Commit

Permalink
🐛 Fix legacy widget registration (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Mar 6, 2024
1 parent 8fa7ce3 commit 64a0472
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
59 changes: 45 additions & 14 deletions src/AcfComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class AcfComposer
*/
protected array $deferredComposers = [];

/**
* The legacy widgets.
*/
protected array $legacyWidgets = [];

/**
* The registered plugin paths.
*/
Expand Down Expand Up @@ -74,14 +79,6 @@ public static function make(Application $app): self
return new static($app);
}

/**
* Handle the ACF Composer instance.
*/
public function handle(): void
{
add_action('acf/init', fn () => $this->boot());
}

/**
* Boot the registered Composers.
*/
Expand All @@ -91,11 +88,33 @@ public function boot(): void
return;
}

$this->handleBlocks();
$this->registerDefaultPath();

$this->handleBlocks();
$this->handleWidgets();

add_filter('acf/init', fn () => $this->handleComposers());

$this->booted = true;
}

/**
* Handle the Composer registration.
*/
public function handleComposers(): void
{
foreach ($this->composers as $namespace => $composers) {
foreach ($composers as $i => $composer) {
$composer = $composer::make($this);

if (is_subclass_of($composer, Options::class) && ! is_null($composer->parent)) {
$this->deferredComposers[$namespace][] = $composer;

unset($this->composers[$namespace][$i]);

continue;
}

$this->composers[$namespace][$i] = $composer->handle();
}
}
Expand All @@ -107,8 +126,22 @@ public function boot(): void
}

$this->deferredComposers = [];
}

$this->booted = true;
/**
* Handle the Widget Composer registration.
*/
public function handleWidgets(): void
{
foreach ($this->legacyWidgets as $namespace => $composers) {
foreach ($composers as $composer) {
$composer = $composer::make($this);

$this->composers[$namespace][] = $composer->handle();
}
}

$this->legacyWidgets = [];
}

/**
Expand Down Expand Up @@ -196,10 +229,8 @@ public function register(string $composer, string $namespace): bool
return false;
}

$composer = $composer::make($this);

if (is_subclass_of($composer, Options::class) && ! is_null($composer->parent)) {
$this->deferredComposers[$namespace][] = $composer;
if (is_subclass_of($composer, Widget::class)) {
$this->legacyWidgets[$namespace][] = $composer;

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/AcfComposerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function boot()

$composer = $this->app->make('AcfComposer');

$composer->handle();
$composer->boot();

if ($this->app->runningInConsole()) {
$this->commands([
Expand Down

0 comments on commit 64a0472

Please sign in to comment.