mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-02-24 15:41:23 +01:00
fix for #2236 + add new |nested filter
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
# v1.8.13
|
||||
## mm/dd/2018
|
||||
|
||||
1. [](#new)
|
||||
* Added new `|nested()` Twig filter to access array objects with dot notation syntax
|
||||
1. [](#bugfix)
|
||||
* Fixed issue with complex lists structure and nested dot-notation [#2236](https://github.com/getgrav/grav/issues/2236)
|
||||
|
||||
# v1.8.12
|
||||
## 10/24/2018
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ class AdminTwigExtension extends \Twig_Extension
|
||||
new \Twig_SimpleFilter('toYaml', [$this, 'toYamlFilter']),
|
||||
new \Twig_SimpleFilter('fromYaml', [$this, 'fromYamlFilter']),
|
||||
new \Twig_SimpleFilter('adminNicetime', [$this, 'adminNicetimeFilter']),
|
||||
new \Twig_SimpleFilter('nested', [$this, 'nestedFilter']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -42,6 +43,23 @@ class AdminTwigExtension extends \Twig_Extension
|
||||
];
|
||||
}
|
||||
|
||||
public function nestedFilter($current, $name)
|
||||
{
|
||||
$path = explode('.', trim($name, '.'));
|
||||
|
||||
foreach ($path as $field) {
|
||||
if (is_object($current) && isset($current->{$field})) {
|
||||
$current = $current->{$field};
|
||||
} elseif (is_array($current) && isset($current[$field])) {
|
||||
$current = $current[$field];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
public function cloneFunc($obj)
|
||||
{
|
||||
return clone $obj;
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
{% set childName = itemName -%}
|
||||
{%- elseif childName starts with '.' -%}
|
||||
{% set childKey = childName|trim('.') %}
|
||||
{% set childValue = val[childName[1:]] %}
|
||||
{% set childValue = val|nested(childName) %}
|
||||
{% set childName = itemName ~ childName %}
|
||||
{% else %}
|
||||
{% set childKey = childName %}
|
||||
|
||||
Reference in New Issue
Block a user