81 lines
2.3 KiB
PHP
81 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Utilities;
|
|
use ourcodeworld\NameThatColor\ColorInterpreter as NameThatColor;
|
|
|
|
class RestAPI
|
|
{
|
|
public function __construct()
|
|
{
|
|
add_action( 'rest_api_init', [$this, 'blocks']);
|
|
}
|
|
|
|
public function blocks( )
|
|
{
|
|
$restBase = 'badegg/v1';
|
|
|
|
register_rest_route($restBase, '/blocks/config', [
|
|
'methods' => 'GET',
|
|
'callback' => [ $this, 'config'],
|
|
'permission_callback' => function(){
|
|
return true;
|
|
},
|
|
]);
|
|
}
|
|
|
|
public function config()
|
|
{
|
|
return rest_ensure_response([
|
|
'container' => $this->containerWidths(),
|
|
'colours' => $this->colours(),
|
|
'tints' => $this->tints(),
|
|
]);
|
|
}
|
|
|
|
public function containerWidths()
|
|
{
|
|
return [
|
|
[ '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' ],
|
|
];
|
|
}
|
|
|
|
public function colours()
|
|
{
|
|
$colour = new Colour;
|
|
$NameThatColour = new NameThatColor;
|
|
|
|
$palette = [];
|
|
|
|
$colours = $colour->values();
|
|
|
|
foreach($colours as $slug => $hex) {
|
|
$palette[] = [
|
|
'name' => esc_html__(@$NameThatColour->name($hex)['name'], 'badegg'),
|
|
'slug' => $slug,
|
|
'color' => $hex,
|
|
];
|
|
}
|
|
|
|
return $palette;
|
|
}
|
|
|
|
public function tints()
|
|
{
|
|
return [
|
|
['label' => __('Lightest', 'badegg'), 'value' => 'lightest'],
|
|
['label' => __('Lighter', 'badegg'), 'value' => 'lighter' ],
|
|
['label' => __('Light', 'badegg'), 'value' => 'light' ],
|
|
['label' => __('None', 'badegg'), 'value' => 0 ],
|
|
['label' => __('Dark', 'badegg'), 'value' => 'dark' ],
|
|
['label' => __('Darker', 'badegg'), 'value' => 'darker' ],
|
|
['label' => __('Darkest', 'badegg'), 'value' => 'darkest' ],
|
|
];
|
|
}
|
|
|
|
}
|