- Issue created by @aaronpinero
- Merge request !8replace in_array function with explicit check of term IDs β (Merged) created by aaronpinero
Avoid the potential for fatal error: "nesting level too deep".
in the TaxonomyReplaceService, the function getTermReferenceField() uses the in_array function to check of a Term object exists in an array of Term objects. This can potentially lead to a fatal error. A similar case is described in https://coderwall.com/p/5efmag/if-you-get-a-nesting-level-too-deep-error...
The link above recommends using strict mode for the in_array function, but strict mode just checks the object types. In this case the code in question is used to check if a Term is in an array of Terms. It should suffice to check if the term IDs are the same. The description of the function actually says this:
"Get the name of the term reference field relevant to this term ID"
My recommendation here is to modify the code in TaxonomyReplaceService beginning on line 146, replacing:
if (in_array($term, $referenced_terms)) {
return $field_name;
}
with
foreach ($referenced_terms as $referenced_term) {
if ($referenced_term->id() === $term->id()) {
return $field_name;
}
}
Active
2.0
Code