Problem/Motivation

Services have boilerplate code that is being removed throughout Drupal

Proposed resolution

Use constructor property promotion to reduce boilerplate, see https://www.drupal.org/project/drupal/issues/3278431

Remaining tasks

  1. Write a merge request
  2. Review
  3. Commit

User interface changes

None

API changes

None

Data model changes

None

Issue fork domain-3553360

Command icon 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

idebr created an issue. See original summary.

idebr’s picture

Status: Active » Needs review

The merge request implements constructor property promotion to reduce boilerplate

mably made their first commit to this issue’s fork.

idebr’s picture

Controllers that extend ControllerBase cannot promote the properties defined in ControllerBase.

The documentation for ControllerBase suggests it is used for simple cases only, so it might be worth dropping the base class to improve maintainability. Maybe in a follow-up issue?

See ControllerBase docblock: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

* Controllers that use this base class have access to a number of utility
* methods and to the Container, which can greatly reduce boilerplate dependency
* handling code. However, it also makes the class considerably more
* difficult to unit test. Therefore this base class should only be used by
* controller classes that contain only trivial glue code. Controllers that
* contain sufficiently complex logic that it's worth testing should not use
* this base class but use ContainerInjectionInterface instead, or even
* better be refactored to be trivial glue code.

mably’s picture

Ok, let's merge it as is for now 👍

  • mably committed 703d2e45 on 3.x authored by idebr
    Issue #3553360 by idebr: Implement constructor property promotion
    
mably’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

idebr’s picture

A follow-up to remove ControllerBase for complex use cases is available at #3554044: Remove ControllerBase for complex use cases

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.