The trimmed version (crucial for this issue) of \Drupal\Core\Render\Element\Weight::processWeight()
looks the following:
if ($element['#delta'] <= $max_elements) {
$element['#type'] = 'select';
$element += $element_info_manager->getInfo('select');
}
else {
$element['#type'] = 'number';
$element += $element_info_manager->getInfo('number');
}
Now imagine the case when $element['#delta']
exceeds system.site.weight_select_max
so the weight
element gets transformed to input[type=number]
instead of select
. The important part of that transformation is \Drupal\Core\Render\Element\Number::preRenderNumber()
, that is declared as one of the #pre_render
callbacks for number
.
However, the next hook may prevent input[type=number]
from being rendered at all and users will see undefined inputs without any attributes (i.e. <input />
):
function multiversion_element_info_alter(array &$types) {
foreach ($types as &$type) {
if (!isset($type['#pre_render'])) {
$type['#pre_render'] = [];
}
$type['#pre_render'][] = 'multiversion_element_pre_render';
}
}
* The code above has actually been taken from the multiversion module.
The described behavior is caused by the array concatenation ($element += $element_info_manager->getInfo('number');
) that adds only the values the keys of which are missing in the initial array.
Comment | File | Size | Author |
---|---|---|---|
#15 | interdiff-2979044-9-15.txt | 1.85 KB | BR0kEN |
#15 | 2979044-15.patch | 6.41 KB | BR0kEN |
Comments
Comment #2
BR0kENTests to expose the problem.
Comment #3
BR0kENThe attempt to adjust the behavior to normal.
Comment #6
BR0kENAnother try.
Comment #7
BR0kENComment #8
BR0kENComment #9
BR0kENComment #10
mitsuroseba CreditAttribution: mitsuroseba for FFW commentedIs it a good idea to use only one condition, and move those lines after it
Like
if ($element['#delta'] <= $max_elements) {
...
}
else {...}
then
$element = array_merge($element, \Drupal::service('element_info')->getInfo($type));
$element['#type'] = $type;
Comment #12
BR0kENHere is the patch for Drupal 8.4.x (without tests). Might be needed for some projects.
Comment #13
l0ke#10 is more of a style question.
I opt for #9 to be RTBC, it is a good and pretty solution of the problem. Thanks @BR0kEN!
Comment #14
alexpottIs this change necessary? Hopefully not because a lot of render items do this. Well it seems it might be - https://3v4l.org/JKNf8 - but this is a separate issue no? Not actually necessary to fix the bug here is it?
Placing this on multiple lines is very confusing for a ternary. If we're using a ternary I think it should be on one line. The comments can go on the line before.
If that's the case can we limit the change to that because it makes it way easier to review.
Comment #15
BR0kENComment #17
l0keI think all points from #14 have been addressed.
Comment #18
rosinegrean CreditAttribution: rosinegrean at PitechPlus commentedComment #19
alexpottCommitted and pushed d90d0ebbda to 8.8.x and d77f9a680e to 8.7.x. Thanks!
Fixed up some comments on commit.