Skip to content

Commit

Permalink
v1.4.1
Browse files Browse the repository at this point in the history
- feat(blocks): Generate blocks with InnerBlock support when using compatible ACF versions (Fixes #16)
- enhance(partials): Optimize conditional order for partials
  • Loading branch information
Log1x authored Jul 1, 2020
1 parent 7eb6b52 commit 5fd6065
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ protected function build($fields = [])
protected function get($partial = null)
{
if (
! is_subclass_of($partial, Partial::class) ||
(new ReflectionClass($partial))->isAbstract()
is_subclass_of($partial, Partial::class) &&
! (new ReflectionClass($partial))->isAbstract()
) {
return is_string($partial) ? include $this->app->path(
Str::finish(
Str::finish($path, '/'),
Str::finish($name, '.php')
)
) : $partial;
return (new $partial($this->app))->compose();
}

return (new $partial($this->app))->compose();
return is_string($partial) ? include $this->app->path(
Str::finish(
Str::finish($path, '/'),
Str::finish($name, '.php')
)
) : $partial;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Console/BlockMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Log1x\AcfComposer\Console;

use Illuminate\Support\Str;

class BlockMakeCommand extends MakeCommand
{
/**
Expand Down Expand Up @@ -41,10 +43,21 @@ class BlockMakeCommand extends MakeCommand
*/
protected function getStub()
{
if (
! empty($version = get_option('acf_version')) &&
Str::before($version, '-') >= '5.9.0'
) {
$this->view = 'repeater-innerblock';
}

if ($this->option('full')) {
return __DIR__ . '/stubs/block.full.stub';
}

if (Str::before($version, '-') >= '5.9.0') {
return __DIR__ . '/stubs/block.innerblock.stub';
}

return __DIR__ . '/stubs/block.stub';
}
}
4 changes: 3 additions & 1 deletion src/Console/stubs/block.full.stub
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class DummyClass extends Block
*
* @var array
*/
public $supports = [];
public $supports = [
'__experimental_jsx' => true,
];

/**
* Data to be passed to the block before rendering.
Expand Down
86 changes: 86 additions & 0 deletions src/Console/stubs/block.innerblock.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace DummyNamespace;

use Log1x\AcfComposer\Block;
use StoutLogic\AcfBuilder\FieldsBuilder;

class DummyClass extends Block
{
/**
* The block name.
*
* @var string
*/
public $name = 'DummyClass';

/**
* The block description.
*
* @var string
*/
public $description = 'Lorem ipsum...';

/**
* The block category.
*
* @var string
*/
public $category = 'common';

/**
* The block icon.
*
* @var string|array
*/
public $icon = 'star-half';

/**
* The block features.
*
* @var array
*/
public $supports = [
'__experimental_jsx' => true,
'mode' => false,
];

/**
* Data to be passed to the block before rendering.
*
* @return array
*/
public function with()
{
return [
'items' => $this->items(),
];
}

/**
* The block field group.
*
* @return array
*/
public function fields()
{
$DummyCamel = new FieldsBuilder('DummySnake');

$DummyCamel
->addRepeater('items')
->addText('item')
->endRepeater();

return $DummyCamel->build();
}

/**
* Return the items field.
*
* @return array
*/
public function items()
{
return get_field('items') ?: [];
}
}
11 changes: 11 additions & 0 deletions src/Console/stubs/views/repeater-innerblock.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@if ($items)
<ul>
@foreach ($items as $item)
<li>{{ $item['item'] }}</li>
@endforeach
</ul>
@else
<p>No items found!</p>
@endif

<InnerBlock />

This comment has been minimized.

Copy link
@orlockz

orlockz Jul 8, 2020

I believe this is supposed to be <InnerBlocks />.
(Missing 's')

This comment has been minimized.

Copy link
@Log1x

Log1x Jul 8, 2020

Author Owner

Indeed it is ;_;

0 comments on commit 5fd6065

Please sign in to comment.