retrofit icon indicating copy to clipboard operation
retrofit copied to clipboard

Allow discovering extensions with legacy `.info` file

Open mglaman opened this issue 1 year ago • 5 comments

This would simplify using Retrofit.

The logic is within \Drupal\Core\Extension\ExtensionDiscovery::scanDirectory:

    foreach ($iterator as $key => $fileinfo) {
      // All extension names in Drupal have to be valid PHP function names due
      // to the module hook architecture.
      if (!preg_match(static::PHP_FUNCTION_PATTERN, $fileinfo->getBasename('.info.yml'))) {
        continue;
      }

It is invoked by \Drupal\Core\Extension\ExtensionDiscovery::scan.

One problem is that ExtensionDiscovery is constructed directly in some cases. But for modules and themes it is constructed and invoked by the ExtensionList class via \Drupal\Core\Extension\ExtensionList::doScanExtensions.

We can decorate extension.list.module and extension.list.theme. The decoration will need to extend the service's class (ModuleExtensionList, ThemeExtensionList.) The method getExtensionDiscovery will need to be overridden to return a new ExtensionDiscovery child class which supports .info discovery.

Then the new class will need to extend \Drupal\Core\Extension\ExtensionDiscovery::scanDirectory to also scan for .info and convert for new .info.yml format.

This could be a major performance issue as it scans the disk twice.

mglaman avatar Jul 18 '23 15:07 mglaman

Also info_parser will need to be decorated as this does the YAML parsing for discovered extensions.

mglaman avatar Jul 18 '23 15:07 mglaman

What is your opinion if we would have Drush command(s) that converts legacy .info and generates the .info.yml files? Something like: ‘$ drush retrofit:init theme’

ndf avatar Oct 03 '23 20:10 ndf

Yes, Drush commands would be the solution here. So you could target an extension and it'd create the file for you.

I paused on this. I probably shouldn't have because it makes it much easier to try out if the command is available. I'll bump my focus on this

mglaman avatar Oct 03 '23 21:10 mglaman

If we are going to scan .info files, I wonder if we can provide auto discovery for class files.

darrenoh avatar Oct 31 '23 13:10 darrenoh

That would be the idea. If we can parse .info then we can include files in files[] automatically.

mglaman avatar Nov 23 '23 20:11 mglaman