Improve blueprint initialization in Flex Objects (fixes content aware fields)

This commit is contained in:
Matias Griese
2019-09-20 11:59:13 +03:00
parent 248c7764f0
commit 4e9d3395e0
4 changed files with 24 additions and 17 deletions

View File

@@ -1,3 +1,9 @@
# v1.7.0-beta.9
## mm/dd/2019
1. [](#bugfix)
* Improve blueprint initialization in Flex Objects (fixes content aware fields)
# v1.7.0-beta.8
## 09/19/2019

View File

@@ -1307,7 +1307,7 @@ class Pages
return;
}
$this->grav['debugger']->addMessage('Page cache missed, rebuilding pages..');
$this->grav['debugger']->addMessage('Page cache missed, rebuilding Flex Pages..');
$root = $this->buildRootPage();
$root_path = $root->path();

View File

@@ -44,8 +44,6 @@ class FlexDirectory implements FlexAuthorizeInterface
protected $blueprint_file;
/** @var Blueprint[] */
protected $blueprints;
/** @var bool[] */
protected $blueprints_init;
/** @var FlexIndexInterface|null */
protected $index;
/** @var FlexCollectionInterface|null */
@@ -154,25 +152,18 @@ class FlexDirectory implements FlexAuthorizeInterface
}
/**
* Returns a new uninitialized instance of blueprint.
*
* Always use $object->getBlueprint() or $object->getForm()->getBlueprint() instead.
*
* @param string $type
* @param string $context
* @return Blueprint
* @internal
*/
public function getBlueprint(string $type = '', string $context = '')
{
$blueprint = $this->getBlueprintInternal($type, $context);
if (empty($this->blueprints_init[$type])) {
$this->blueprints_init[$type] = true;
$blueprint->setScope('object');
$blueprint->init();
if (empty($blueprint->fields())) {
throw new RuntimeException(sprintf('Flex: Blueprint for %s is missing', $this->type));
}
}
return $blueprint;
return clone $this->getBlueprintInternal($type, $context);
}
/**

View File

@@ -731,12 +731,22 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
*/
public function getBlueprint(string $name = '')
{
$blueprint = clone $this->_flexDirectory->getBlueprint($name ? '.' . $name : $name);
$blueprint = $this->doGetBlueprint($name);
$blueprint->setScope('object');
$blueprint->setObject($this);
return $blueprint->init();
}
/**
* @param string $name
* @return Blueprint
*/
protected function doGetBlueprint(string $name = ''): Blueprint
{
return $this->_flexDirectory->getBlueprint($name ? '.' . $name : $name);
}
/**
* {@inheritdoc}
* @see FlexObjectInterface::getForm()