Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rareloop/pebble-acf-blocks
https://github.com/rareloop/pebble-acf-blocks
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/rareloop/pebble-acf-blocks
- Owner: Rareloop
- License: mit
- Created: 2020-04-03T15:12:07.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-04-28T15:50:15.000Z (over 4 years ago)
- Last Synced: 2024-04-27T13:07:57.207Z (7 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ACF Blocks for Pebble (Lumberjack & Primer)
This package provides a way to create [ACF Blocks](https://www.advancedcustomfields.com/resources/blocks/) that use Twig templates and simultaneously integrate with both Lumberjack and Primer.
## Installation
`composer require rareloop/pebble-acf-blocks`
Once installed, register the Service Provider in config/app.php:
```php
'providers' => [
...Rareloop\Lumberjack\AcfBlocks\AcfBlocksProvider::class,
...
],
```Copy the example `config/acfblocks.php` file to you theme directory.
## Usage
To create a block, first create a child of the `AcfBlock`. This should sit in the same folder as your Primer component, for example `blocks/my-block`. The name of the class should also be the Upper Camel Case version of the folder name, in our case `MyBlock`.
_Note: Pebble maps the namespace `\Patterns` to the directory `my-theme/resources/patterns`_
```php
get_field('test_field'),
];
}/**
* Provide the config required to register this block
* https://www.advancedcustomfields.com/resources/acf_register_block_type/
*
* @return array
*/
public static function blockConfig(): array
{
return [
'name' => 'mytestblock',
'title' => __('Test Block'),
'description' => __('A first go with a block.'),
'category' => 'formatting',
'icon' => 'admin-comments',
'keywords' => ['testimonial', 'quote'],
];
}
}
```The `blockConfig()` function is what ACF uses to register the block with WordPress. For more configuration options please see the [ACF documentation](https://www.advancedcustomfields.com/resources/acf_register_block_type/).
The `context()` function is where you provide the data for your patterns `template.twig` file when used in WordPress. Within this function, all calls to `get_field()` will be scoped to the current Gutenberg block, as is the case with other ACF Blocks.
The final step is to add the class to your `config/acfblocks.php` file:
```php
[
\Patterns\Blocks\MyBlock\MyBlock::class,
]
];
```### Additional Parameters
You have access to the following additional parameters from within your ACF class:
- `$this->content` - The block inner HTML (empty)
- `$this->isPreview` - Whether or not the block is being shown in preview
- `$this->postId` - The ID of the post that the block is attached to