Problem/Motivation
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)
Proposed resolution
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'],
],
],
]);
Comments
Comment #3
useernamee commentedProviding a patch.
Comment #4
useernamee commentedComment #6
deimos commentedI resolved merge-conflict in MR and providing updated patch.