Skip to content

Commit

Permalink
Added support for flex-ignore@ to hide all the nested fields in the…
Browse files Browse the repository at this point in the history
… blueprint
  • Loading branch information
mahagr committed Sep 2, 2022
1 parent dbca0b4 commit 3f10c05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

1. [](#new)
* Added `authorize-*@:` support for Flex blueprints, e.g. `authorize-disabled@: not delete` disables the field if user does not have access to delete object
* Added support for `flex-ignore@` to hide all the nested fields in the blueprint

# v1.7.35
## 08/04/2022
Expand Down
8 changes: 4 additions & 4 deletions system/src/Grav/Common/Data/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ protected function dynamicSecurity(array &$field, $property, array &$call)
$success = $this->resolveActions($user, $actions);
}
if (!$success) {
$this->addPropertyRecursive($field, 'validate', ['ignore' => true]);
static::addPropertyRecursive($field, 'validate', ['ignore' => true]);
}
}

Expand Down Expand Up @@ -566,7 +566,7 @@ protected function dynamicScope(array &$field, $property, array &$call)
}

if ($matches) {
$this->addPropertyRecursive($field, 'validate', ['ignore' => true]);
static::addPropertyRecursive($field, 'validate', ['ignore' => true]);
return;
}
}
Expand All @@ -577,7 +577,7 @@ protected function dynamicScope(array &$field, $property, array &$call)
* @param mixed $value
* @return void
*/
protected function addPropertyRecursive(array &$field, $property, $value)
public static function addPropertyRecursive(array &$field, $property, $value)
{
if (is_array($value) && isset($field[$property]) && is_array($field[$property])) {
$field[$property] = array_merge_recursive($field[$property], $value);
Expand All @@ -587,7 +587,7 @@ protected function addPropertyRecursive(array &$field, $property, $value)

if (!empty($field['fields'])) {
foreach ($field['fields'] as $key => &$child) {
$this->addPropertyRecursive($child, $property, $value);
static::addPropertyRecursive($child, $property, $value);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion system/src/Grav/Framework/Flex/FlexDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,13 @@ protected function dynamicFlexField(array &$field, $property, array $call): void
if (is_array($value) && isset($field[$property]) && is_array($field[$property])) {
$value = $this->mergeArrays($field[$property], $value);
}
$field[$property] = $not ? !$value : $value;
$value = $not ? !$value : $value;

if ($property === 'ignore' && $value) {
Blueprint::addPropertyRecursive($field, 'validate', ['ignore' => true]);
} else {
$field[$property] = $value;
}
}
}

Expand Down

0 comments on commit 3f10c05

Please sign in to comment.