- Issue created by @useernamee
- @useernamee opened merge request.
- Status changed to Needs review
almost 2 years ago 10:52am 14 June 2023
When editing a field settings on a content type that uses shs widget in form display this error is shown (due to default value field):
Error message
Warning: Undefined array key "#attached" in Drupal\shs\Plugin\Field\FieldWidget\OptionsShsWidget::afterBuild() (line 270 of modules/contrib/shs/src/Plugin/Field/FieldWidget/OptionsShsWidget.php).
Drupal\shs\Plugin\Field\FieldWidget\OptionsShsWidget::afterBuild(Array, Object)
call_user_func_array(Array, Array) (Line: 1083)
We could use null coalescing operator \Drupal\shs\Plugin\Field\FieldWidget\OptionsShsWidget::afterBuild
instead of ternary operator.
$element['#attached'] = $element['#attached'] ?? [];
$element['#attached'] = array_merge($element['#attached'], [
'drupalSettings' => [
'shs' => [
$element_key => $element['#shs'],
],
],
]);
Needs review
2.0
Code