You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
findBy() returns an array of entities (T[]), but the translation extractor expects a static array literal (an instance of Node\Expr\Array_).
I think the extractor can only analyze static arrays defined directly in the code. It cannot process arrays created dynamically at runtime via method calls like findBy() or helper functions like enumChoicesWithAll().
When the extractor encounters these dynamic calls, it sees a Node\Expr\MethodCall or Node\Expr\FuncCall instead of a static array, which triggers the errors:
Form choice is not an array: The extractor cannot process the dynamically generated choices.
Choice label is not a scalar string: In similar dynamic cases, the extractor is unable to determine the label because it isn’t provided as a static scalar string.
The error is triggered in the following block of code in the translation extractor: FormTypeChoices.php:
} elseif (!$choicesinstanceofNode\Expr\Array_) {
$this->addError($choices, 'Form choice is not an array');
continue;
}
Here, the result of findBy() is treated as a method call (Node\Expr\MethodCall), not as a static array node, which leads to the error.
Form choice is not an array: The extractor cannot process the dynamically generated choices.
Choice label is not a scalar string: In similar dynamic cases, the extractor is unable to determine the label because it isn’t provided as a static scalar string.
Question
I am wondering if there is an alternative approach that would allow the translation extractor to handle dynamic choices without requiring the use of multiple @Ignore annotations. Has anyone encountered a similar issue or found a solution that would let the extractor process dynamically generated arrays (or provide a configurable fallback during extraction)?
Any guidance, suggestions, or workarounds would be greatly appreciated.
Thank you for your time and support!
The text was updated successfully, but these errors were encountered:
Description
When running the translation extractor (
php bin/console translation:extract
), I encounter the following errors:These errors occur in my form types where dynamic choices are generated via function calls. For example, in my
ProductType
form I use:And in another form, I have:
Problem
The issue arises because:
findBy()
returns an array of entities (T[]
), but the translation extractor expects a static array literal (an instance ofNode\Expr\Array_
).findBy()
or helper functions likeenumChoicesWithAll()
.Node\Expr\MethodCall
orNode\Expr\FuncCall
instead of a static array, which triggers the errors:The error is triggered in the following block of code in the translation extractor: FormTypeChoices.php:
Here, the result of
findBy()
is treated as a method call (Node\Expr\MethodCall
), not as a static array node, which leads to the error.Question
I am wondering if there is an alternative approach that would allow the translation extractor to handle dynamic choices without requiring the use of multiple
@Ignore
annotations. Has anyone encountered a similar issue or found a solution that would let the extractor process dynamically generated arrays (or provide a configurable fallback during extraction)?Any guidance, suggestions, or workarounds would be greatly appreciated.
Thank you for your time and support!
The text was updated successfully, but these errors were encountered: