Implementing hook_build_defaults_alter according to documentation
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api...
expects 3 arguments after the $build_list, namely
$entity, $view_mode, $entity_langcode
And indeed those three arguments are passed in EntityViewBuilder::viewMultiple
However
Drupal::moduleHandler()->alter function only allows 2 $context args, so the absence of the final arg produces a php warning.

CommentFileSizeAuthor
#3 2557929-3.patch2.65 KBswentel
#2 2557929-2.patch1.87 KBswentel

Comments

matslats created an issue. See original summary.

swentel’s picture

Version: 8.0.0-beta14 » 8.0.x-dev
Status: Active » Needs review
StatusFileSize
new1.87 KB

Hmmm, you're right, so we (probably) don't have any tests for this, but it's kind of useless to be there as you can get the language from the entity, so we can just remove it.

swentel’s picture

StatusFileSize
new2.65 KB

Missed another api documentation

lucastockmann’s picture

Status: Needs review » Needs work

So, I just made a short regex (moduleHandler\(\)->alter\(([^,]+,\s?){2}[^,\) \{]+\)) search over the core and saw that many of our alter methods have more than 2 arguments.
How should we deal with this? - Is there any need to fix this as it's only a warning? Or is there maybe already a meta Issue for this?

In case my questions are obsolete and we already have a solution or an issue for this, the issue can be set back to needs review.

berdir’s picture

Status: Needs work » Closed (duplicate)

$langcode was removed, so this resolved itself.

@lucastockmann: Three arguments is fine. It's one primary argument to be altered + two contexts. You need to look for three or more arguments.