Problem/Motivation

Drupal Core sets dynamic properties on Extension and Theme objects during discovery, when building extension lists, and when resolving dependencies. In some cases, their availability depends on where the object comes from.

As a result, IDEs cannot reliably suggest these properties or infer their types. And PHPStan reports valid accesses as undefined property errors unless covered by baseline exceptions.

Background

When #2188661: Extension System, Part II: ExtensionDiscovery introduced Extension for filesystem discovery, other parts of core already added information to discovered objects. In comment #51, @sun described these dynamically added properties as an existing problem to address once the new discovery code was in place.

In preparation for PHP 8.2, #3299853: Apply #[\AllowDynamicProperties] attribute to base classes to make PHP 8.2 log size sane added #[\AllowDynamicProperties] to Extension. The attribute allows dynamic properties at runtime but leaves their names and types unspecified.

#2024043: Add Module, Theme, Profile, and Extension value objects documents the properties that Core uses today and discusses how these objects should represent extension data in the longer term. Comments #52 and #57 discussed whether properties such as $requires, $required_by, and $sort belong on Extension or on more specific classes.

#3015812: Introduce new Theme extension object and properly deprecate REGIONS_VISIBLE and REGIONS_ALL introduced Theme as a subclass of Extension.

In comment #46, @alexpott linked #3026232: Deprecate Theme extension object public properties as the follow-up to deprecate direct access to public theme properties, and in comment #48, he proposed adding getters as those accesses are deprecated.

Later in the same issue, comment #147 revisited properties such as $base_themes and $sub_themes. Computing those relationships requires the full theme list. The issue kept that work in ThemeExtensionList and left further changes to the object model for later.

Proposed resolution

Add @property tags for 29 existing dynamic properties on Extension and Theme so IDEs and PHPStan recognize the properties and their types.

Document the Theme return type of ThemeExtensionList::getList() and use it in ConfigImportSubscriber so PHPStan recognizes theme-specific properties.

For each property, document what it represents, which method sets it, when it is available, and its internal status under Drupal's BC policy, to leave further decisions to #2024043: Add Module, Theme, Profile, and Extension value objects and #3026232: Deprecate Theme extension object public properties.

Remove the corresponding PHPStan baseline entries.

Remaining tasks

Review.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

n/a

Issue fork drupal-3640019

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

pancho created an issue. See original summary.

nicxvan’s picture

Status: Active » Closed (duplicate)
Related issues: +#3635205: Add property annotations for Extension

This is a duplicate of #3635205: Add property annotations for Extension which is already rtbc.

Thanks!

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.

pancho’s picture