Drupal 10 was released on 14 December 2022. Let's make this module D10-compatible!

Callouts:
- This module uses jquery.once, which is removed in D10. Change the library requirement and update the actual JS (note that there is also an npm/gulp build that needs to be run.
- The automated tests need to be refactored to use a different theme, such as Olivero
- The automated tests include integration with Webform. This test may need to be reworked to be compliant with Webform 6.2.x

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

levmyshkin created an issue. See original summary.

levmyshkin’s picture

Here is a patch for .info.yml file

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

mark_fullmer’s picture

Status: Active » Needs work

There are some additional elements that need to be addressed for this to be D10 compatible. I added some updates to the test syntax. The remaining item there would be to replace the usage of jQuery in media_library.form-element.js with Drupal core equivalents (i.e., standalone core/once).

Additionally, this module provides integration with Webform, which does not yet have a D10 release (it's close: #3262067: [META] Make Webform compatible with Drupal 10. I was able to functionally test this using the staged changes in Webform and everything looks good, but automated tests won't pass on drupal.org until Webform has a D10-compatible release.

Setting this to "Needs work" for the jQuery conversion.

levmyshkin’s picture

Hi mark_fullmer, I replaced jQuery once with javascript once in 3304993-drupal-10-support branch. Unfortunately Webform module is still not available for Drupal 10:
https://www.drupal.org/project/webform/issues/3262067#comment-14819666

Also I changed core_version_requirement to ^9.2 || ^10, becuase javascript once() was added only in 9.2 Drupal core:
https://www.drupal.org/node/3158256

levmyshkin’s picture

Status: Needs work » Needs review
mark_fullmer’s picture

StatusFileSize
new259.73 KB

Also I changed core_version_requirement to ^9.2 || ^10, becuase javascript once() was added only in 9.2 Drupal core

Thanks for this!

Unfortunately Webform module is still not available for Drupal 10

For the purposes of the test integration, I think it will be acceptable to retrieve the 6.2.x branch, which is nominally D10 compatible, and on which the media_library_form_element tests pass, with no deprecation warnings.

I replaced jQuery once with javascript once in 3304993-drupal-10-support branch.

Woohoo! I ran the JS build script to write these changes to the JS file that is actually referenced by the library in https://git.drupalcode.org/project/media_library_form_element/-/merge_re...

Attaching a patch to demonstrate test coverage, and leaving as "Needs review" so someone else can verify the work.

mark_fullmer’s picture

Issue summary: View changes

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

rajab natshah’s picture

Priority: Normal » Major
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Tested this using the upgrade status and all issues have been addressed.

Once this is merged could there be a release as this is a block for bootstrap_styles + bootstrap_layout_builder.

phenaproxima’s picture

  1. +++ b/tests/src/FunctionalJavascript/SingleItemTest.php
    @@ -58,12 +58,12 @@ class SingleItemTest extends MediaLibraryTestBase {
    -  protected $defaultTheme = 'classy';
    +  protected $defaultTheme = 'olivero';
    

    It would be better to change this test to use Stark, but that's out of scope here.

  2. +++ b/tests/src/FunctionalJavascript/SingleItemTest.php
    @@ -230,6 +230,7 @@ class SingleItemTest extends MediaLibraryTestBase {
    +    $this->getSession()->resizeWindow(1200, 5000);
    

    Why is this added?

mark_fullmer’s picture

It would be better to change this test to use Stark, but that's out of scope here.

Agreed on both counts -- Stark would be better, but since the existing tests expect certain CSS classes to be present, I was trying to change as little as possible to keep the scope at D10 compatibility.

$this->getSession()->resizeWindow(1200, 5000);

The switch to Olivero caused the visibility of elements within the Media Library to go off-screen, due to differences in CSS margins. The test failure was, as I recall, "Element not clickable at this point." Making the screen width in the test bigger ensures that all elements in the Media Library are visible. The other method I'm aware of for handling this is to use JS to scroll the item into view a la something like the below code, but again, I was rying to change as little as possible.

   $script = "document.evaluate('" . $selector . "', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView();";
    $this->getSession()->executeScript($script);
    $assert->waitForElementVisible('xpath', $selector, $this->getTimeout());
phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed

Okay, makes sense to me. Thanks, @mark_fullmer.

Nothing else really raised a red flag, and tests appear to be passing on Drupal 9 and 10. Not sure I have anything to complain about, so I've committed and pushed to 2.x. Thanks everyone!

mark_fullmer’s picture

Status: Fixed » Active
StatusFileSize
new538 bytes

I notice that the final commit does not include the accessCheck to the media query suggested in https://www.drupal.org/project/media_library_form_element/issues/3304993.... Is this not needed?

levmyshkin’s picture

I added accessCheck() before to avoid warnings in PHP Unit, but it looks like we don't force to use it anymore:
https://www.drupal.org/node/3201242#comment-14650219

I have ran tests for PHP init in media_library_form_element without accessCheck() and it didn't show any warnings. So I think we can remove accessCheck() for now or set it accessCheck(FALSE).

mark_fullmer’s picture

I think we should add accessCheck(FALSE), taking the statement from the change notice at its word:

For Drupal 10 this will be enforced by throwing an exception if ::accessCheck() is not called.

levmyshkin’s picture

Hi mark_fullmer, I'm confusing how to add changes in current git branches for this ticket. I will attach a patch for accessCheck(FALSE) here.

mark_fullmer’s picture

Status: Active » Reviewed & tested by the community

The patch in #19 looks good. Note that this change is present in the getTestValues() method, which is implementing an expected method from WebFormElementBase (https://git.drupalcode.org/project/webform/-/blob/6.1.x/src/Plugin/Webfo...), but that it is only used in the context of testing.

levmyshkin’s picture

Hi mark_fullmer, thank you! Do you have access to merge pull requests and release new Media Library Form API Element version with Drupal 10 support?

mark_fullmer’s picture

Status: Reviewed & tested by the community » Fixed

I have commit access but I don't have the ability to cut a release. I've committed the change and marked this issue as fixed.

Since this is a pro-forma change that only affects (theoretical) testing, I don't think it's necessary to get it into a release immediately for people trying to use this with D10.

Thanks, levmyshkin!

Status: Fixed » Closed (fixed)

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