Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report render array output error in Metadata Display preview #274

Closed
aksm opened this issue Feb 17, 2023 · 1 comment
Closed

Report render array output error in Metadata Display preview #274

aksm opened this issue Feb 17, 2023 · 1 comment
Assignees
Labels
Custom Entities enhancement New feature or request metadata Meta(l) data Twig Twig template processing
Milestone

Comments

@aksm
Copy link
Contributor

aksm commented Feb 17, 2023

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;
}

@DiegoPino DiegoPino added enhancement New feature or request Twig Twig template processing metadata Meta(l) data Custom Entities labels Feb 17, 2023
@DiegoPino DiegoPino added this to the 1.1.0 milestone Feb 17, 2023
@DiegoPino
Copy link
Member

Solved for main preview via #274
@aksm we need an issue that matches this one on AMI!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Custom Entities enhancement New feature or request metadata Meta(l) data Twig Twig template processing
Projects
None yet
Development

No branches or pull requests

2 participants