Compare commits
5 Commits
fd4ee11d26
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a8df23529 | |||
| 1d3a8477ee | |||
| fc49265cb9 | |||
| 8ffec45182 | |||
| 002f33c5e1 |
36
app/API/Admin.php
Normal file
36
app/API/Admin.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\API;
|
||||
|
||||
class Admin
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_action( 'rest_api_init', [$this, 'blocks']);
|
||||
}
|
||||
|
||||
public function blocks( )
|
||||
{
|
||||
register_rest_route('badegg/v1', '/blocks/container_width', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [ $this, 'container_width'],
|
||||
'permission_callback' => function(){
|
||||
return true;
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
public function container_width()
|
||||
{
|
||||
$containerWidths = [
|
||||
[ 'label' => __('Auto', 'badegg'), 'value' => 0 ],
|
||||
[ 'label' => __('Narrow', 'badegg'), 'value' => 'narrow' ],
|
||||
[ 'label' => __('Small', 'badegg'), 'value' => 'small' ],
|
||||
[ 'label' => __('Medium', 'badegg'), 'value' => 'medium' ],
|
||||
[ 'label' => __('Large', 'badegg'), 'value' => 'large' ],
|
||||
[ 'label' => __('Edge to edge', 'badegg'), 'value' => 'full' ],
|
||||
];
|
||||
|
||||
return rest_ensure_response($containerWidths);
|
||||
}
|
||||
}
|
||||
@@ -57,21 +57,8 @@ autoload_psr4('PostTypes');
|
||||
autoload_psr4('ACF');
|
||||
autoload_psr4('Utilities');
|
||||
autoload_psr4('Admin');
|
||||
autoload_psr4('Ajax');
|
||||
autoload_psr4('API');
|
||||
|
||||
function autoload_psr4_blocks() {
|
||||
$path = __dir__ . '/resources/views/acf-blocks/*';
|
||||
$namespace = 'Blocks\\';
|
||||
|
||||
foreach(glob($path, GLOB_ONLYDIR) as $directory) {
|
||||
$name = basename($directory);
|
||||
$class = $namespace . $name . '\\' . $name;
|
||||
|
||||
new $class();
|
||||
}
|
||||
}
|
||||
|
||||
autoload_psr4_blocks();
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -142,11 +142,7 @@ hr {
|
||||
}
|
||||
|
||||
.align {
|
||||
&-centre {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&-right {
|
||||
text-align: right;
|
||||
}
|
||||
&-left { text-align: left; }
|
||||
&-centre, &-center { text-align: center; }
|
||||
&-right { text-align: right; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"apiVersion": 3,
|
||||
"name": "badegg/acfdemo",
|
||||
"title": "ACF Demo",
|
||||
"category": "badegg",
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
// block.json's editorScript, loaded only in the block editor
|
||||
console.log('loaded: resources/views/blocks/acfdemo/index.js')
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
// block.json's script, loaded in block editor and front end
|
||||
console.log('loaded: resources/views/blocks/acf-demo/script.js')
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
// block.json's viewScript, applied on front end only
|
||||
console.log('loaded: resources/views/blocks/acf-demo/view.js')
|
||||
|
||||
@@ -8,9 +8,25 @@
|
||||
"foreground": "#f58762"
|
||||
},
|
||||
"description": "A wrapper to contain core blocks",
|
||||
"attributes": {
|
||||
"container_width": {
|
||||
"type": "string",
|
||||
"default": 0
|
||||
},
|
||||
"alignment": {
|
||||
"type": "string"
|
||||
},
|
||||
"padding_top": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"padding_bottom": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
"html": true,
|
||||
"align": ["wide", "full"],
|
||||
"color": {
|
||||
"background": true,
|
||||
"text": false
|
||||
|
||||
@@ -1,17 +1,93 @@
|
||||
// block.json's editorScript, loaded only in the block editor
|
||||
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { registerBlockType } from '@wordpress/blocks';
|
||||
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
|
||||
|
||||
import {
|
||||
useBlockProps,
|
||||
InnerBlocks,
|
||||
InspectorControls,
|
||||
BlockControls,
|
||||
AlignmentToolbar,
|
||||
} from '@wordpress/block-editor';
|
||||
|
||||
import {
|
||||
Panel,
|
||||
PanelBody,
|
||||
PanelRow,
|
||||
SelectControl,
|
||||
ToggleControl,
|
||||
} from '@wordpress/components';
|
||||
import { useState, useEffect } from '@wordpress/element';
|
||||
import apiFetch from '@wordpress/api-fetch';
|
||||
import metadata from './block.json';
|
||||
import allowedBlocks from '../../../json/core-block-whitelist.json';
|
||||
|
||||
registerBlockType(metadata.name, {
|
||||
edit({ attributes, setAttributes }) {
|
||||
const blockProps = useBlockProps();
|
||||
const [ isLoading, setIsLoading ] = useState( true );
|
||||
|
||||
const {
|
||||
container_width,
|
||||
alignment,
|
||||
padding_top,
|
||||
padding_bottom,
|
||||
} = attributes;
|
||||
|
||||
const [
|
||||
containerWidthOptions, setContainerWidthOptions,
|
||||
] = useState( [] );
|
||||
|
||||
useEffect( () => {
|
||||
apiFetch( { path: '/badegg/v1/blocks/container_width' } )
|
||||
.then( ( data ) => {
|
||||
setContainerWidthOptions( data );
|
||||
setIsLoading( false );
|
||||
} )
|
||||
.catch( () => {
|
||||
setContainerWidthOptions( [] );
|
||||
setIsLoading( false );
|
||||
} );
|
||||
}, [] );
|
||||
|
||||
console.log(attributes);
|
||||
|
||||
return (
|
||||
<div { ...blockProps }>
|
||||
<div className="container">
|
||||
<BlockControls>
|
||||
<AlignmentToolbar
|
||||
value={ alignment }
|
||||
onChange={(value) => setAttributes({alignment: value})}
|
||||
/>
|
||||
</BlockControls>
|
||||
<InspectorControls>
|
||||
<Panel>
|
||||
<PanelBody title={ __("Settings", "badegg") }>
|
||||
<SelectControl
|
||||
label={ __("Container Width", "badegg") }
|
||||
value={ container_width }
|
||||
options={ containerWidthOptions }
|
||||
onChange={ (value) => setAttributes({ container_width: value }) }
|
||||
__next40pxDefaultSize={ true }
|
||||
__nextHasNoMarginBottom={ true }
|
||||
/>
|
||||
<ToggleControl
|
||||
label={ __('Top Padding', 'badegg') }
|
||||
checked={ padding_top }
|
||||
onChange={(value) => setAttributes({ padding_top: value }) }
|
||||
__nextHasNoMarginBottom
|
||||
/>
|
||||
<ToggleControl
|
||||
label={ __('Bottom Padding', 'badegg') }
|
||||
checked={ padding_bottom }
|
||||
onChange={(value) => setAttributes({ padding_bottom: value }) }
|
||||
__nextHasNoMarginBottom
|
||||
/>
|
||||
</PanelBody>
|
||||
</Panel>
|
||||
</InspectorControls>
|
||||
<div className={`container container-${ attributes.container_width } align-${ attributes.alignment }`}>
|
||||
<InnerBlocks
|
||||
allowedBlocks={ allowedBlocks }
|
||||
defaultBlock={
|
||||
@@ -27,10 +103,10 @@ registerBlockType(metadata.name, {
|
||||
</div>
|
||||
);
|
||||
},
|
||||
save() {
|
||||
save({ attributes }) {
|
||||
return (
|
||||
<div { ...useBlockProps.save() }>
|
||||
<div className="container">
|
||||
<div className={`container container-${attributes.container_width} align-${ attributes.alignment }`}>
|
||||
<InnerBlocks.Content />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
// block.json's script, loaded in block editor and front end
|
||||
console.log('loaded: resources/views/blocks/article/script.js')
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
// block.json's viewScript, applied on front end only
|
||||
console.log('loaded: resources/views/blocks/article/view.js')
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
// block.json's script, loaded in block editor and front end
|
||||
console.log('loaded: resources/views/blocks/example/script.js')
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
// block.json's viewScript, applied on front end only
|
||||
console.log('loaded: resources/views/blocks/example/view.js')
|
||||
|
||||
Reference in New Issue
Block a user