Hi,
I have a custom module that provides regions to Entity View Displays in conjunction with layout module. I am extending the EntityViewDisplayEditForm
class with mine where I add some logic for this. It's like Display Suite does it but more on point/single-purpose.
Anyway, what I have encountered in the past(beta days of D8) was that the tablePreRender
method always ended up in infinite loop so I had to override it in my class. The fix was simple(the same as in the patch). But now with some changes to the FieldUiTable
the method for rendering the table(FieldUiTable::tablePreRender
) is also called from the form
method since the EntityViewDisplayEditForm
uses '#type' => 'field_ui_table'
now. This would mean I would have to override the FieldUiTable element in order to prevent overriding two methods for the same reason.
I had a look at the issue again and the source of my infinite loop is the way the core is processing the rows in the table and how it handles the parents.
The code is:
$regions = $elements['#regions'];
$tree = ['' => ['name' => '', 'children' => []]];
$trees = array_fill_keys(array_keys($regions), $tree);
$parents = [];
$children = Element::children($elements);
$list = array_combine($children, $children);
// Iterate on rows until we can build a known tree path for all of them.
while ($list) {
foreach ($list as $name) {
$row = &$elements[$name];
$parent = $row['parent_wrapper']['parent']['#value'];
// Proceed if parent is known.
if (empty($parent) || isset($parents[$parent])) {
// Grab parent, and remove the row from the next iteration.
$parents[$name] = $parent ? array_merge($parents[$parent], [$parent]) : [];
unset($list[$name]);
...
and the "bug", in my opinion, is the if (empty($parent) || isset($parents[$parent])) {
.
What that does basically is it will process the row/field only if the parent is empty(ie. no "region" is assigned = hidden field) or if the parent/region was already processed. What will happen is that the parent/region will never be processed if it has value since the first condition makes sure this won't happen. So the loop will never fill up the $parents
variable and in my case it will cause infinite loop because my empty region is called 'hidden'.
If I remove that condition completely my form renders just fine and if I disable my module, so the base form is used, it renders fine as well.
So I think in order to make mine, and maybe DS maintainers(or any other contrib module that will fiddle with these forms), life easier I suggest this condition be removed.
Comment | File | Size | Author |
---|---|---|---|
fieldui-tableprerender-parent-fix.patch | 3.21 KB | Anonymous (not verified) | |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedivanjaros created an issue. See original summary.
Comment #2
swentel CreditAttribution: swentel as a volunteer commentedWill have to test with fieldgroup too since that module deals with a lot parenting.
Comment #3
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedComment #8
slydevil CreditAttribution: slydevil commentedI noticed that this only happened when I tried to add a Details group within a Fieldset group. I did not know at the time that the Details groups was a collapsible fieldset. I had to apply a portion of this patch to delete the Details group.
Comment #15
cilefen CreditAttribution: cilefen commented