InvalidArgumentException: The allowed types parameter is required and must be an array of strings. in Drupal\media_library\MediaLibraryState->validateRequiredParameters() (line 150 of core/modules/media_library/src/MediaLibraryState.php).

Created on 4 July 2024, 12 months ago

Problem/Motivation

"The website encountered an unexpected error. Try again later.

InvalidArgumentException: The allowed types parameter is required and must be an array of strings. in Drupal\media_library\MediaLibraryState->validateRequiredParameters() (line 150 of core/modules/media_library/src/MediaLibraryState.php)."

Sharing SS:

After Deleting all Media types, I am getting this error on the home page & content page as an admin, except for admin pages...

Steps to reproduce

1. Delete all media types from admin>structure>media.
2. Go back to the home page or any content page.

Proposed resolution

Fix the issue in validateRequiredParameters()

๐Ÿ› Bug report
Status

Active

Version

10.2 โœจ

Component
Mediaย  โ†’

Last updated about 4 hours ago

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia sourav_paul Kolkata

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @sourav_paul
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourav_paul Kolkata
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    Fixes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies. Also, 10.2 is in security mode now.

  • Does this bug require the sitestudio_page_builder module to reproduce? It is installed on that site. Itโ€™s in the stack trace. But itโ€™s not in the steps to reproduce.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourav_paul Kolkata

    @cilefen site studio is not required to reproduce the issue....

  • Status changed to Postponed: needs info 12 months ago
  • I can't reproduce this by building a reference site on https://simplytest.me so the steps to reproduce this need refining.

  • Issue was unassigned.
  • Status changed to Active 12 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourav_paul Kolkata
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourav_paul Kolkata
  • First commit to issue fork.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia vinmayiswamy

    Hi, I followed the steps outlined in the issue summary to reproduce this issue in Drupal 10.2.8-dev (cloned from 10.2.x), using MySQL 5.7 (as MySQL 5.8 is unsupported in DDEV for arm64 architecture. Please see the error below for reference) and PHP 8.3.

    $ ddev config --database=mysql:5.8
    You are reconfiguring the project at /Users/vinmayi.nidubrolu/projects/drupal102x/drupal.
    The existing configuration will be updated and replaced.
    Configuring a 'drupal' project named 'drupal102x' with docroot '' at '/Users/vinmayi.nidubrolu/projects/drupal102x/drupal'.
    For full details use 'ddev describe'.
    failed to validate config: the drupal102x project has an unsupported database type/version: 'mysql:5.8', DDEV arm64 only supports the following database types and versions: mariadb: [10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.11], mysql: [5.7 8.0], postgres: [9 10 11 12 13 14 15 16]
    

    However, I am not able to reproduce the issue.

    After deleting all media types as described, I revisited the nodes created with the content type that included the media field. The nodes rendered without any issues, and there were no relevant entries in the "Recent log messages."

    Additionally, I checked the same scenario in Drupal 11.x with PHP 8.3 and MariaDB 10.11, and I still couldn't reproduce the issue.

    It seems that this issue may not be reproducible in my current environment. Kindly please let me know if there are any additional steps or configurations that I might have missed that could help in replicating the problem.

    Thanks!

  • Status changed to Postponed: needs info 10 months ago
  • Status changed to Active 3 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia rajeshreeputra Pune

    Steps to reproduce:
    Install site with minimal profile
    Install media_library, ckeditor5, field_ui module
    Visit admin/config/content/formats/add to create new editor.
    Add title New Editor
    Select Text editor as CKEditor5
    Add DrupalMedia in Toolbar as shown in Screenshot.
    Update account settings at admin/config/people/accounts/fields
    click Create a new field
    Select Formatted text
    Add label Bio
    Select Text (formatted, long)
    Click Continue

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mausolos

    Confirming #12, similar behavior (I did the same steps basically but out of order).

    You can also reproduce on any mature website by simply deleting all the media types and then attempting to either load an existing full text field or trying to add a new full text field to a content type.

    For a clean/new site, if you go to:
    ~/admin/structure/media

    You will see:
    No media types available. Add media type.

    If you see that, then you will be able to reproduce the error, because:
    ~Line 149-157 of core\modules\media_library\src\MediaLibraryState.php:

        // The allowed media type IDs must be an array of non-empty strings.
        if (empty($allowed_media_type_ids) || !is_array($allowed_media_type_ids)) {
          throw new \InvalidArgumentException('The allowed types parameter is required and must be an array of strings.');
        }
        foreach ($allowed_media_type_ids as $allowed_media_type_id) {
          if (!is_string($allowed_media_type_id) || empty(trim($allowed_media_type_id))) {
            throw new \InvalidArgumentException('The allowed types parameter is required and must be an array of strings.');
          }
        } 
    

    What's even more irksome is that you can first have created the content type and the full text field, THEN add the DrupalMedia button, and then receive this error simply by going back to edit the field you already created.

    The workaround for now appears to be to add a media type.

    The proper user experience ought to be something like a warning, prompting you to create a media type.

  • This bug report will be improved by someone putting the corrected steps to reproduce into this issue summary and removing the โ€œneeds steps to reproduceโ€ tag.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia JatinGupta40

    I tried with the #12 steps and everything seems to be working fine for me.
    There is no error on console or anywhere else.

Production build 0.71.5 2024