Hide form fields in blueprints by using dynamic property like scope@: object or scope-ignore@: object, right now only Flex sets the scope

This commit is contained in:
Matias Griese
2018-09-27 22:51:35 +03:00
parent b4d4fb900e
commit 9204b87f3a
3 changed files with 32 additions and 1 deletions

View File

@@ -16,7 +16,7 @@
* Added `Grav\Framework\Collection\AbstractIndexCollection` class
* Added `Grav\Framework\Object\ObjectIndex` class
* Added `Grav\Framework\Flex` classes
* Added proper support for hiding form fields in blueprints by using dynamic property like `security@: admin.foobar` to any field
* Added support for hiding form fields in blueprints by using dynamic property like `security@: admin.foobar`, `scope@: object` or `scope-ignore@: object` to any field
1. [](#improved)
* Doctrine filecache is now namespaced with prefix to support purging

View File

@@ -19,9 +19,16 @@ class Blueprint extends BlueprintForm
/** @var string */
protected $context = 'blueprints://';
protected $scope;
/** @var BlueprintSchema */
protected $blueprintSchema;
public function setScope($scope)
{
$this->scope = $scope;
}
/**
* Set default values for field types.
*
@@ -280,6 +287,29 @@ class Blueprint extends BlueprintForm
}
}
/**
* @param array $field
* @param string $property
* @param array $call
*/
protected function dynamicScope(array &$field, $property, array &$call)
{
if ($property && $property !== 'ignore') {
return;
}
$scopes = (array)$call['params'];
$matches = \in_array($this->scope, $scopes, true);
if ($this->scope && $property !== 'ignore') {
$matches = !$matches;
}
if ($matches) {
$this->addPropertyRecursive($field, 'validate', ['ignore' => true]);
return;
}
}
protected function addPropertyRecursive(array &$field, $property, $value)
{
if (\is_array($value) && isset($field[$property]) && \is_array($field[$property])) {

View File

@@ -134,6 +134,7 @@ class FlexDirectory implements FlexAuthorizeInterface
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));