Problem/Motivation

Saw this deprecation notice while working on my module. Cheers!

1) /app/web/core/lib/Drupal/Core/Hook/HookCollectorPass.php:513
smart_date_module_implements_alter without a #[LegacyModuleImplementsAlter] attribute is deprecated in drupal:11.2.0 and removed in drupal:12.0.0. See https://www.drupal.org/node/3496788
Triggered by:

* Drupal\Tests\date_ap_style\Functional\DateRangeFormatterTest::testDateRangeFormatterWithToSeparator (2 times)
  /usr/local/date_ap_style/tests/src/Functional/DateRangeFormatterTest.php:165

Steps to reproduce

Run phpunit tests locally with deprecations turned on.

Proposed resolution

Follow steps on https://www.drupal.org/node/3496788

Remaining tasks

User interface changes

API changes

Data model changes

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:

Issue fork smart_date-3557723

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

trackleft2 created an issue. See original summary.

trackleft2’s picture

Project: AP Style Date » Smart Date
Version: 3.0.x-dev » 4.2.x-dev
trackleft2’s picture

Issue summary: View changes
ritarshi_chakraborty’s picture

Working on it.

ritarshi_chakraborty’s picture

Status: Active » Needs review

The Drupal\Core\Hook\Attribute\LegacyModuleImplementsAlter attribute class does exist but it seems like PHPStan does not scan or autoload it automatically.

trackleft2’s picture

Status: Needs review » Needs work

Thanks for taking this on, please add a note to remove the entire function once the minimum supported version of Drupal for the module is 11.2 or greater and link to the change record as well. https://www.drupal.org/node/3496788

Additionally, according to the instructions in the linked change record, step 1 is "Achieve the same functionality as your hook_module_implements_alter. Dynamic ordering is currently not supported."

The current state of the merge request seems to only address step #2
"Add the #[LegacyModuleImplementsAlter] to your implementation of hook_module_implements_alter. Once the minimum supported version of Drupal for the module is 11.2 or larger you may delete the entire function and attribute."

In my opinion we should change the scope of this issue to "Modernize Smart Date’s hooks to use Drupal 11’s attribute-based system" otherwise, the changes in the merge request are solely there to hide deprecation notices, which is probably not what we want.

If you agree please update the issue title to "Modernize Smart Date’s hooks to use Drupal 11’s attribute-based system"

See https://www.md-systems.ch/de/blog/2025-10-19/converting-legacy-hooks
See https://git.drupalcode.org/project/smart_date/-/blob/4.2.x/smart_date.to...
See https://git.drupalcode.org/project/smart_date/-/blob/4.2.x/smart_date.vi...

I believe this would involve adding the LegacyHook attribute to existing hooks, and creating new OOP Hook implementations for each existing hook.

Possible example

use Drupal\Core\Hook\Attribute\LegacyHook;
use Drupal\smart_date\Hook\SmartDateTokenHooks;
use Drupal\Core\Render\BubbleableMetadata;

/**
 * Shim for older Drupal versions (10.1–11.0).
 *
 * @phpstan-ignore-next-line
 */
#[LegacyHook]
function smart_date_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  return \Drupal::service(SmartDateTokenHooks::class)
    ->tokens($type, $tokens, $data, $options, $bubbleable_metadata);
}

Alternatively we can create a new issue to modernize and block this one with that one.

ritarshi_chakraborty’s picture

Hey @trackleft2, do you want me to make the changes here or on a new issue ticket?