Fix signature of hook media_library_media_modify_entity_build_defaults_alter()

Created on 28 April 2023, over 1 year ago
Updated 10 September 2024, 19 days ago

Problem/Motivation

The following hook signature is not correct according to Drupal hook definition:
function media_library_media_modify_entity_build_defaults_alter(array &$build, EntityInterface $entity, string $view_mode): void

The last parameter $view_mode must not specify the typehint string:

function hook_entity_build_defaults_alter(array &$build, \Drupal\Core\Entity\EntityInterface $entity, $view_mode) {
}

Reference: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...

Errors are displayed in logs as follows:
[Thu Apr 27 19:43:15.979162 2023] [php:notice] [pid 78223] [client 127.0.0.1:35912] TypeError: media_library_media_modify_entity_build_defaults_alter(): Argument #3 ($view_mode) must be of type string, null given, called

Proposed resolution

Change the hook definition to:
media_library_media_modify_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode): void

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain nicobot Granada

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

Comments & Activities

Production build 0.71.5 2024