Problem/Motivation
The REST Entity Display module in Drupal is generating multiple PHP deprecation warnings due to implicitly marking parameters as nullable. These warnings appear under PHP 8.4 and indicate that the module code needs to explicitly declare nullable types to comply with modern PHP standards. This results in log noise and potential compatibility issues with newer PHP versions.
Steps to reproduce
- Install REST Entity Display version 2.0.0 on a Drupal site running PHP 8.4 or higher.
- Enable full error reporting including deprecated notices (e.g.,
error_reporting(E_ALL | E_DEPRECATED)). - Clear the Drupal cache using
drush cr. - Observe the PHP deprecation warnings in the logs or debug output, for example:
- PHP Deprecated: Drupal\rest_entity_display_search_api_opensearch\Plugin\search_api\processor\RestEntityDisplayRenderedItem::getPropertyDefinitions(): Implicitly marking parameter $datasource as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rest_entity_display/rest_entity_display_search_api/src/Plugin/search_api/processor/RestEntityDisplayRenderedItem.php on line 126
- PHP Deprecated: Drupal\rest_entity_display\EntityDisplayManagerInterface::getNormalizedEntityDisplay(): Implicitly marking parameter $langcode as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rest_entity_display/src/EntityDisplayManagerInterface.php on line 29
- PHP Deprecated: Drupal\rest_entity_display\EntityDisplayManagerInterface::getNormalizedEntityDisplay(): Implicitly marking parameter $rendering_context as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rest_entity_display/src/EntityDisplayManagerInterface.php on line 29
Proposed resolution
Update the REST Entity Display module to explicitly declare nullable types (e.g., ?Type) for all affected parameters. This includes:
RestEntityDisplayRenderedItem.php: UpdategetPropertyDefinitions($datasource)to explicitly mark$datasourceas nullable.EntityDisplayManagerInterface.php: UpdategetNormalizedEntityDisplay($langcode, $rendering_context)to explicitly mark$langcodeand$rendering_contextas nullable.
Implementing these changes will remove the deprecation warnings and ensure compatibility with PHP 8.4 and future versions.
Issue fork rest_entity_display-3574571
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
Comment #3
johnatas commentedComment #6
johnatas commentedComment #8
johnatas commented