Problem/Motivation

When visiting tab "Settings" of a webform, the following error shown up in the browser:

"The website encountered an unexpected error. Please try again later."

Steps to reproduce

1. Install Drupal 10.1.0-rc1 with the standard profile in use.
2. Install module webform 6.2.0-beta6.
3. Visit page http://127.0.0.1/admin/structure/webform/manage/contact/settings (assuming that you have the Drupal site installed locally).
4. Now check "Recent log messages" ( http://127.0.0.1/admin/reports/dblog ). The following record found: "Error: [] operator not supported for strings in Drupal\webform\Utility\WebformDialogHelper::attachLibraries() (line 63 of web/modules/contrib/webform/src/Utility/WebformDialogHelper.php)."

Line 63 of file "WebformDialogHelper.php" contains the following code:

$build['#attached']['library'][] = 'webform/webform.admin.dialog';

Comments

deminy created an issue. See original summary.

jrockowitz’s picture

StatusFileSize
new609 bytes

I am not sure I will be able to replicate the issue but the attached patch should fix it.

jrockowitz’s picture

Status: Active » Needs review
deminy’s picture

Status: Needs review » Needs work

Thanks for taking a look at the issue so quickly. I gave the patch a try but unfortunately the issue still exists. It seems that array field $build['#attached']['library'] already exists as a string (and thus it won't be overidden). Here is a customized change I made:

  public static function attachLibraries(array &$build) {
    $build += ['#attached' => []];
    $build['#attached'] += ['library' => []];
    file_put_contents(__DIR__ . 'log.txt', var_export($build['#attached'], true));
    // ...
  }

The log contains the following:

array (
  'library' => 'core/drupal.dialog.ajax',
)
deminy’s picture

I took a look at Drupal core and noticed the following MR created for issue #2253257 (Use a modal for entity delete operation links):

https://git.drupalcode.org/project/drupal/-/merge_requests/3700/diffs#8d...

And, here is the merged commit for that issue:

https://github.com/drupal/drupal/commit/bab4e14492b807364137f4b4075c86cb...

Hope it helps.

jrockowitz’s picture

StatusFileSize
new690 bytes

That helps a lot.

The below code is a mistake coming from Drupal Core.

        '#attached' => [
          'library' => 'core/drupal.dialog.ajax',
        ],

...it should be...

        '#attached' => [
          'library' => ['core/drupal.dialog.ajax'],
        ],

You should file a new major issue and add a note to #2253257: Use a modal for entity delete operation links.

For now, I can provide a reasonable patch workaround.

biancaradu27’s picture

StatusFileSize
new784 bytes

After applying the patch I get this error Warning: Undefined array key "#attached" in Drupal\webform\Utility\WebformDialogHelper::attachLibraries() (line 64 of modules/contrib/webform/src/Utility/WebformDialogHelper.php). So I added a fix to this patch. My core version is 10.1 and webform "drupal/webform": "^6.2@beta".

jrockowitz’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new690 bytes
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

  • jrockowitz authored 71d184a4 on 6.1.x
    Issue #3367466 by jrockowitz, biancaradu27: Unable To Access Tab...

  • jrockowitz authored 71d184a4 on 6.2.x
    Issue #3367466 by jrockowitz, biancaradu27: Unable To Access Tab...

  • jrockowitz authored 71d184a4 on 6.x
    Issue #3367466 by jrockowitz, biancaradu27: Unable To Access Tab...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.