mirror of
https://github.com/getgrav/grav.git
synced 2026-05-06 20:47:10 +02:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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])) {
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user