comparison core/modules/field_layout/src/FieldLayoutBuilder.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
65 if ($layout_definition && $fields = $this->getFields($build, $display, 'view')) { 65 if ($layout_definition && $fields = $this->getFields($build, $display, 'view')) {
66 // Add the regions to the $build in the correct order. 66 // Add the regions to the $build in the correct order.
67 $regions = array_fill_keys($layout_definition->getRegionNames(), []); 67 $regions = array_fill_keys($layout_definition->getRegionNames(), []);
68 68
69 foreach ($fields as $name => $field) { 69 foreach ($fields as $name => $field) {
70 // Move the field from the top-level of $build into a region-specific 70 // If the region is controlled by the layout, move the field from the
71 // section. 71 // top-level of $build into a region-specific section. Custom regions
72 // could be set by other code at run-time; these should be ignored.
72 // @todo Ideally the array structure would remain unchanged, see 73 // @todo Ideally the array structure would remain unchanged, see
73 // https://www.drupal.org/node/2846393. 74 // https://www.drupal.org/node/2846393.
74 $regions[$field['region']][$name] = $build[$name]; 75 if (isset($regions[$field['region']])) {
75 unset($build[$name]); 76 $regions[$field['region']][$name] = $build[$name];
77 unset($build[$name]);
78 }
76 } 79 }
77 // Ensure this will not conflict with any existing array elements by 80 // Ensure this will not conflict with any existing array elements by
78 // prefixing with an underscore. 81 // prefixing with an underscore.
79 $build['_field_layout'] = $display->getLayout()->build($regions); 82 $build['_field_layout'] = $display->getLayout()->build($regions);
80 } 83 }
101 foreach ($fields as $name => $field) { 104 foreach ($fields as $name => $field) {
102 // As this is a form, #group can be used to relocate the fields. This 105 // As this is a form, #group can be used to relocate the fields. This
103 // avoids breaking hook_form_alter() implementations by not actually 106 // avoids breaking hook_form_alter() implementations by not actually
104 // moving the field in the form structure. If a #group is already set, 107 // moving the field in the form structure. If a #group is already set,
105 // do not overwrite it. 108 // do not overwrite it.
106 if (!isset($build[$name]['#group'])) { 109 if (isset($regions[$field['region']]) && !isset($build[$name]['#group'])) {
107 $build[$name]['#group'] = $field['region']; 110 $build[$name]['#group'] = $field['region'];
108 } 111 }
109 } 112 }
110 // Ensure this will not conflict with any existing array elements by 113 // Ensure this will not conflict with any existing array elements by
111 // prefixing with an underscore. 114 // prefixing with an underscore.