Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Code improvements #80

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Change Log

## [0.8.1]

- Added the option `SupportsFullHeight`
- fix: Typos
- fix: condition to apply supports_align_content

## [0.8]

- Merged the PR [#75](https://github.com/MWDelaney/sage-acf-gutenberg-blocks/pull/75) by [@robmeijerink](https://github.com/robmeijerink)
- Merged the PR [#69](https://github.com/MWDelaney/sage-acf-gutenberg-blocks/pull/69) by [@mccahan](https://github.com/mccahan)
- Merged the PR [#65](https://github.com/MWDelaney/sage-acf-gutenberg-blocks/pull/65) by [@teaforchris](https://github.com/teaforchris)
- Code Improvements
- Added verification before to insert the template
- Now It requires PHP >=7.4

## [0.7]

- Fix Sage9 view location. Thanks [@robmeijerink](https://github.com/robmeijerink)!

## [0.6]

- Merge pull request #49 from speakerbug/support-acf-5.9
- Support new properties in ACF 5.9

## [0.5]

- Sage 10 support
- Anchor support

## [0.4.2]

- Add support for "Mode" and "PostTypes" headers in block registration.

## [0.4.1]

- Fix regression in locate_template() function call

## [0.4]

- Fix alignment classes.

## [0.3]

- Refactor for maintainability
- Add `sage-acf-gutenberg-blocks-templates` filter to define new locations for blocks
- Limit block detection to the directories supplied to the filter, fixes errors on subdirectories

## [0.2]

- Fix namespace in callback function.

## [0.1]

- Update README.md
48 changes: 38 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Sage ACF Gutenberg Blocks
Generate ACF Gutenberg blocks just by adding templates to your Sage theme. This package is based heavily on [this article](https://medium.com/nicooprat/acf-blocks-avec-gutenberg-et-sage-d8c20dab6270) by [nicoprat](https://github.com/nicooprat).
Generate ACF Gutenberg blocks just by adding templates to your Sage theme.

This package is based heavily on [this article](https://medium.com/nicooprat/acf-blocks-avec-gutenberg-et-sage-d8c20dab6270) by [nicoprat](https://github.com/nicooprat).

## Installation
Run the following in your Sage (v9 or 10) based theme directory:
```sh
composer require "mwdelaney/sage-acf-gutenberg-blocks"
composer require "larodiel/sage-acf-gutenberg-blocks"
```

## Creating blocks
Expand All @@ -22,9 +24,12 @@ Add blade templates to `views/blocks` which get and use ACF data. Each template
SupportsAlign:
SupportsMode:
SupportsMultiple:
SupportsFullHeight:
SupportsInnerBlocks:
EnqueueStyle:
EnqueueScript:
EnqueueAssets:
Parent:
--}}
```

Expand All @@ -43,9 +48,12 @@ Add blade templates to `views/blocks` which get and use ACF data. Each template
SupportsAlign: left right
SupportsMode: false
SupportsMultiple: false
SupportsFullHeight: false
SupportsInnerBlocks: false
EnqueueStyle: styles/style.css
EnqueueScript: scripts/script.js
EnqueueAssets: path/to/asset
Parent: core/column
--}}

<blockquote data-{{ $block['id'] }} class="{{ $block['classes'] }}">
Expand All @@ -71,18 +79,22 @@ The options in the file header map to options in the [`acf_register_block_type`
| ------------------ | ------------------------------------------------ | ---------- | ---- |
| `Title` | Title of the block in the gutenberg editor | i.e. `Testimonial` | _required_ |
| `Description` | Description of the block in the gutenberg editor | i.e. `My testimonial block` | _optional_ |
| `Category` | Category to store the block in. Use these values or [register your own custom block categories](https://wordpress.org/gutenberg/handbook/extensibility/extending-blocks/#managing-block-categories) | `common`, `formatting`, `layout`, `widgets`, `embed` | _required_ |
| `Category` | Category to store the block in. Use these values or [register your own custom block categories](#creating-your-custom-blocks-categories) | `common`, `formatting`, `layout`, `widgets`, `embed` | _required_ |
| `Icon` | An icon property can be specified to make it easier to identify a block. Uses [dashicons](https://developer.wordpress.org/resource/dashicons/) | i.e. `book-alt` | _optional_ |
| `Keywords` | An array of search terms to help user discover the block while searching. Sepearate values with a space. | i.e. `quote mention cite` | _optional_ |
| `Keywords` | An array of search terms to help user discover the block while searching. Separate values with a space. | i.e. `quote mention cite` | _optional_ |
| `Mode` | The display mode for your block. auto: Preview is shown by default but changes to edit form when block is selected. preview: Preview is always shown. Edit form appears in sidebar when block is selected. edit: Edit form is always shown. | `auto`, `preview` or `edit` |_optional_ (defaults to `preview`) |
| `Align` | The default block alignment. | `left center right wide full` |_optional_ (defaults to empty string)
| `PostTypes` | An array of post types to restrict this block type to. Sepearate values with a space. | i.e. `post page` |
| `PostTypes` | An array of post types to restrict this block type to. Separate values with a space. | i.e. `post page` |
| `SupportsAlign` | This property adds block controls which allow the user to change the block’s alignment. Set to true to show all alignments, false to hide the alignment toolbar. Set to an array (strings separated by spaces) of specific alignment names to customize the toolbar. | (boolean) `true`, `false`<br> or (array) `left center right wide full` | _optional_ (defaults to true) |
| `SupportsMode` | This property allows the user to toggle between edit and preview modes via a button. | `true` or `false` |_optional_ (defaults to `true`) |
| `SupportsMultiple` | This property allows the block to be added multiple times. | `true` or `false` |_optional_ (defaults to `true`) |
| `SupportsInnerBlocks` | This property allows the block to support the nesting of other blocks within it. | `true` or `false` |_optional_ (defaults to `false`) |
| `SupportsFullHeight` | This property allows enables the full height button on the toolbar of a block | `true` or `false` |_optional_ (defaults to `false`) |
| `SupportsInnerBlocks` | This property allows the block to support the nesting of other blocks within it. | `true` or `false` |_optional_ (defaults to `false`) ___This works just on preview mode___ |
| `SupportsAlignText` | This property adds an alignment toolbar button similar to that seen when editing a paragraph of text. | `true` or `false` |_optional_ (defaults to `false`) |
| `SupportsAlignContent` | This property adds an alignment toolbar button similar to that seen when editing a core "Cover block" | `true` or `false` |_optional_ (defaults to `false`) |
| `SupportsAlignContent` | This property adds an alignment toolbar button similar to that seen when editing a core "Cover block" | `true`, `false` or matrix (Show full alignment matrix in toolbar) |_optional_ (defaults to `false`) |
| `EnqueueStyle` | A CSS file to load when the block is used. | e.g. `styles/my-block.css` |_optional_ (defaults to empty string) |
| `EnqueueScript` | A JS file to load when the block is used. | e.g. `scripts/my-block.js` |_optional_ (defaults to empty string) |
| `Parent` | An array of block types to restrict where this block can be used. Separate values with a space. | e.g. `core/column acf/parent-block` |_optional_ (defaults to usable anywhere) |

## Creating ACF fields
Once a block is created you'll be able to assign ACF fields to it using the standard Custom Fields interface in WordPress. We recommend using [sage-advanced-custom-fields](https://github.com/MWDelaney/sage-advanced-custom-fields) to keep your ACF fields in version control with Sage.
Expand All @@ -91,15 +103,31 @@ Once a block is created you'll be able to assign ACF fields to it using the stan
Block data can be altered via the 'sage/blocks/[block-name]/data' filter. For example, if your block template is called `my-block.blade.php`, you can alter the data this way:

```php
add_filter('sage/blocks/my-block/data', function ($block) { // Do your thing here. });
add_filter('sage/blocks/my-block/data', function ($block) { /* Do your thing here. */ });
```

## Filter template folders
By default all your template files in `views/blocks` will be loaded. You can use the templates filter to add more folders if you wish. See an example below of how to add your own folders.

```php
add_filter('sage-acf-gutenberg-blocks-templates', function ($folders) {
add_filter('sage-acf-gutenberg-blocks-templates', function ($folders) {
$folders[] = 'views/your-folder'; // Adds your folder
return $folders;
});
```
```

## Creating your custom blocks categories

```php
add_filter('block_categories_all', function ($categories) {
// Define the new categories
$newCategories = [
['slug' => 'my-custom-category', 'title' => __('Custom Category', 'sage')],
['slug' => 'my-custom-category2', 'title' => __('Custom Category 2', 'sage')],
];

// Merge the new categories with the existing ones
return array_merge($categories, $newCategories);
});
```
More details about the hook `block_categories_all` on [registering your own custom block categories](https://developer.wordpress.org/reference/hooks/block_categories_all/)
36 changes: 26 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
{
"name": "mwdelaney/sage-acf-gutenberg-blocks",
"description": "Create Gutenberg blocks from Sage blade templates and ACF fields.",
"keywords": ["wordpress", "gutenberg", "advanced custom fields"],
"homepage": "https://github.com/MWDelaney/sage-acf-gutenberg-blocks",
"name": "larodiel/sage-acf-gutenberg-blocks",
"description": "Fork of the original Sage ACF Gutenberg Blocks project. Create Gutenberg blocks from Sage blade templates and ACF fields.",
"keywords": [
"wordpress",
"gutenberg",
"advanced custom fields"
],
"homepage": "https://github.com/larodiel/sage-acf-wp-blocks",
"license": "MIT",
"authors": [
{
"name": "Michael W. Delaney",
"email": "[email protected]"
"email": "[email protected]",
"homepage": "https://github.com/MWDelaney",
"role": "Creator"
},
{
"name": "Nico Prat",
"homepage": "https://github.com/nicooprat",
"role": "Developer"
},
{
"name": "Nico Prat"
}
"name": "Victor Larodiel",
"email": "[email protected]",
"homepage": "https://github.com/larodiel",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.2"
"php": ">=7.4"
},
"autoload": {
"files": ["sage-acf-gutenberg-blocks.php"]
"autoload": {
"files": [
"sage-acf-gutenberg-blocks.php"
]
}
}
Loading