Blueprints: Add support for importing fields (#637)

This commit is contained in:
Matias Griese
2016-02-02 11:56:12 +02:00
parent 9024d0f3e3
commit 327826542d

View File

@@ -1,6 +1,7 @@
<?php
namespace Grav\Common\Data;
use Grav\Common\File\CompiledYamlFile;
use Grav\Common\GravTrait;
use RocketTheme\Toolbox\ArrayTraits\Export;
use RocketTheme\Toolbox\ArrayTraits\ExportInterface;
@@ -29,13 +30,14 @@ class Blueprint extends BaseBlueprints implements ExportInterface
{
parent::__construct(is_array($name) ? $name : null);
if ($data) {
$this->embed('', $data);
}
if ($context) {
$this->setContext($context);
}
if ($data) {
$this->embed('', $data);
$this->init('static');
}
}
/**
@@ -265,21 +267,27 @@ class Blueprint extends BaseBlueprints implements ExportInterface
* @param string $property
* @param array $call
*/
protected function dynamicImport(array &$field, $property, array &$call)
protected function staticImport(array &$field, $property, array &$call)
{
$params = $call['params'];
// Support nested blueprints.
if ($this->context) {
$values = (array) $params;
if (!isset($field['fields'])) {
$field['fields'] = [];
}
foreach ($values as $bname) {
$b = $this->context->get($bname);
$field['fields'] = array_merge($field['fields'], $b->fields());
}
$value = $call['params'];
if (is_array($value)) {
$filename = $value['context'] . '/' . $value['type'] . YAML_EXT;
$type = $value['type'];
} else {
$filename = 'blueprints://' . $value . YAML_EXT;
$type = $value;
}
if (!is_file($filename)) {
return;
}
$file = CompiledYamlFile::instance($filename);
$blueprint = (new Blueprint($type, $file->content(), $this->context))->init('static');
//$this->embed($field['name'], $blueprint->toArray(), '.', -1);
$this->parseFormFields($blueprint->toArray()['form']['fields'], $this->filter, '', $field['name'].'.', -1, $call['form']);
}
/**