Fix constructors which have incorrectly marked arguments as nullable

Created on 10 October 2024, 4 months ago

Problem/Motivation

We have a number of classes that have nullable arguments in their constructors which would cause fatal errors in case these arguments are actually omitted.

Steps to reproduce

An example from TaxonomyIndexTidEventSeriesDepth:

  public function __construct(array $configuration, $plugin_id, $plugin_definition, VocabularyStorageInterface $vocabulary_storage, TermStorageInterface $term_storage, ?AccountInterface $current_user = NULL, ?EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, EntityFieldManagerInterface $entity_field_manager = NULL, Connection $database) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $vocabulary_storage, $term_storage, $current_user);
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
    $this->entityFieldManager = $entity_field_manager;
    $this->database = $database;
  }

The following arguments are optional but if we would instantiate the class without these arguments we would get fatal errors:

  1. AccountInterface $current_user = NULL: This is passed on to the parent class which requires this to be an account object and would throw a fatal error if it is NULL.
  2. EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL: is required by internal methods such as ::buildExtraOptionsForm() which would fatal if this is NULL.
  3. EntityFieldManagerInterface $entity_field_manager = NULL: is required by internal methods such as ::buildExtraOptionsForm() which would fatal if this is NULL.

Proposed resolution

Audit all of our constructors and ::create() methods to check for invalid nullable arguments.

Since this causes potential B/C breaks if existing code is extending our classes, we should do this in the 3.x branch.

API changes

Constructor signatures will change.

📌 Task
Status

Active

Version

3.0

Component

Recurring Events (Main module)

Created by

🇧🇬Bulgaria pfrenssen Sofia

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024