Problem/Motivation

The following are dynamic properties on \Drupal\Core\Extension\Extension

  • base_theme
  • base_themes
  • engine
  • filename
  • incompatible_base
  • incompatible_engine
  • incompatible_module
  • incompatible_php
  • incompatible_region
  • info
  • insufficient_module_permissions
  • is_admin
  • is_default
  • libraries
  • module_dependencies
  • module_dependencies_disabled
  • module_dependencies_list
  • notes
  • operations
  • origin
  • owner
  • pathname
  • prefix
  • required
  • requiredBy
  • requires
  • root
  • schema_version
  • screenshot
  • sort
  • status
  • sub_themes
  • subpath
  • type
  • weight

(see \Drupal\Core\Extension\ModuleHandler::buildModuleDependencies() for example)

Let's add specific getters and setters on the Extension class for better discoverability and documentation.

Steps to reproduce

Proposed resolution

Add getters and setters for missing properties to the Extension class except for Info which is much more complicated.

Remaining tasks

User interface changes

n.a.

API changes

New methods on extension class.

Data model changes

Release notes snippet

Comments

kim.pepper created an issue. See original summary.

kim.pepper’s picture

Issue summary: View changes
kim.pepper’s picture

Status: Active » Needs review
StatusFileSize
new27.86 KB

Initial patch.

kim.pepper’s picture

kim.pepper’s picture

StatusFileSize
new27.79 KB
new14.25 KB

Reverts the twig changes and replaces a few more uses of ->requires.

andypost’s picture

I bet it needs few more properties (used in extension discovery) like weight

See #2024043-63: Add Module, Theme, Profile, and Extension value objects

andypost’s picture

Maybe it makes sense to introduce kinda "third party settings" for extensions objects instead of removed "info" property, ref #3035618: Extension.php code quality: declare info array as public class field

andypost’s picture

Priority: Normal » Major
Issue tags: +PHP 8.2

In a light of PHP 8.2 this looks major blocker as #2024043-63: Add Module, Theme, Profile, and Extension value objects shows tons of deprecations

kim.pepper’s picture

Title: Create methods for dynamic Extension properties » Create getters and setters for dynamic Extension properties
Related issues: +#3035618: Extension.php code quality: declare info array as public class field, +#2721603: ExtensionList cleanup and separation of concerns
andypost’s picture

berdir’s picture

StatusFileSize
new26.84 KB

->origin and ->subpath are additional examples, added by \Drupal\Core\Extension\ExtensionDiscovery::scanDirectory().

Removing the array return type, that's an API change on an interface, we can't do that. And fixed the required check in ModuleListForm. That's requireD, not requires and is a flag if a module is required, this change caused the module install form to attempt to install any module in the system that had any dependencies, which then unsurprisingly blew up badly.

We can't just make them deprecated, they are an API even if not explicitly defined. I guess we need a BC layer with __get/__set(), we could also use that to temporarily throw an exception on any unknown property to find others that will cause issues in PHP 8.2.

berdir’s picture

StatusFileSize
new1.86 KB
andypost’s picture

temporarily throw an exception on any unknown property to find others that will cause issues in PHP 8.2.

not sure it needed as PHP will do that for us

berdir’s picture

> not sure it needed as PHP will do that for us

Yes, but we can't reliable test yet on 8.2. I only meant as part of the process of ensuring that we define all the properties this class needs, not to actually commit it.

kim.pepper’s picture

StatusFileSize
new28.66 KB
new2.06 KB

Added magic methods to trigger deprecations on direct property access and throw an exception if a property is undefined. Lets see how much blows up.

kim.pepper’s picture

StatusFileSize
new28.71 KB
new528 bytes

Added origin, subpath, required as allowed properties.

kim.pepper’s picture

I'm starting to think this issue and #2024043: Add Module, Theme, Profile, and Extension value objects are too closely linked to split apart.

kim.pepper’s picture

StatusFileSize
new49 KB
new23.86 KB

Added a few more properties.

kim.pepper’s picture

StatusFileSize
new51.49 KB
new7.04 KB

Still more missing properties.

andypost’s picture

Thank you! It looks like neverending story so I tend to agree about split a-ka #17

kim.pepper’s picture

StatusFileSize
new52.05 KB
new1.49 KB

Hmm. There is a 'base_theme' property and a 'base_themes' property. 🤔

kim.pepper’s picture

StatusFileSize
new54.71 KB
new4.43 KB

Theme extensions are really a dumping ground. Found the following properties:

  • incompatible_base
  • incompatible_engine
  • incompatible_module
  • incompatible_php
  • incompatible_region
  • insufficient_module_permissions
  • is_admin
  • is_default
  • notes
  • operations
  • screenshot
kim.pepper’s picture

StatusFileSize
new56.42 KB
new8.17 KB

A couple more:

  • module_dependencies_list
  • module_dependencies_disabled

Also made the properties nullable types.

kim.pepper’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 23: 3292759-23.patch, failed testing. View results

kim.pepper’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new57.89 KB
new8.9 KB

OK. so the __get()/__set() magic methods don't get called on public properties. So I'll try protected again and see what breaks.

Also, since we are removing adding any dynamic properties in this patch, I think we can remove ExtensionSerializationTest::testPublicProperties()

I expect we will get a lot of fails due to deprecations.

kim.pepper’s picture

StatusFileSize
new188.15 KB
new148.3 KB

Replaced a load of direct property access with getters / setters.

kim.pepper’s picture

StatusFileSize
new191.79 KB
new7.11 KB

Found a few more direct property access.

kim.pepper’s picture

StatusFileSize
new191.8 KB

Re-roll.

borisson_’s picture

Theme extensions are really a dumping ground. Found the following properties:

Yes, this changed object is huge, and by introducing it now, we're not really designing it correctly I think. Instead of trying to get all this in by 8.2/10.0 would it make more sense to just define them as properties for now?
I'm not sure if the effort to more properly define profiles would also have an impact in having seperate theme/module/profile objects? Or should that be a followup (or even a good idea?)

Looks like the latest patch also has a couple JS failures, but I haven't yet looked at why.

borisson_’s picture

Just read the linked issue #2024043: Add Module, Theme, Profile, and Extension value objects, and agreeing with #17 & #20. If we want to have getters/setters it should all go in as one effort.

berdir’s picture

Note that the Extension class now has the annotation to allow dynamic properties, that's not very pretty but it means that this is no longer a blocker for PHP 8.2 support and we do not need to rush it. I didn't read the other issue just going from the issue title, but +1 to splitting into separate classes so that we can have the methods only where the make sense.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

moshe weitzman’s picture

This would be helpful for Drush's PmCommands to avoid phpstan complaining when accessing $extension->origin

kim.pepper’s picture

We should add a Universal object crate to PHPStan config to suppress this warning until we resolve it.

This came up in another issue somewhere, but I can't seem to find it.

tim.plunkett’s picture

Re #35/#36, adding this to core/phpstan.neon.dist doesn't help contrib modules (since extending core's is a bad practice), but adding it to your own does help.

  universalObjectCratesClasses:
    - Drupal\Core\Extension\Extension

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.