mirror of
https://github.com/getgrav/grav.git
synced 2025-10-26 07:56:07 +01:00
Blueprint extend: Add blueprint special types support
This commit is contained in:
14
composer.lock
generated
14
composer.lock
generated
@@ -637,22 +637,22 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/rockettheme/toolbox.git",
|
||||
"reference": "ede7afafb4ab4e808324ea2b6e6f58aee3efaf26"
|
||||
"reference": "a88015f9e6e473e5ddf4294f747d8fe434de3857"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/rockettheme/toolbox/zipball/ede7afafb4ab4e808324ea2b6e6f58aee3efaf26",
|
||||
"reference": "ede7afafb4ab4e808324ea2b6e6f58aee3efaf26",
|
||||
"url": "https://api.github.com/repos/rockettheme/toolbox/zipball/a88015f9e6e473e5ddf4294f747d8fe434de3857",
|
||||
"reference": "a88015f9e6e473e5ddf4294f747d8fe434de3857",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"pimple/pimple": "~3.0",
|
||||
"symfony/event-dispatcher": "~2.5",
|
||||
"symfony/yaml": "~2.5"
|
||||
"symfony/event-dispatcher": ">2.5",
|
||||
"symfony/yaml": ">2.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.0.*"
|
||||
"phpunit/phpunit": "~5.1"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@@ -677,7 +677,7 @@
|
||||
"php",
|
||||
"rockettheme"
|
||||
],
|
||||
"time": "2016-02-11 19:08:48"
|
||||
"time": "2016-02-16 10:01:59"
|
||||
},
|
||||
{
|
||||
"name": "symfony/console",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace Grav\Common\Config;
|
||||
|
||||
use Grav\Common\File\CompiledYamlFile;
|
||||
use Grav\Common\Grav;
|
||||
use RocketTheme\Toolbox\Blueprints\Blueprints;
|
||||
|
||||
/**
|
||||
@@ -19,6 +20,22 @@ class CompiledBlueprints extends CompiledBase
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Returns checksum from the configuration files.
|
||||
*
|
||||
* You can set $this->checksum = false to disable this check.
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function checksum()
|
||||
{
|
||||
if (!isset($this->checksum)) {
|
||||
$this->checksum = md5(json_encode($this->files) . json_encode($this->getTypes()) . $this->version);
|
||||
}
|
||||
|
||||
return $this->checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create configuration object.
|
||||
*
|
||||
@@ -26,13 +43,21 @@ class CompiledBlueprints extends CompiledBase
|
||||
*/
|
||||
protected function createObject(array $data = [])
|
||||
{
|
||||
$this->object = new Blueprints($data);
|
||||
$this->object = (new Blueprints($data))->setTypes($this->getTypes());
|
||||
}
|
||||
|
||||
protected function getTypes()
|
||||
{
|
||||
return Grav::instance()['plugins']->formFieldTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize configuration object.
|
||||
*/
|
||||
protected function finalizeObject() {}
|
||||
protected function finalizeObject()
|
||||
{
|
||||
$this->object->init('static');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load single configuration file and append it to the correct position.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace Grav\Common\Data;
|
||||
|
||||
use Grav\Common\File\CompiledYamlFile;
|
||||
use Grav\Common\GravTrait;
|
||||
use Grav\Common\Grav;
|
||||
use RocketTheme\Toolbox\ArrayTraits\Export;
|
||||
use RocketTheme\Toolbox\ArrayTraits\ExportInterface;
|
||||
use RocketTheme\Toolbox\Blueprints\Blueprints as BaseBlueprints;
|
||||
@@ -15,7 +15,7 @@ use RocketTheme\Toolbox\Blueprints\Blueprints as BaseBlueprints;
|
||||
*/
|
||||
class Blueprint extends BaseBlueprints implements ExportInterface
|
||||
{
|
||||
use Export, GravTrait;
|
||||
use Export;
|
||||
|
||||
public $initialized = false;
|
||||
|
||||
@@ -34,6 +34,10 @@ class Blueprint extends BaseBlueprints implements ExportInterface
|
||||
$this->setContext($context);
|
||||
}
|
||||
|
||||
$types = Grav::instance()['plugins']->formFieldTypes;
|
||||
|
||||
$this->setTypes($types);
|
||||
|
||||
if ($data) {
|
||||
$this->embed('', $data);
|
||||
$this->init('static');
|
||||
@@ -262,7 +266,7 @@ class Blueprint extends BaseBlueprints implements ExportInterface
|
||||
&& $field['validate']['required'] === true
|
||||
&& !isset($data[$name])) {
|
||||
$value = isset($field['label']) ? $field['label'] : $field['name'];
|
||||
$language = self::getGrav()['language'];
|
||||
$language = Grav::instance()['language'];
|
||||
$message = sprintf($language->translate('FORM.MISSING_REQUIRED_FIELD', null, true) . ' %s', $value);
|
||||
$messages[$field['name']][] = $message;
|
||||
}
|
||||
@@ -310,7 +314,7 @@ class Blueprint extends BaseBlueprints implements ExportInterface
|
||||
$value = $call['params'];
|
||||
|
||||
$default = isset($field[$property]) ? $field[$property] : null;
|
||||
$config = self::getGrav()['config']->get($value, $default);
|
||||
$config = Grav::instance()['config']->get($value, $default);
|
||||
|
||||
if (!is_null($config)) {
|
||||
$field[$property] = $config;
|
||||
|
||||
@@ -21,6 +21,11 @@ class Plugin implements EventSubscriberInterface
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $features = [];
|
||||
|
||||
/**
|
||||
* @var Grav
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,8 @@ class Plugins extends Iterator
|
||||
{
|
||||
use GravTrait;
|
||||
|
||||
public $formFieldTypes;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
@@ -44,21 +46,40 @@ class Plugins extends Iterator
|
||||
public function setup()
|
||||
{
|
||||
$blueprints = [];
|
||||
$formFields = [];
|
||||
|
||||
/** @var Plugin $plugin */
|
||||
foreach ($this->items as $plugin) {
|
||||
if (isset($plugin->features['blueprints'])) {
|
||||
$blueprints["plugin://{$plugin->name}/blueprints"] = $plugin->features['blueprints'];
|
||||
}
|
||||
if (method_exists($plugin, 'getFormFieldTypes')) {
|
||||
$formFields[get_class($plugin)] = isset($plugin->features['formfields']) ? $plugin->features['formfields'] : 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ($blueprints) {
|
||||
// Order by priority.
|
||||
arsort($blueprints);
|
||||
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = Grav::instance()['locator'];
|
||||
|
||||
$locator->addPath('blueprints', '', array_keys($blueprints), 'system/blueprints');
|
||||
}
|
||||
|
||||
if ($formFields) {
|
||||
// Order by priority.
|
||||
arsort($formFields);
|
||||
|
||||
$list = [];
|
||||
foreach ($formFields as $className => $priority) {
|
||||
$plugin = $this->items[$className];
|
||||
$list += $plugin->getFormFieldTypes();
|
||||
}
|
||||
|
||||
$this->formFieldTypes = $list;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user