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'],
        ],
      ],
    ]);

Issue fork shs-3366543

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

useernamee created an issue. See original summary.

useernamee’s picture

StatusFileSize
new773 bytes

Providing a patch.

useernamee’s picture

Status: Active » Needs review

deimos made their first commit to this issue’s fork.

deimos’s picture

StatusFileSize
new785 bytes

I resolved merge-conflict in MR and providing updated patch.