Replace deprecated REQUIREMENT_ERROR constant in search_api_db_defaults_requirements() for Drupal 11+ compatibility

Created on 15 July 2025, 8 days ago

Problem/Motivation

The search_api_db_defaults_requirements() function in the search_api_db_defaults module uses the deprecated REQUIREMENT_ERROR constant:

'requirements' => [
  'severity' => REQUIREMENT_ERROR,
]

As of Drupal 11.2.0, this constant is deprecated and will be removed in Drupal 12.0.0:

REQUIREMENT_ERROR is deprecated in drupal:11.2.0 and removed in drupal:12.0.0. Use \Drupal\Core\Extension\Requirement\RequirementSeverity::Error instead.

When running the functional test \Drupal\Tests\search_api_db_defaults\Functional\IntegrationTest::testInstallAndDefaultSetupWorking,
the test fails because the severity level is not correctly interpreted in newer Drupal versions โ€” no error message is printed as expected.
This is due to the conditional check using:
if ($requirement['severity'] === RequirementSeverity::Error)
โ€ฆwhich will not match REQUIREMENT_ERROR (int 2 vs. \RequirementSeverity::Error enum), leading to a silent failure.

Steps to reproduce

Run the test:
--filter=testInstallAndDefaultSetupWorking

Proposed resolution

Update the severity key to use the enum class:

use Drupal\Core\Extension\Requirement\RequirementSeverity;

...

'requirements' => [
  'severity' => RequirementSeverity::Error,
]

This ensures forward compatibility and fixes the test behavior under Drupal 11+.

Remaining tasks

๐Ÿ› Bug report
Status

Active

Version

1.0

Component

Tests

Created by

๐Ÿ‡ช๐Ÿ‡ธSpain tuwebo

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

Comments & Activities

  • Issue created by @tuwebo
  • @tuwebo opened merge request.
  • ๐Ÿ‡ช๐Ÿ‡ธSpain tuwebo

    All tests passed (PHPUnit, PHPCS, PHPStan), but the pipeline shows as failed due to a post-job exit code 1.
    The patch simply replaces the deprecated REQUIREMENT_ERROR with RequirementSeverity::Error, ensuring compatibility with Drupal 11.2+ and 12.x. I think it should be safe to merge it. Moving to Needs review.

Production build 0.71.5 2024