Skip to content

Report render array output error in Metadata Display preview #274

@aksm

Description

@aksm

What?

When a render array output is generated via a metadata display template, e.g. {{ data.ia_an_array_dont_uoutput_me }}, the error (see screenshot below) is not reported in the preview.

render_array_error

Todo:

  • Add a report of the KEYS used in the template v/s the JSON (basically a coverage of their use of values (from the source) in the output).
    1. Get all keys on the selected ADO
    2. Check their type (single value, iterable)
    3. Rename them to data.thekeyname in a function
    4. Parse the Twig checking how many times thekeyname is mentioned or attribute(‘thekeyname’, data) and in which lines

See for reference (no longer working due to changed interface):

private function getTwigVariableNames(ModuleNode $nodes): array {
$variables = [];
foreach ($nodes as $node) {
if ($node instanceof \Twig_Node_Expression_Name) {
$name = $node->getAttribute('name');
$variables[$name] = $name;
}
elseif ($node instanceof \Twig_Node_Expression_Constant && $nodes instanceof \Twig_Node_Expression_GetAttr) {
$value = $node->getAttribute('value');
if (!empty($value) && is_string($value)) {
$variables[$value] = $value;
}
}
elseif ($node instanceof \Twig_Node_Expression_GetAttr) {
$path = implode('.', $this->getTwigVariableNames($node));
if (!empty($path)) {
$variables[$path] = $path;
}
}
elseif ($node instanceof \Twig_Node) {
$variables += $this->getTwigVariableNames($node);
}
}
return $variables;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions