Getting custom code ready for Drupal 12

DevelopmentUpgrading

Drupal 12.0 is, in the words of its release notes, nearly identical to Drupal 11.5 – except that everything deprecated during Drupal 11 is removed and the libraries underneath move to new major versions. For custom code that means two kinds of work: replacing deprecated calls, and adapting to the new libraries. Both can be done while the site is still on Drupal 11, which is the point: the upgrade itself should be boring.

1. Find the deprecations

Start with the Upgrade Status module. Version 5.0.0 (November 2026) supports Drupal 10.4, 11 and 12, and scans your custom modules and themes with PHPStan for code that is deprecated and will be removed. Run it on Drupal 11.5 if you can – it is the version closest to 12, so it reports the most.

Every deprecation message tells you what to use instead and links to a change record. For example, from core in Drupal 12:

node_type_get_names() is deprecated in drupal:11.3.0 and is removed from
drupal:13.0.0. Use \Drupal::service('entity_type.bundle.info')
->getBundleLabels('node') instead.

Note that some deprecations are only removed in Drupal 13. Code that triggers them still runs on 12, but fix them now while you are in the code anyway. Drupal Rector (the palantirnet/drupal-rector package) can rewrite many deprecated calls automatically – check its rules against your code and review every change.

2. The info file

Tell Drupal your module works with 12:

core_version_requirement: ^11 || ^12

Only add ^12 when the module really works there. If the module also has a composer.json, its requirement on drupal/core must allow 12 too – a mismatch between the two is a common reason why Composer refuses a contributed module that drupal.org says is compatible.

3. Hooks

Drupal 12 no longer finds procedural hooks outside the main .module file, and the .module file itself has been deprecated since 11.5. Move hooks into classes with the #[Hook] attribute. The whole process is in Hooks in Drupal 12.

4. Symfony 8

Drupal 12 uses Symfony 8 (8.2 in the release candidate), up from Symfony 7 in Drupal 11. If your code uses Symfony components directly – event subscribers, console commands, HTTP foundation, validators – check Symfony's own upgrade notes for 8.0. Symfony removes what it deprecated in 7.x, so code that runs without Symfony deprecation notices on Drupal 11.5 is in good shape. Composer packages you require that only allow Symfony 6 or 7 will block the upgrade; Drush 13 is the best-known example.

5. Guzzle 8

Drupal 12 ships Guzzle 8. Code that makes HTTP requests through Drupal's http_client service usually keeps working; code that uses Guzzle's internals, middleware or older helper functions needs checking.

6. Constructors in core classes

Many core classes now use constructor property promotion (change record 3635267). If your class extends a core class and overrides its constructor, or sets properties the parent used to declare, it can break: properties may be declared differently, or arguments may have changed. Check every class that extends a core service, form, controller or plugin base class, and prefer dependency injection through create() and your own constructor arguments over copying the parent's.

7. Tests: PHPUnit 12

Core's tests run on PHPUnit 12.5, and PHPUnit 12 no longer reads metadata from doc-comment annotations: @group, @covers, @dataProvider and the rest must be PHP attributes, such as #[Group('mymodule')] and #[DataProvider('provideCases')] (change record 3581981). Also note that Drupal 12 releases no longer include tests. On this site, installed with Composer from 12.0.0-rc1, web/core has no tests folder at all – not even the base classes UnitTestCase and BrowserTestBase that your own tests extend. To run tests, you need core's test code from another source, such as a git checkout of core; see the change record on the 12.0.x change list.

8. JavaScript and front end

  • jQuery 4. Removed jQuery functions (many of the old $.isArray-style helpers) will fail. Check custom JavaScript and the libraries you include.
  • Backbone and Underscore are no longer in core. Code that declares core/backbone or core/underscore as a dependency must bring its own copy or stop using them.
  • HTMX 4. If you used Drupal's HTMX integration, the step from HTMX 2 to 4 is a breaking change (change record 3583674): some attributes are removed, event names change and HX-Trigger becomes HX-Source.
  • CKEditor 5 version 49 changes some styling; custom CKEditor plugins need testing.

9. Modules that left core

If your custom code depends on a module that has left core – Contact, Search, Toolbar, Shortcut, History and others – add the contributed version to your composer.json and to your module's dependencies. See Modules removed from Drupal 12 core.

10. Test the whole thing

Set up a copy of the site on Drupal 12 (or 12.0.0-rc1 before the release), run the database updates and click through the parts your custom code touches. Watch the log under Reports → Recent log messages. The full upgrade procedure is in Upgrading from Drupal 11 to Drupal 12.