Problem/Motivation

We want the "Form Mode Manager" module to be ready for Drupal 9, I created a patch to achieve this.

Steps to reproduce

I installed a Drupal 9 site and added this module, and change the requirement in its info.yml file.
I tested this with Node entity, in the near future I'll test this with custom entities.

Proposed resolution

I attached the patch

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

alvarito75 created an issue. See original summary.

alvarito75’s picture

Issue summary: View changes
sahana _n’s picture

Status: Active » Reviewed & tested by the community

The patch applied cleanly.

scott_euser’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5.28 KB
new4.25 KB

This patch no longer applies to 2.x-dev, updated patch, fixes a couple more issues introduced since then.

Tested by enabling the module, adding a form mode, adding that form mode to core article type, updating the form display settings, and then editing an article in the new form mode.

  1. Removes UrlGeneratorTrait https://www.drupal.org/project/drupal/issues/3067198
  2. Updates ConfigurablePluginInterface as per this deprecation https://www.drupal.org/node/2946161
  3. Updates compatibility with abstract class EntityDisplayFormBase which has changed constructor args https://www.drupal.org/node/3087546
  4. Adds Drupal 9 compatibility to info.yml file
scott_euser’s picture

Found one more when manually checking the help pages

segi’s picture

I have started to use patch #5. I found an error on admin/user page "Warning: strpos() expects parameter 1 to be string, object given in Drupal\Component\Utility\UrlHelper::stripDangerousProtocols() (line 358 of /var/www/html/web/core/lib/Drupal/Component/Utility/UrlHelper.php)"
The problem was that the toUrl() gives back an URL object. Here is my fix.

muaz7731’s picture

Tested out the patch from #6. got this:

patch -p1 < form_mode_manager-drupal-9-compatibility-3164478-6.patch
patching file form_mode_manager.info.yml
Hunk #1 FAILED at 2.
1 out of 1 hunk FAILED -- saving rejects to file form_mode_manager.info.yml.rej
patching file src/AbstractEntityFormModesFactory.php
patching file src/ComplexEntityFormModes.php
patching file src/EntityRoutingMapInterface.php
patching file src/Form/FormModeManagerDisplayEditForm.php
patching file src/FormModeManagerPermissions.php

I fix it by tweaking the file form_mode_manager.info.yml to add this below "core : '8.x':

core_version_requirement: ^8 || ^9

Tested out using contrib module Profile, and it works for me.The module that I currently using is form_mode_manager-8.x-2.0-rc3 with Drupal 9.1.3

+1 for RTBC

playful’s picture

Any chance to get a D9 ready release for this module?

muaz7731’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new38.69 KB

The patch #6 works for development build 8.x-2.x-dev

However the submodule does not work for drupal 9. I dont know if the submodule is important or not. I dont use it

https://www.drupal.org/files/issues/2021-03-01/Capture.PNG

I set this as rtbc.

pianomansam’s picture

Status: Reviewed & tested by the community » Needs work

@muaz91 I would think it's inappropriate to set this as RTBC if parts of it are still not working.

drupalviking’s picture

I have now tested it on four different occasions with the 8.x-2.x branch and the patches work for the main module. But there is still the issue of the sub-modules, that have not been patched yet. I will take a look at it and supply a patch for that.

drupalviking’s picture

Status: Needs work » Needs review

I applied the patch #6 to the code plus I added the core_version_requirement directive to each of the three submodules. Please review.

guilhermevp’s picture

Status: Needs review » Needs work
StatusFileSize
new13.83 KB
new89.92 KB

Testing the merge request, module, sub modules and example install as they should, but I came across this error while doing some testing. Not sure if it is related to the new code, or it's an older issue but moving to needs work.

The error happened at admin/config/content/form_mode_manager/theme-switcher .

drupalviking’s picture

@guilhermevp, is there an active theme (installed and set to default) in your test environment? If not, this error comes up.

drupalviking’s picture

Nevermind, I can also generate it. Back to the drawing board.

scott_euser’s picture

Definitely struggled with getting the MR in place sorry. Default UI here from drupal.org created a separate merge request but I wanted to make a MR into your branch since its not open for commits from others.

Ultimately link to it is here:
https://git.drupalcode.org/issue/form_mode_manager-3164478/-/merge_reque...

But drupal.org isn't picking it up.

guilhermevp’s picture

Status: Needs work » Reviewed & tested by the community

I was able to install in D9 and use it as intended. Seems good to me! No more errors in theme as well.

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

dww’s picture

Assigned: Unassigned » dww
Status: Reviewed & tested by the community » Needs work

I just applied the patch from #3140602: Automated Drupal Rector fixes, added it to this MR, and closed that issue as a duplicate.

Also marked #3110961: Make 8.x-1.x compatible with Drupal 9 as a duplicate (even though it was opened much earlier than this one) since the changes in the latest patch over there are already included with this MR. If I were a maintainer, I'd credit https://www.drupal.org/u/ankithashetty here since they worked on the D9 port originally.

Since we've got an MR and issue fork going, I'm also hiding all the patches and screenshots attached here to avoid confusion...

Meanwhile, trying to run this module's full tests against a local 9.2.x dev site, and we get:

Fatal error: Trait 'Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait' not found in /Users/dww/drupal/form_mode_manager/tests/src/Functional/FormModeManagerUiTest.php on line 16

I'll work on fixing that next. Stay tuned. Thanks!

dww’s picture

Okay, the TaxonomyTestTrait fix was pretty simple (b86f1cd) All tests are passing locally on 8.9.x now, although they were generating the following deprecation notices:

  • 29x: Drupal\Tests\BrowserTestBase::$defaultTheme is required in drupal:9.0.0 when using an install profile that does not set a default theme. See https://www.drupal.org/node/3083055, which includes recommendations on which theme to use.
  • 1x: \Drupal\Core\Extension\ThemeHandlerInterface::install() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Extension\ThemeInstallerInterface::install() instead. See https://www.drupal.org/node/3017233
  • 1x: Any entity_reference_autocomplete component of an entity_form_display must have a match_limit setting. The uid field on the node.node_form_mode_example.default form display is missing it. This BC layer will be removed before 9.0.0. See https://www.drupal.org/node/2863188

Pushed another commit to add $defaultTheme (00a8c7cb)

Also moved modules/examples/src/Tests/FormModeManagerExamplesTest.php to modules/examples/tests/src/Functional/FormModeManagerExamplesTest.php (0e8ebd86) and got that one passing on D9 (e546f167 and 622d3d90).

Also fixed "Any entity_reference_autocomplete component of an entity_form_display must have a match_limit setting" via commit 3db4051.

However, trying to run either tests/src/Functional/FormModeManagerRouteTest.php or tests/src/Functional/FormModeManagerUiTest.php is causing phpunit to seg fault. 🎉 Fun! Not sure what's going on there, yet. 😉 Stay tuned.

Would be curious if anyone else can setup a local 9.2.x core test site, checkout the MR branch as a module in that site, then run phpunit locally to try to run the tests directly under D9. Would love to hear about the results.

scott_euser’s picture

StatusFileSize
new153.41 KB

The tests do run for me within DDEV from your merge request

Screenshot of phpunit tests running for Form Mode Manager issue 3164478

I do still get these deprecation notices in the results too though:

Remaining self deprecation notices (39)

  39x: Calling Drupal\Tests\UiHelperTrait::drupalPostForm() with $submit as an object is deprecated in drupal:9.2.0 and the method is removed in drupal:10.0.0. Use $this->submitForm() instead. See https://www.drupal.org/node/3168858
    22x in FormModeManagerRouteTest::testFormModeManagerPlugin from Drupal\Tests\form_mode_manager\Functional
    4x in FormModeManagerRouteTest::testAdminRoutes from Drupal\Tests\form_mode_manager\Functional
    3x in FormModeManagerRouteTest::testListWithTwoFormModeManagerRoutes from Drupal\Tests\form_mode_manager\Functional
    2x in FormModeManagerRouteTest::testAnonymousSpecificFormModeManagerRoutes from Drupal\Tests\form_mode_manager\Functional
    2x in FormModeManagerRouteTest::testAddFormModeManagerRoutes from Drupal\Tests\form_mode_manager\Functional
    2x in FormModeManagerRouteTest::testEditFormModeManagerRoutes from Drupal\Tests\form_mode_manager\Functional
    2x in FormModeManagerRouteTest::testUserEditFormModeManagerRoutes from Drupal\Tests\form_mode_manager\Functional
    2x in FormModeManagerRouteTest::testListWithOneFormModeManagerRoutes from Drupal\Tests\form_mode_manager\Functional
guilhermevp’s picture

Well, I think that updating drupalPostForm() can be solved in a new issue.

dww’s picture

Assigned: dww » Unassigned
Status: Needs work » Needs review
Related issues: +#3208369: drupalPostForm() is deprecated, use $this->submitForm() instead.

Great, thanks!

Initial investigation into the local phpunit seg faults are that my machine is running out of RAM deep inside a very complex preg_replace_common(). I haven't yet had a chance to dig deeper. But it's encouraging that the tests all pass for @scott_euser locally on D9. I'm prepared to chalk this up to my local environment and not the fault of the porting efforts in here. So back to NR and unassigned.

I am curious if the tests in here, or the module code itself, are doing things with preg_replace* that could be optimized to be less resource intensive, but that also seems out of scope for this particular issue.

Completely agreed that #3208369: drupalPostForm() is deprecated, use $this->submitForm() instead. should remain a separate issue. ;) That's only about Drupal 10 compatibility. We've got plenty of time to fix that. Thanks for already opening that one and providing the patch, @guilhermevp!

dww’s picture

Title: Drupal 9 deprecated code removed » Port to Drupal 9 API (remove D8 deprecated code) and declare D9 compatibility
Category: Feature request » Task

Also, I don't think this is a 'feature'. This is more accurately a task. Also, more explicit /accurate title.

dww’s picture

I don't think this is a 'feature', it's more accurately a 'task'. Also, more explicit /accurate title.

dww’s picture

https://www.drupal.org/pift-ci-job/2094540 was complaining about some new code style bugs from the MR (in particular, some unused use statements). I just ran phpcbf from the 9.2.x core site and pushed the results to the MR. Hopefully this next test run will be pretty clean. I don't think we need to completely solve all the CS stuff in here, this is already turning into a fairly big MR.

scott_euser’s picture

Status: Needs review » Reviewed & tested by the community

I'm happy to mark this as RTBC - with the patch from the MR I can successfully use the module from configuration to extending it for a complex use case one of our projects has. Note I have not looked line by line at the code itself though.

Thanks very much for all the work on this!

  • dww committed 0b080b2 on 8.x-2.x
    Issue #3164478 by dww: Define $defaultTheme and move $modules to...
  • dww committed 213f804 on 8.x-2.x
    Issue #3164478 by dww: Add the required 'match_limit' setting to the...
  • dww committed 4254f4d on 8.x-2.x
    Issue #3164478 by dww: Fix additional code style bugs.
    
  • dww committed 6f4de45 on 8.x-2.x
    Issue #3164478 by dww: Really fix the namespace for...
  • dww committed 71ab3f7 on 8.x-2.x
    Issue #3164478 by dww: Fix most code style bugs automatically with...
  • dww committed 7c1a137 on 8.x-2.x
    Issue #3164478 by dww: Define $defaultTheme and move $modules to...
  • dww committed 7fb6816 on 8.x-2.x
    Issue #3164478 by dww: Convert usages of deprecated 'theme_handler'...
  • dww committed 80ad348 on 8.x-2.x
    Issue #3164478 by dww: Move modules/examples/src/Tests/* to modules/...
  • dww committed d4a62fa on 8.x-2.x
    Issue #3164478 by dww: Fix the namespace for FormModeManagerExamplesTest...
  • dww committed f7af7d7 on 8.x-2.x
    Issue #3164478 by dww: Replace deprecated Unicodee:strtolower() (patch...
  • dww committed fabd81a on 8.x-2.x
    Issue #3164478 by dww: Fix namespace for deprecated TaxonomyTestTrait...

dww credited ankithashetty.

dww’s picture

Status: Reviewed & tested by the community » Fixed

#3219216: Offer to co-maintain Form mode manager is fixed and I'm now a co-maintainer. ;)

So I pushed all the commits from the MR into the 8.x-2.x branch. 🎉

I've got a few other things I'd like to land ASAP, then I'll tag a new RC with D9 compatibility. I'll post a link here when the release is out, but calling this fixed for now.

Thanks everyone!
-Derek

dww’s picture

Status: Fixed » Closed (fixed)

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