default content block that uses core inner blocks
This commit is contained in:
@@ -8,21 +8,51 @@ class CloneGroup
|
||||
{
|
||||
|
||||
}
|
||||
public function background()
|
||||
public function block_background()
|
||||
{
|
||||
return [
|
||||
'contrast',
|
||||
'bg_type',
|
||||
'bg_colour',
|
||||
'bg_tint',
|
||||
'bg_opacity',
|
||||
'bg_image',
|
||||
'bg_video',
|
||||
'pattern',
|
||||
'pattern_top',
|
||||
'pattern_bottom',
|
||||
'padding_top',
|
||||
'padding_bottom',
|
||||
];
|
||||
}
|
||||
|
||||
public function block_intro()
|
||||
{
|
||||
return [
|
||||
'overline',
|
||||
'heading',
|
||||
'blurb',
|
||||
'intro_alignment',
|
||||
];
|
||||
}
|
||||
|
||||
public function block_footer()
|
||||
{
|
||||
return [
|
||||
'blurb_footer',
|
||||
'links',
|
||||
'footer_alignment',
|
||||
];
|
||||
}
|
||||
|
||||
public function block_settings()
|
||||
{
|
||||
return [
|
||||
'section_anchor_id',
|
||||
'padding_top',
|
||||
'padding_bottom',
|
||||
'container_width',
|
||||
'angle_status',
|
||||
'angle_position',
|
||||
'angle_direction',
|
||||
'angle_colour',
|
||||
'angle_tint',
|
||||
];
|
||||
}
|
||||
|
||||
public function block_all()
|
||||
{
|
||||
return array_merge($this->block_intro(), $this->block_footer(), $this->block_settings(), $this->block_background());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin;
|
||||
use Blocks\Content;
|
||||
|
||||
class Blocks
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_filter( 'block_categories_all' , [$this, 'categories']);
|
||||
add_action('allowed_block_types_all', [$this, 'blacklist'], 100, 2);
|
||||
}
|
||||
|
||||
public function categories( $categories )
|
||||
{
|
||||
|
||||
// Adding a new category.
|
||||
$categories = array_merge([
|
||||
[
|
||||
'slug' => 'badegg',
|
||||
'title' => __('Provided by Bad Egg Digital'),
|
||||
],
|
||||
], $categories);
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public function blacklist()
|
||||
{
|
||||
// Reference:
|
||||
@@ -130,6 +146,10 @@ class Blocks
|
||||
'core/social-links',
|
||||
];
|
||||
|
||||
$Content = new Content\Content();
|
||||
|
||||
$blacklist = array_diff($blacklist, $Content->inner_blocks());
|
||||
|
||||
return array_values( array_diff( $blocks, $blacklist ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Blocks;
|
||||
use App\Utilities;
|
||||
use App\ACF;
|
||||
|
||||
class BadExample
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_action('acf/init', [$this, 'init']);
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
acf_register_block_type([
|
||||
'name' => 'badegg/bad-example',
|
||||
'title' => __('Bad Example'),
|
||||
'description' => __('This is an example block'),
|
||||
'render_callback' => [ $this, 'render'],
|
||||
'category' => 'layout',
|
||||
'multiple' => false,
|
||||
'icon' => [
|
||||
'src' => 'dismiss',
|
||||
],
|
||||
'supports' => [
|
||||
'align' => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function render($block)
|
||||
{
|
||||
$CssClasses = new Utilities\CssClasses;
|
||||
$Colour = new Utilities\Colour;
|
||||
$CloneGroup = new ACF\CloneGroup;
|
||||
|
||||
$data = [];
|
||||
|
||||
$fields = [
|
||||
'heading',
|
||||
'blurb',
|
||||
];
|
||||
|
||||
$fields = array_merge($fields, $CloneGroup->background());
|
||||
|
||||
foreach($fields as $field):
|
||||
$data[$field] = get_field($field);
|
||||
endforeach;
|
||||
|
||||
unset($block['data']);
|
||||
$block['name'] = str_replace('acf/', '', $block['name']);
|
||||
|
||||
$data = array_merge($data, $block);
|
||||
$data['section_classes'] = $CssClasses->section($data);
|
||||
$data['block'] = $block;
|
||||
|
||||
$data['knockout'] = ($Colour->is_dark($data['bg_colour'], $data['bg_tint'], $data['contrast'])) ? null : 'knockout';
|
||||
|
||||
echo \Roots\view('blocks.bad-example', [
|
||||
'data' => $data,
|
||||
'block' => $block,
|
||||
])->render();
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,8 @@ class CssClasses {
|
||||
|
||||
$classes = [
|
||||
'section',
|
||||
'section-' . str_replace('acf/', '', $props['name']),
|
||||
'section-' . $props['name'],
|
||||
// 'section-' . str_replace('acf/', '', $props['name']),
|
||||
'bg-' . $this->colourTint([
|
||||
'colour' => @$props['bg_colour'],
|
||||
'tint' => @$props['bg_tint'],
|
||||
|
||||
@@ -31,9 +31,6 @@ class App extends Composer
|
||||
'VideoSrcset' => new Utilities\VideoSrcset,
|
||||
'ImageSrcset' => new Utilities\ImageSrcset,
|
||||
'siteName' => $this->siteName(),
|
||||
'company_legal' => get_field('badegg_company_legal', 'option'),
|
||||
'company_tel' => get_field('badegg_company_tel', 'option'),
|
||||
'company_email' => get_field('badegg_company_email', 'option'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user