Declaration of Drupal\entity_information\Routing\RouteSubscriber::getSubscribedEvents() must be compatible with Drupal\Core\Routing\RouteSubscriberBase::getSubscribedEvents(): array

Created on 29 June 2023, over 1 year ago
Updated 4 December 2023, about 1 year ago

Problem/Motivation

When installing this module on a fresh copy of D10 I noticed a fatal PHP error caused by the mismatch between the declaration of ::getSubscribedEvents() in this module and the version of core I'm using.

Steps to reproduce

Install the module on D10

Proposed resolution

Remove Drupal\entity_information\Routing\RouteSubscriber::getSubscribedEvents() and allow it to be inherited from base class.

🐛 Bug report
Status

Closed: cannot reproduce

Version

2.0

Component

Code

Created by

🇳🇴Norway zaporylie

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

Comments & Activities

  • Issue created by @zaporylie
  • Status changed to Needs review over 1 year ago
  • 🇺🇦Ukraine teodorakis

    Here's a patch.

  • 🇮🇳India Akram Khan Cuttack, Odisha

    I reviewed the above patch and it's resolved the issue. Before patch when i try to extend the module it gives fatal error and after applying patch the module enabled successfully. Additionally, I have attached before and after state screenshots for reference.

  • 🇳🇱Netherlands wilfred waltman

    Thanks to you both. I will taak a look at the patch soon.

  • Assigned to wilfred waltman
  • Status changed to Closed: cannot reproduce over 1 year ago
  • 🇳🇱Netherlands wilfred waltman

    I can not reproduce this. Maybe it is fixed by the implemented coding standards fixes

  • I was able to reproduce this error in Drupal 10, looking at the Core RouteSubscriber libraries, adding ":array" in the function declaration solved my problem.

    /**
    * {@inheritdoc}
    */
    public static function getSubscribedEvents(): array {
    $events = parent::getSubscribedEvents();
    $events[RoutingEvents::ALTER] = ['onAlterRoutes', 100];
    return $events;
    }

    I leave the patch in the hands of whoever wants to do it.
    Greetings.

  • 🇩🇪Germany thomaswalther Rhein-Main Area

    I got this error on updating Drupal 9.5.11 to Drupal 10 with composer.

    This is also in other modules, the same file.

    To find all the affected files:
    find ./ -type f -exec grep -Hni "getSubscribedEvents() {" {} \;

    Shell command for 1 file:

    sed -i 's/getSubscribedEvents() {/getSubscribedEvents():array {/g' ./modules/contrib/entity_usage_light/src/Routing/RouteSubscriber.php

Production build 0.71.5 2024