Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Add support for passing partials to ->addLayout (Fixes #257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Aug 12, 2024
2 parents f7f998b + a5eb943 commit c80c52d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Builder/FlexibleContentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Log1x\AcfComposer\Builder;

use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Partial;
use ReflectionClass;
use StoutLogic\AcfBuilder\FieldsBuilder;
use StoutLogic\AcfBuilder\FlexibleContentBuilder as FieldBuilder;

Expand Down Expand Up @@ -64,6 +66,14 @@ class FlexibleContentBuilder extends FieldBuilder
*/
public function addLayout($layout, $args = [])
{
if (
is_string($layout) &&
is_subclass_of($layout, Partial::class) &&
! (new ReflectionClass($layout))->isAbstract()
) {
$layout = $layout::make($this->composer())->compose();
}

$layout = is_a($layout, FieldsBuilder::class)
? clone $layout
: Builder::make($layout, $args);
Expand Down
1 change: 1 addition & 0 deletions src/Console/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function handle()
'public function enqueue($block = [])' => 'public function assets(array $block): void',
'public function enqueue()' => 'public function assets(array $block): void',
'/->addFields\(\$this->get\((.*?)\)\)/' => fn ($match) => "->addPartial({$match[1]})",
'/->addLayout\(\$this->get\((.*?)\)\)/' => fn ($match) => "->addLayout({$match[1]})",
];

$this->components->info('Checking for outdated <fg=blue>ACF Composer</> classes...');
Expand Down

0 comments on commit c80c52d

Please sign in to comment.