diff --git a/web/app/themes/badegg/app/blocks.php b/web/app/themes/badegg/app/blocks.php
index ae10807..1eae159 100644
--- a/web/app/themes/badegg/app/blocks.php
+++ b/web/app/themes/badegg/app/blocks.php
@@ -4,7 +4,18 @@
* Theme Blocks.
*/
-namespace App;
+namespace App\Blocks;
+
+// Disable all core blocks except what we need as inner blocks
+// resources/js/editor.js handles hiding the inner blocks at the top level
+add_action('allowed_block_types_all', __NAMESPACE__ . '\\list_allowed', 100, 2);
+
+// add blocks to the allowed list via filter
+add_filter('badegg_block_types_allow', function($allowed){
+ return array_merge($allowed, [
+ // 'core/categories',
+ ]);
+});
// Add the badegg block category
add_filter( 'block_categories_all' , function ( $categories ) {
@@ -25,6 +36,7 @@ add_action('init', function () {
$blocks = glob(get_theme_file_path('resources/views/blocks/*/block.json'));
foreach ($blocks as $block_json) {
+ $json = json_decode($block_json);
$slug = basename(dirname($block_json));
// Editor JS
@@ -61,7 +73,7 @@ add_action('init', function () {
);
}
- register_block_type($block_json, [
+ $props = [
'editor_script' => "{$slug}-editor-script",
'editor_style' => "{$slug}-editor-style",
'style' => "{$slug}-style",
@@ -79,27 +91,15 @@ add_action('init', function () {
return $content;
}
- ]);
+ ];
+
+ if(!@$json['render_callback']) unset($props['render_callback']);
+
+ register_block_type($block_json, $props);
}
});
-// Disable most of the core blocks
-add_action('allowed_block_types_all', function(){
- $blocks = array_keys( \WP_Block_Type_Registry::get_instance()->get_all_registered() );
- $blacklist = array_diff(block_blacklist(), block_whitelist());
-
- return array_values( array_diff( $blocks, $blacklist ) );
-}, 100, 2);
-
-function block_blacklist()
-{
- $file = file_get_contents(get_theme_file_path("resources/json/core-block-blacklist.json"));
- $json = json_decode($file);
-
- return $json;
-}
-
-function block_whitelist()
+function list_inner()
{
$file = file_get_contents(get_theme_file_path("resources/json/core-block-whitelist.json"));
$json = json_decode($file);
@@ -107,14 +107,32 @@ function block_whitelist()
return $json;
}
-function block_all()
+function list_all()
{
- $enabled_blocks = array_map(function($block) {
+ $blocks = array_map(function($block) {
$name = $block->name;
return $block->name;
}, \WP_Block_Type_Registry::get_instance()->get_all_registered());
- return array_values($enabled_blocks);
+ return array_values($blocks);
+}
+
+function list_custom()
+{
+ return array_filter(list_all(), function($value){
+ if (str_starts_with($value, 'acf/') || str_starts_with($value, 'badegg/')) return $value;
+ });
+}
+
+function list_allowed()
+{
+ $add_allowed = [];
+
+ return array_merge(
+ list_custom(),
+ list_inner(),
+ apply_filters('badegg_block_types_allow', $add_allowed),
+ );
}
diff --git a/web/app/themes/badegg/resources/js/editor.js b/web/app/themes/badegg/resources/js/editor.js
index d94e11c..f15df0c 100644
--- a/web/app/themes/badegg/resources/js/editor.js
+++ b/web/app/themes/badegg/resources/js/editor.js
@@ -1,45 +1,45 @@
import domReady from '@wordpress/dom-ready';
+import blockWhitelist from '../json/core-block-whitelist.json';
domReady(() => {
+ const TEXT_EDITOR_BLOCKS = [
+ // Design
+ 'core/separator',
+ 'core/spacer',
+
+ // Media
+ 'core/cover',
+ 'core/file',
+ 'core/gallery',
+ 'core/image',
+ 'core/media-text',
+ 'core/audio',
+ 'core/video',
+
+ // Text
+ 'core/footnotes',
+ 'core/heading',
+ 'core/list',
+ 'core/code',
+ 'core/details',
+ 'core/list-item',
+ 'core/missing',
+ 'core/paragraph',
+ 'core/preformatted',
+ 'core/pullquote',
+ 'core/quote',
+ 'core/table',
+ 'core/verse',
+ ];
const restrictEditorParentBlocks = (settings, name) => {
- const TEXT_EDITOR_BLOCKS = [
- // Design
- 'core/separator',
- 'core/spacer',
-
- // Media
- 'core/cover',
- 'core/file',
- 'core/gallery',
- 'core/image',
- 'core/media-text',
- 'core/audio',
- 'core/video',
-
- // Text
- 'core/footnotes',
- 'core/heading',
- 'core/list',
- 'core/code',
- 'core/details',
- 'core/freeform',
- 'core/list-item',
- 'core/missing',
- 'core/paragraph',
- 'core/preformatted',
- 'core/pullquote',
- 'core/quote',
- 'core/table',
- 'core/verse',
- ];
-
if (TEXT_EDITOR_BLOCKS.includes(name)) {
- settings.parent = ['acf/badegg-editor']
+ settings.parent = [
+ 'acf/badegg-editor',
+ 'badegg/article',
+ ];
}
- // console.log(settings, name)
-
return settings
}
diff --git a/web/app/themes/badegg/resources/json/core-block-blacklist.json b/web/app/themes/badegg/resources/json/core-block-blacklist.json
deleted file mode 100644
index 1a97b6c..0000000
--- a/web/app/themes/badegg/resources/json/core-block-blacklist.json
+++ /dev/null
@@ -1,102 +0,0 @@
-[
- "core/button",
- "core/comment-template",
- "core/home-link",
- "core/navigation-link",
- "core/navigation-submenu",
- "core/buttons",
- "core/column",
- "core/columns",
- "core/group",
- "core/more",
- "core/nextpage",
- "core/separator",
- "core/spacer",
- "core/text-columns",
-
- "core/embed",
-
- "core/cover",
- "core/file",
- "core/gallery",
- "core/image",
- "core/media-text",
- "core/audio",
- "core/video",
-
- "core/block",
-
- "core/footnotes",
- "core/heading",
- "core/list",
- "core/code",
- "core/details",
- "core/freeform",
- "core/list-item",
- "core/missing",
- "core/paragraph",
- "core/preformatted",
- "core/pullquote",
- "core/quote",
- "core/table",
- "core/verse",
-
- "core/avatar",
- "core/comment-author-name",
- "core/comment-content",
- "core/comment-date",
- "core/comment-edit-link",
- "core/comment-reply-link",
- "core/comments",
- "core/comments-pagination",
- "core/comments-pagination-next",
- "core/comments-pagination-numbers",
- "core/comments-pagination-previous",
- "core/comments-title",
- "core/loginout",
- "core/navigation",
- "core/pattern",
- "core/post-author",
- "core/post-author-biography",
- "core/post-author-name",
- "core/post-comments-form",
- "core/post-content",
- "core/post-date",
- "core/post-excerpt",
- "core/post-featured-image",
- "core/post-navigation-link",
- "core/post-template",
- "core/post-terms",
- "core/post-title",
- "core/query",
- "core/query-no-results",
- "core/query-pagination",
- "core/query-pagination-next",
- "core/query-pagination-numbers",
- "core/query-pagination-previous",
- "core/query-title",
- "core/read-more",
- "core/site-logo",
- "core/site-tagline",
- "core/site-title",
- "core/template-part",
- "core/term-description",
- "core/post-comments",
-
- "core/legacy-widget",
- "core/widget-group",
- "core/archives",
- "core/calendar",
- "core/categories",
- "core/latest-comments",
- "core/latest-posts",
- "core/page-list",
- "core/page-list-item",
- "core/rss",
- "core/search",
- "core/shortcode",
- "core/social-link",
- "core/tag-cloud",
- "core/html",
- "core/social-links"
-]
diff --git a/web/app/themes/badegg/resources/views/acf-blocks/Editor/Editor.php b/web/app/themes/badegg/resources/views/acf-blocks/Editor/Editor.php
index 632a792..effa2c2 100644
--- a/web/app/themes/badegg/resources/views/acf-blocks/Editor/Editor.php
+++ b/web/app/themes/badegg/resources/views/acf-blocks/Editor/Editor.php
@@ -41,7 +41,7 @@ class Editor
$themeURL = get_template_directory_uri();
if($is_preview && @$block['data']['inserter']):
- echo '
';
+ echo '
';
return;
endif;
diff --git a/web/app/themes/badegg/resources/views/blocks/article/block.json b/web/app/themes/badegg/resources/views/blocks/article/block.json
new file mode 100644
index 0000000..0ecf606
--- /dev/null
+++ b/web/app/themes/badegg/resources/views/blocks/article/block.json
@@ -0,0 +1,10 @@
+{
+ "apiVersion": 3,
+ "name": "badegg/article",
+ "title": "Article Builder",
+ "category": "badegg",
+ "description": "A wrapper to contain core blocks",
+ "editorScript": "article-editor-script",
+ "editorStyle": "article-editor-style",
+ "style": "article-style"
+}
diff --git a/web/app/themes/badegg/resources/views/blocks/article/editor.scss b/web/app/themes/badegg/resources/views/blocks/article/editor.scss
new file mode 100644
index 0000000..3677994
--- /dev/null
+++ b/web/app/themes/badegg/resources/views/blocks/article/editor.scss
@@ -0,0 +1,3 @@
+.block-badegg-example-editor {
+ display: block;
+}
diff --git a/web/app/themes/badegg/resources/views/blocks/article/index.jsx b/web/app/themes/badegg/resources/views/blocks/article/index.jsx
new file mode 100644
index 0000000..6a95bfa
--- /dev/null
+++ b/web/app/themes/badegg/resources/views/blocks/article/index.jsx
@@ -0,0 +1,41 @@
+import { registerBlockType } from '@wordpress/blocks';
+import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
+import metadata from './block.json';
+import allowedBlocks from '../../../json/core-block-whitelist.json';
+
+registerBlockType(metadata.name, {
+ icon: {
+ src: 'format-aside',
+ foreground: '#f58762',
+ },
+ edit({ attributes, setAttributes }) {
+ const blockProps = useBlockProps();
+
+ return (
+
+ );
+ },
+ save() {
+ return (
+
+ )
+ }
+});
diff --git a/web/app/themes/badegg/resources/views/blocks/article/render.blade.php b/web/app/themes/badegg/resources/views/blocks/article/render.blade.php
new file mode 100644
index 0000000..6dd917d
--- /dev/null
+++ b/web/app/themes/badegg/resources/views/blocks/article/render.blade.php
@@ -0,0 +1,3 @@
+
+ Bad Egg Article Block (Blade)
+
diff --git a/web/app/themes/badegg/resources/views/blocks/article/style.scss b/web/app/themes/badegg/resources/views/blocks/article/style.scss
new file mode 100644
index 0000000..575266f
--- /dev/null
+++ b/web/app/themes/badegg/resources/views/blocks/article/style.scss
@@ -0,0 +1,3 @@
+.block-badegg-hero {
+ display: block;
+}
diff --git a/web/app/themes/badegg/resources/views/blocks/example/index.jsx b/web/app/themes/badegg/resources/views/blocks/example/index.jsx
index edf11dc..aef1c57 100644
--- a/web/app/themes/badegg/resources/views/blocks/example/index.jsx
+++ b/web/app/themes/badegg/resources/views/blocks/example/index.jsx
@@ -1,7 +1,6 @@
import { registerBlockType } from '@wordpress/blocks';
registerBlockType('badegg/example', {
- apiVersion: 3, // optional in JS, primarily in block.json
edit() {
return (