Invalid function definition in SchemaNameBase extensions

Created on 8 January 2024, 6 months ago

Problem/Motivation

Some plugins incorrectly extend the SchemaNameBase "form()" function definition, by not declaring the "array" return type:
Fatal error: Declaration of Drupal\schema_recipe\Plugin\metatag\Tag\SchemaRecipeRecipeIngredient::form(array $element = []) must be compatible with Drupal\schema_metatag\Plugin\metatag\Tag\SchemaNameBase::form(array $element = []): array in /var/www/html/docroot/modules/contrib/schema_metatag/schema_recipe/src/Plugin/metatag/Tag/SchemaRecipeRecipeIngredient.php on line 34

Steps to reproduce

On a new/clean project:
Add the module to a project, enable and configure the recipe related schema - fatal error due to "recipeInstructions" and "recipeIngredient" fields plugin definition.

Proposed resolution

Update the "form()" function definition by adding the return type:
public function form(array $element = []) {
to
public function form(array $element = []): array {

πŸ› Bug report
Status

Closed: won't fix

Version

3.0

Component

Code

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

Comments & Activities

Production build 0.69.0 2024