1. Go to this page and download the library: Download log1x/acf-composer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
log1x / acf-composer example snippets
namespace App\Fields;
use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Field;
class ExampleField extends Field
{
/**
* The field group.
*
* @return array
*/
public function fields()
{
$fields = Builder::make('example_field');
$fields
->setLocation('post_type', '==', 'post');
$fields
->addRepeater('items')
->addText('item')
->endRepeater();
return $fields->build();
}
}
namespace App\Fields\Partials;
use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Partial;
class ListItems extends Partial
{
/**
* The partial field group.
*
* @return array
*/
public function fields()
{
$fields = Builder::make('listItems');
$fields
->addRepeater('items')
->addText('item')
->endRepeater();
return $fields;
}
}
namespace App\Fields;
use App\Fields\Partials\ListItems;
use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Field;
class Example extends Field
{
/**
* The field group.
*
* @return array
*/
public function fields()
{
$fields = Builder::make('example');
$fields
->setLocation('post_type', '==', 'post');
$fields
->addPartial(ListItems::class);
return $fields->build();
}
}
namespace App\Blocks;
use Log1x\AcfComposer\Block;
use Log1x\AcfComposer\Builder;
class ExampleBlock extends Block
{
/**
* The block name.
*
* @var string
*/
public $name = 'Example Block';
/**
* 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';
/**
* 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()
{
$fields = Builder::make('example_block');
$fields
->addRepeater('items')
->addText('item')
->endRepeater();
return $fields->build();
}
/**
* Return the items field.
*
* @return array
*/
public function items()
{
return get_field('items') ?: [];
}
}