Problem/Motivation

#2208429: Extension System, Part III: ExtensionList, ModuleExtensionList and ProfileExtensionList makes it possible to deprecate \Drupal\Core\Extension\ModuleHandlerInterface::getName() and replace it with calls to \Drupal::service('extension.list.module')->getName($module)

Proposed resolution

Mark ModuleHandlerInterface::getName() as @deprecated. Include @see for the change record.

Cause ModuleHandler::getName() to @trigger_error(E_USER_DEPRECATED). (Note this is the implementation, not the interface.)

Replace all core usages of ModuleHandler::getName() with ModuleExtensionList::getName(). (I found two in language.module, there are probably others.)

Add a new method \Drupal\Core\Plugin\CategorizingPluginManagerTrait::getModuleExtensionList().

Helpful links on deprecation: https://www.drupal.org/core/deprecation#how-method

Remaining tasks

User interface changes

None

API changes

  • ModuleHandler::getName() is deprecated
  • New method \Drupal\Core\Plugin\CategorizingPluginManagerTrait::getModuleExtensionList() is added

Data model changes

None

CommentFileSizeAuthor
#105 2926070-nr-bot.txt90 bytesneeds-review-queue-bot
#101 2926070-nr-bot.txt90 bytesneeds-review-queue-bot
#95 2926070-95.patch51.98 KBandypost
#85 2926070-85.patch51.93 KBandypost
#85 interdiff.txt20.28 KBandypost
#84 2926070-84.patch52.79 KBandypost
#84 interdiff.txt11.94 KBandypost
#81 2926070-81.patch49.26 KBandypost
#81 interdiff.txt921 bytesandypost
#79 2926070-79.patch49.26 KBandypost
#79 interdiff.txt27.29 KBandypost
#77 2926070-77.patch49.37 KBsmustgrave
#77 interdiff-75-77.txt5.45 KBsmustgrave
#75 2926070-75.patch49.34 KBsmustgrave
#75 interdiff-73-75.txt784 bytessmustgrave
#73 2926070-73.patch49.32 KBsmustgrave
#73 interdiff-71-73.txt2.12 KBsmustgrave
#71 2926070-71.patch49.57 KBsmustgrave
#71 interdiff-69-71.txt1.09 KBsmustgrave
#69 2926070-69.patch50 KBsmustgrave
#69 interdiff-67-69.txt4.03 KBsmustgrave
#67 2926070-67.patch47.88 KBsmustgrave
#67 interdiff-65-67.txt4.33 KBsmustgrave
#65 2926070-65.patch43.93 KBsmustgrave
#65 interdiff-64-65.txt2.06 KBsmustgrave
#64 2926070-64.patch42.16 KBsmustgrave
#64 interdiff-63-64.txt2.06 KBsmustgrave
#63 2926070-63.patch35.94 KBsmustgrave
#63 interdiff-53-63.txt2.06 KBsmustgrave
#53 2926070-53.patch40.64 KBgnuget
#53 2926070-interdiff-50-53.txt3.38 KBgnuget
#50 2926070-50.patch40.9 KBgnuget
#50 2926070-47-50-interdiff.txt3.19 KBgnuget
#47 2926070-46.patch39.87 KBgnuget
#47 2926070-43-46-interdiff.txt1.07 KBgnuget
#43 2926070-43.patch39.47 KBgnuget
#43 2926070-39-43-interdiff.txt825 bytesgnuget
#39 2926070-39.patch39.47 KBgnuget
#39 2926070-36-39-interdiff.txt19.19 KBgnuget
#36 2926070-31-36-interdiff.txt24.08 KBgnuget
#36 2926070-36.patch36.37 KBgnuget
#31 interdiff-2926070-26-31.txt9.41 KBzahord
#31 2926070-31.patch20.11 KBzahord
#29 2926070-29.patch3.1 KBandypost
#26 interdiff-2926070-23-26.txt4.29 KBMerryHamster
#26 2926070-26.patch11.38 KBMerryHamster
#23 2926070-23.patch6.21 KBzahord
#20 interdiff-2926070-18-20.txt664 byteszahord
#20 2926070-20.patch5.49 KBzahord
#18 interdiff-2926070-16-18.txt749 bytesyogeshmpawar
#18 2926070-18.patch4.87 KByogeshmpawar
#16 interdiff-2926070-14-16.txt1.61 KByogeshmpawar
#16 2926070-16.patch4.94 KByogeshmpawar
#14 interdiff-2926070-12-14.txt875 bytesyogeshmpawar
#14 2926070-14.patch4.75 KByogeshmpawar
#12 interdiff-2926070-9-12.txt777 bytesyogeshmpawar
#12 2926070-12.patch4.19 KByogeshmpawar
#9 2926070-9.patch4.15 KBzahord
#6 2926070-6.patch4.88 KBzahord

Issue fork drupal-2926070

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

alexpott created an issue. See original summary.

ioana apetri’s picture

Assigned: Unassigned » ioana apetri

I will work on this.Could you tell me where is specifically used? I cannot see anywhere. Thanks

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mile23’s picture

Issue summary: View changes
Issue tags: +@deprecated

Updated IS with some instructions. Thanks for taking it on, @yo30.

mile23’s picture

Issue summary: View changes
Issue tags: +Needs change record
zahord’s picture

StatusFileSize
new4.88 KB

Hi, I've create a patch with the change after the update of 8.6.x, I hope it works.

zahord’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 6: 2926070-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

zahord’s picture

StatusFileSize
new4.15 KB
zahord’s picture

Status: Needs work » Needs review
mile23’s picture

Status: Needs review » Needs work

Thanks. Looking pretty good except for a few things.

  1. --- a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php
    +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php
    

    Still needs to @trigger_error() in the implementation.

  2. +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php
    @@ -388,6 +388,11 @@ public function getModuleDirectories();
    +   * @see https://www.drupal.org/node/2926070   ¶
    

    Trailing whitespace, and the change record is https://www.drupal.org/node/2709919

yogeshmpawar’s picture

Assigned: ioana apetri » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.19 KB
new777 bytes

Updated patch with changes addressed in comment #11 & also added interdiff.

alexpott’s picture

Status: Needs review » Needs work
yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.75 KB
new875 bytes

Thanks @alexpott for pointing this issue mentioned in comment #11.1, also added an interdiff.

Status: Needs review » Needs work

The last submitted patch, 14: 2926070-14.patch, failed testing. View results

yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.94 KB
new1.61 KB

Few changes in patch & PHPLint error removed.

Status: Needs review » Needs work

The last submitted patch, 16: 2926070-16.patch, failed testing. View results

yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.87 KB
new749 bytes

Sorry, my bad missed one line to remove & added updated patch with an interdiff.

Status: Needs review » Needs work

The last submitted patch, 18: 2926070-18.patch, failed testing. View results

zahord’s picture

StatusFileSize
new5.49 KB
new664 bytes

Added an update in PermissionHandler::getModuleNames()

zahord’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 20: 2926070-20.patch, failed testing. View results

zahord’s picture

StatusFileSize
new6.21 KB
zahord’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

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

MerryHamster’s picture

StatusFileSize
new11.38 KB
new4.29 KB

I hope changes help reduce bugs in tests

MerryHamster’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 26: 2926070-26.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new3.1 KB

Test injection into PermissionHandler

Status: Needs review » Needs work

The last submitted patch, 29: 2926070-29.patch, failed testing. View results

zahord’s picture

StatusFileSize
new20.11 KB
new9.41 KB

Updated to prevent error when PermissionHandlerTest

zahord’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 31: 2926070-31.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gnuget’s picture

Hi @zahord.

Thanks for your patch!

I reviewed the patch and found a few things that need to be fixed before to be ready.

I'm going to work on those later this week unless you wanted to do it :-)

let me know.

David.

  1. +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php
    @@ -389,6 +389,11 @@ public function getModuleDirectories();
    +   * @see https://www.drupal.org/node/2709919
    
    +++ b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php
    @@ -103,7 +103,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
    -      '#title' => $this->t('This link is provided by the @name module. The title and path cannot be edited.', ['@name' => $this->moduleHandler->getName($provider)]),
    +      '#title' => $this->t('This link is provided by the @name module. The title and path cannot be edited.', ['@name' => \Drupal::service('extension.list.module')->getName($provider)]),
         ];
    

    Here the extension.list.module can be injected.

  2. +++ b/core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php
    @@ -49,7 +49,7 @@ protected function getProviderName($provider) {
    -      return $this->getModuleHandler()->getName($provider);
    +      return \Drupal::service('extension.list.module')->getName($provider);
    

    Here the service can't be injected but we might want to emulate what was done with the moduleHandler.

    I mean, create a function called getExtensionListModule.

  3. +++ b/core/modules/breakpoint/src/BreakpointManager.php
    @@ -244,7 +244,7 @@ public function clearCachedDefinitions() {
    -      $label = $this->moduleHandler->getName($group);
    +      $label = \Drupal::service('extension.list.module')->getName($group);
    

    Here the extension.list.module can be injected as well.

  4. +++ b/core/modules/help/src/Controller/HelpController.php
    @@ -114,7 +114,7 @@ public function helpMain() {
    -      $module_name = $this->moduleHandler()->getName($name);
    +      $module_name = \Drupal::service('extension.list.module')->getName($name);
    

    Here we should inject it as well.

  5. +++ b/core/modules/help/src/Plugin/HelpSection/HookHelpSection.php
    @@ -60,7 +60,7 @@ public static function create(ContainerInterface $container, array $configuratio
    -      $title = $this->moduleHandler->getName($module);
    +      $title = \Drupal::service('extension.list.module')->getName($module);
    

    Here as well, it should be injected.

  6. +++ b/core/modules/user/src/Form/UserPermissionsForm.php
    @@ -153,7 +153,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    -          '#markup' => $this->moduleHandler->getName($provider),
    +          '#markup' => \Drupal::service('extension.list.module')->getName($provider),
    

    here as well.

  7. +++ b/core/modules/user/src/Plugin/views/access/Permission.php
    @@ -115,7 +115,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    -      $display_name = $this->moduleHandler->getName($provider);
    +      $display_name = \Drupal::service('extension.list.module')->getName($provider);
    

    Here as well.

  8. +++ b/core/modules/user/src/Plugin/views/field/UserData.php
    @@ -73,7 +73,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    -      $names[$name] = $this->moduleHandler->getName($name);
    +      $names[$name] = \Drupal::service('extension.list.module')->getName($name);
    

    as well.

  9. +++ b/core/modules/user/src/Plugin/views/filter/Permissions.php
    @@ -70,7 +70,7 @@ public function getValueOptions() {
    -        $display_name = $this->moduleHandler->getName($provider);
    +        $display_name = \Drupal::service('extension.list.module')->getName($provider);
    

    Here as well

  10. +++ b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php
    @@ -62,6 +75,11 @@ protected function setUp() {
    +    // Initialize modules ModuleExtensionList object. ¶
    

    Remove this extra space at the end of the line.

gnuget’s picture

Status: Needs work » Needs review
StatusFileSize
new36.37 KB
new24.08 KB

Here my first try.

I removed the moduleHandler in the plugins where it wasn't used anymore.

I used this line to make sure that we removed all the old calls:

grep -HirnE modulehandler\-\>getName .

And I fixed all the points from #35

Status: Needs review » Needs work

The last submitted patch, 36: 2926070-36.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mile23’s picture

+++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php
@@ -747,6 +747,7 @@ public function getModuleDirectories() {
+    @trigger_error('getName($module) is deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Extension\ModuleExtensionList::getName($module). See https://www.drupal.org/node/2709919.', E_USER_DEPRECATED);

Should be __METHOD__ . 'is deprecated....' like you see in parseDependency().

Also, we're up to 8.7.x now, so we have to change that in both of the deprecation messages.

gnuget’s picture

Status: Needs work » Needs review
StatusFileSize
new19.19 KB
new39.47 KB

Hi @Mile23

Thank you for your review.

Ok New patch, I did the following changes:

  • There was a couple uses of the getName in the language.module used directly from the Drupal::service method, so I updated them.
  • removed the classed added at #31 ( TestModuleExtensionList) and instead I mocked the ModuleExtensionList.
  • #38 was addressed
  • I fixed the MenuLinkDefaultFormTest.

And let's see what the bot says at this time :-)

The commands used to check if all the methods were updated are:

grep -Hrin "module_handler.*getName" .
grep -HirnE modulehandler\-\>getName .
andypost’s picture

Status: Needs review » Needs work

Finally green and yay! few things needs work

  1. +++ b/core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php
    @@ -71,6 +71,21 @@ public function getModuleHandler() {
    +    if (isset($this->moduleExtensionList)) {
    +      return $this->moduleExtensionList;
    +    }
    +    return \Drupal::service('extension.list.module');
    

    var never set - use `!isset()` condition to get service to static cache

  2. +++ b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php
    @@ -461,3 +474,7 @@ public function formatPlural($count, $singular, $plural, array $args = [], array
    +
    +if (!defined('DRUPAL_MINIMUM_PHP')) {
    +  define('DRUPAL_MINIMUM_PHP', '5.3.10');
    +}
    
    +++ b/core/tests/Drupal/Tests/Core/Menu/MenuLinkDefaultFormTest.php
    @@ -51,3 +53,7 @@ public function testExtractFormValues() {
    +
    +if (!defined('DRUPAL_MINIMUM_PHP')) {
    +  define('DRUPAL_MINIMUM_PHP', '5.3.10');
    +}
    
    +++ b/core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php
    @@ -151,3 +153,7 @@ public function processDefinition(&$definition, $plugin_id) {
    +
    +if (!defined('DRUPAL_MINIMUM_PHP')) {
    +  define('DRUPAL_MINIMUM_PHP', '5.3.10');
    +}
    

    would be great to add why that added and follow-up to get rid of

tim.plunkett’s picture

Reading through this issue, I understand that we *can* deprecate ModuleHandlerInterface::getName()
But I don't see any discussion of why we should.

The module handler service seems like the perfect place to consult when looking for this information.
Just because it itself has to delegate to another service to find the answer doesn't mean that all module devs should do the same instead.
Additionally, you end up with code like this, where you need TWO separate services injected:

+++ b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php
@@ -65,14 +73,15 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
     $this->moduleHandler = $module_handler;
+    $this->moduleExtensionList = $module_extension_list;

Why do we want to encourage devs to use the extension.list.module service directly?
I think the abstraction of keeping it on the module handler is a good one.

alexpott’s picture

@tim.plunkett I think that #41 is a good point. The one reason that sticks out for me is the ModuleHandler is about handling installed modules, calling their hooks and loading their code.

>>> \Drupal::moduleHandler()->getName('webform_ui');
=> "Webform UI"
>>> \Drupal::moduleHandler()->getModule('webform_ui');
Drupal/Core/Extension/Exception/UnknownExtensionException with message 'The module webform_ui does not exist.'
>>>

The above code is super odd to me.

gnuget’s picture

Status: Needs work » Needs review
StatusFileSize
new825 bytes
new39.47 KB

Thanks for all your comments!

40.1

var never set - use `!isset()` condition to get service to static cache

I almost copied getModuleHandler to create getModuleExtensionList and there the moduleHandler is not set either, and I think that is on purpose because this is a trait, so we cannot know if the class that used this trait defined the var or not, so it tries to check if it is defined and if that is the case then it uses it if not then get the service.

41.2

would be great to add why that added and follow-up to get rid of

I had to define the constant because it is used at Drupal\Core\Extension\ModuleExtensionList::defaults not sure if we can just get rid of it, the same happened with Drupal\Core\Extension\ThemeHandler and at ThemeHandlerTest these constants were defined as well at the end of the tests, and there wasn't added a comment explaining why they were defined there, should I anyway add the comment?

I noticed a small error so I attach a new patch.

I hope this address #42, if you want me to change something anyway let me know and I will provided a new patch.

Thanks again.

David.

alexpott’s picture

Here's one thing that's annoying - it'd be nice if the extension object was more aware...

>>> \Drupal::moduleHandler()->getName('menu_ui');
=> "Menu UI"
>>> \Drupal::moduleHandler()->getModule('menu_ui')->getName();
=> "menu_ui"

¯\_(ツ)_/¯

alexpott’s picture

  1. +++ b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php
    @@ -65,14 +73,15 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
         $this->moduleHandler = $module_handler;
    

    The module handler is not required anymore and should be removed.

  2. +++ b/core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php
    @@ -49,7 +49,7 @@ protected function getProviderName($provider) {
    -      return $this->getModuleHandler()->getName($provider);
    

    We don;t need the module handler code here anymore really. The getting of list and checking if it is there could be achieved with the module list service. We could catch \Drupal\Core\Extension\Exception\UnknownExtensionException instead of getting the list here.

mile23’s picture

+++ b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php
@@ -461,3 +474,7 @@ public function formatPlural($count, $singular, $plural, array $args = [], array
+if (!defined('DRUPAL_MINIMUM_PHP')) {
+  define('DRUPAL_MINIMUM_PHP', '5.3.10');

+++ b/core/tests/Drupal/Tests/Core/Menu/MenuLinkDefaultFormTest.php
@@ -51,3 +53,7 @@ public function testExtractFormValues() {
+if (!defined('DRUPAL_MINIMUM_PHP')) {
+  define('DRUPAL_MINIMUM_PHP', '5.3.10');

+++ b/core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php
@@ -151,3 +153,7 @@ public function processDefinition(&$definition, $plugin_id) {
+if (!defined('DRUPAL_MINIMUM_PHP')) {
+  define('DRUPAL_MINIMUM_PHP', '5.3.10');

Generally, if you're doing this then you're really writing a kernel test and don't know it yet. If we can move the tests to be kernel tests without changing what they're testing, then maybe we should. But if we leave them as unit tests, we should at least mark them as @runTestsInSeparateProcesses so we don't pollute the constant space for other tests. And also add @todo so we can change them in #2908079: Move some of the bootstrap.inc PHP-related constants to \Drupal and deprecate the old versions

gnuget’s picture

StatusFileSize
new1.07 KB
new39.87 KB

Hi AlexPott.

45.1

The module handler is not required anymore and should be removed.

Yes it is used, not by MenuLinkDefaultForm but ViewsMenuLinkForm extends this class and there it is being used at buildConfigurationForm

45.2

Ok, new patch attached (I didn't deleted getModuleHandler() even if it is not used anymore because it is a public function and not sure if I will break the BC if I delete it) this is pretty similar to what I did on #3012962 :-)

almaudoh’s picture

>>> \Drupal::moduleHandler()->getName('webform_ui');
=> "Webform UI"
>>> \Drupal::moduleHandler()->getModule('webform_ui');
Drupal/Core/Extension/Exception/UnknownExtensionException with message 'The module webform_ui does not exist.'
>>>

The above code is super odd to me.

This is actually a bug. The exception should be UninstalledExtensionException. This particular wtf is one of the reasons for deprecating ModuleHandler::getName(). A thing to do here would be to get them to behave the same.

Status: Needs review » Needs work

The last submitted patch, 47: 2926070-46.patch, failed testing. View results

gnuget’s picture

Status: Needs work » Needs review
StatusFileSize
new3.19 KB
new40.9 KB

#46

Generally, if you're doing this then you're really writing a kernel test and don't know it yet. If we can move the tests to be kernel tests without changing what they're testing, then maybe we should

I haven't the expertise to say if we can convert this into a KernelTest, so I will let to someone else decide about that, for now I just added the @todo and the @runTestsInSeparateProcesses in the tests which define the constant.

Also, I fixed the failing test.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php
    @@ -747,6 +747,7 @@ public function getModuleDirectories() {
    +    @trigger_error(__METHOD__ . ' is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Extension\ModuleExtensionList::getName($module). See https://www.drupal.org/node/2709919.', E_USER_DEPRECATED);
    

    I guess at this point we would need to reroll this patch against 8.8.x

  2. +++ b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php
    @@ -461,3 +475,8 @@ public function formatPlural($count, $singular, $plural, array $args = [], array
    +// @todo Remove as part of https://www.drupal.org/node/2908079
    +if (!defined('DRUPAL_MINIMUM_PHP')) {
    +  define('DRUPAL_MINIMUM_PHP', '5.3.10');
    +}
    

    I'm confused, why are we adding a DRUPAL_MINIMUM_PHP which is lower than the real value right now?

gnuget’s picture

Status: Needs work » Needs review
StatusFileSize
new3.38 KB
new40.64 KB

New patch rerolled against 8.8.x

I'm confused, why are we adding a DRUPAL_MINIMUM_PHP which is lower than the real value right now?

No idea, I just updated the patch to use the real value.

larowlan’s picture

Answering @tim.plunkett in #41, there is a hidden circular dependency between the module handler and the extension list.

ExtensionList has module handler injected, and ModuleHandler::getName() refs the extension list.

So this would resolve that. But yeah, there are other ways around that, such as a setModuleExtensionList method on module handler, which we could call from ModuleExtensionList::construct, but that still hides the dependency

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Should this be going into 10?

andypost’s picture

Version: 9.5.x-dev » 10.1.x-dev

Yes, thank you

smustgrave’s picture

StatusFileSize
new2.06 KB
new35.94 KB

Took a shot. Lets see what fails.

smustgrave’s picture

StatusFileSize
new2.06 KB
new42.16 KB

Apologize can't get phpstan working on D10 so if this fails sorry!

smustgrave’s picture

StatusFileSize
new2.06 KB
new43.93 KB

Status: Needs review » Needs work

The last submitted patch, 65: 2926070-65.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new4.33 KB
new47.88 KB

Status: Needs review » Needs work

The last submitted patch, 67: 2926070-67.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new4.03 KB
new50 KB

Status: Needs review » Needs work

The last submitted patch, 69: 2926070-69.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new1.09 KB
new49.57 KB
kim.pepper’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php
    @@ -715,6 +715,7 @@ public function getModuleDirectories() {
    +    @trigger_error(__METHOD__ . ' is deprecated in Drupal 10.1.x and will be removed before Drupal 11.0.0. Use \Drupal\Core\Extension\ModuleExtensionList::getName($module). See https://www.drupal.org/node/2709919.', E_USER_DEPRECATED);
    

    We need a legacy test for this deprecation

  2. +++ b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php
    @@ -400,3 +418,8 @@ public function formatPlural($count, $singular, $plural, array $args = [], array
    +// @todo Remove as part of https://www.drupal.org/node/2908079
    +if (!defined('DRUPAL_MINIMUM_PHP')) {
    +  define('DRUPAL_MINIMUM_PHP', '5.5.9');
    +}
    

    We shouldn't need to do this anymore. See https://www.drupal.org/node/2909361

  3. +++ b/core/tests/Drupal/Tests/Core/Menu/MenuLinkDefaultFormTest.php
    @@ -51,3 +54,8 @@ public function testExtractFormValues() {
    +// @todo Remove as part of https://www.drupal.org/node/2908079
    +if (!defined('DRUPAL_MINIMUM_PHP')) {
    +  define('DRUPAL_MINIMUM_PHP', '5.5.9');
    +}
    

    ditto

  4. +++ b/core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php
    @@ -151,3 +161,8 @@ public function processDefinition(&$definition, $plugin_id) {
    +// @todo Remove as part of https://www.drupal.org/node/2908079
    +if (!defined('DRUPAL_MINIMUM_PHP')) {
    +  define('DRUPAL_MINIMUM_PHP', '5.5.9');
    +}
    

    ditto

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new2.12 KB
new49.32 KB

Addressed #72

kim.pepper’s picture

+++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerTest.php
@@ -26,2 +26,12 @@
+    \Drupal::service('module_handler')->getName('module_test');

We should add an assert here.

smustgrave’s picture

StatusFileSize
new784 bytes
new49.34 KB

Updated based on #74

daffie’s picture

Status: Needs review » Needs work
Issue tags: -Needs change record
  1. +++ b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php
    @@ -60,12 +68,15 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
        * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
    

    With the change from this issue is the module handler service no longer used. It can be properly deprecated. The ViewsMenuLinkForm is extending this class and it is using the module handler service. Therefor in that class the module handler service need to be added.

  2. +++ b/core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php
    @@ -46,13 +47,12 @@ protected function processDefinitionCategory(&$definition) {
    +    catch (UnknownExtensionException $unknownExtensionException) {
    

    Can we change this line to: catch (UnknownExtensionException $e) {

  3. +++ b/core/modules/breakpoint/src/BreakpointManager.php
    @@ -100,9 +110,10 @@ class BreakpointManager extends DefaultPluginManager implements BreakpointManage
    -  public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache_backend, TranslationInterface $string_translation) {
    +  public function __construct(ModuleHandlerInterface $module_handler, ModuleExtensionList $module_extension_list, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache_backend, TranslationInterface $string_translation) {
    

    We add a new service always to the end of the list, not somewhere in the middle. It is easier for classes that are overriding the class we are changing.

  4. +++ b/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php
    @@ -74,13 +74,13 @@ class ReviewForm extends MigrateUpgradeFormBase {
    -  public function __construct(StateInterface $state, MigrationPluginManagerInterface $migration_plugin_manager, PrivateTempStoreFactory $tempstore_private, MigrationState $migrationState, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler = NULL) {
    +  public function __construct(StateInterface $state, MigrationPluginManagerInterface $migration_plugin_manager, PrivateTempStoreFactory $tempstore_private, MigrationState $migrationState, ConfigFactoryInterface $config_factory, ModuleExtensionList $module_extension_list) {
    

    We cannot just remove an exiting service from a class. The problem is that an overridding class might be using the service and when we remove it the overriding will fail. This is a BC break. So module handler service needs to be properly deprecated in this issue.

  5. +++ b/core/modules/user/src/Plugin/views/access/Permission.php
    @@ -55,13 +55,13 @@ class Permission extends AccessPluginBase implements CacheableDependencyInterfac
    -  public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleHandlerInterface $module_handler) {
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleExtensionList $module_extension_list) {
    

    Again we cannot just remove a service. It need to be properly deprecated.

  6. +++ b/core/modules/user/src/Plugin/views/filter/Permissions.php
    @@ -42,14 +42,14 @@ class Permissions extends ManyToOne {
    -  public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleHandlerInterface $module_handler) {
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleExtensionList $module_extension_list) {
    

    Again we cannot just remove a service. It need to be properly deprecated.

  7. I have created a new change record. Please change the links to the new CR (https://www.drupal.org/node/3310017).
smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new5.45 KB
new49.37 KB

Interdiff is missing some changes. I use patchutils and get an error sometimes when the changes are alot.

This patch needed a reroll also

I addressed the points in #76 to best my ability. Could use some feedback on the deprecated service if that was done correctly.

Status: Needs review » Needs work

The last submitted patch, 77: 2926070-77.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new27.29 KB
new49.26 KB

Here's fixes and clean-up

Status: Needs review » Needs work

The last submitted patch, 79: 2926070-79.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new921 bytes
new49.26 KB

Fix broken test

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Applied patch #81

Searched for "Drupal::service('module_handler')->getName" only instance I found was in the test.

Change record appears to list those classes that have been updated with a new argument.

Think this is good.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php
    @@ -46,13 +48,13 @@ protected function processDefinitionCategory(&$definition) {
    -    $list = $this->getModuleHandler()->getModuleList();
    -    // If the module exists, return its human-readable name.
    -    if (isset($list[$provider])) {
    -      return $this->getModuleHandler()->getName($provider);
    +    try {
    +      return $this->getModuleExtensionList()->getName($provider);
    +    }
    +    catch (UnknownExtensionException $e) {
    +      // Otherwise, return the machine name.
    +      return $provider;
         }
    -    // Otherwise, return the machine name.
    -    return $provider;
    

    With these changes \Drupal\Core\Plugin\CategorizingPluginManagerTrait::getModuleHandler is unused so we should deprecate it.

  2. +++ b/core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php
    @@ -70,6 +72,21 @@ public function getModuleHandler() {
    +  /**
    +   * Returns the module extension list used.
    +   *
    +   * @return \Drupal\Core\Extension\ModuleExtensionList
    +   *   The module extension list.
    +   */
    +  public function getModuleExtensionList(): ModuleExtensionList {
    

    Why public? I think the old getModuleHandler() was public by mistake. This doesn't feel like it should be a public method of a plugin manager.

  3. +++ b/core/modules/language/language.module
    --- a/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php
    +++ b/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php
    
    +++ b/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php
    @@ -76,11 +77,17 @@ class ReviewForm extends MigrateUpgradeFormBase {
    -  public function __construct(StateInterface $state, MigrationPluginManagerInterface $migration_plugin_manager, PrivateTempStoreFactory $tempstore_private, MigrationState $migrationState, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) {
    +  public function __construct(StateInterface $state, MigrationPluginManagerInterface $migration_plugin_manager, PrivateTempStoreFactory $tempstore_private, MigrationState $migrationState, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, protected ?ModuleExtensionList $moduleExtensionList = NULL) {
         parent::__construct($config_factory, $migration_plugin_manager, $state, $tempstore_private);
         $this->migrationState = $migrationState;
         $this->moduleHandler = $module_handler;
    +    if ($this->moduleExtensionList === NULL) {
    +      @trigger_error('Calling ' . __METHOD__ . '() without the $moduleExtensionList argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
    +      $this->moduleExtensionList = \Drupal::service('extension.list.module');
    +    }
    

    The module handler can be deprecated here - use a union id ModuleHandlerInterface|ModuleExtensionList $module_handler and the DeprecatedServicePropertyTrait. This is better than doing constructor promotion because it means less change in the future. It does mean you'll have to add the typehinted property the ModuleExtensionList but it means we don't have a NULL argument and we don't have to go about removing the module handler later.

  4. +++ b/core/modules/user/src/Plugin/views/access/Permission.php
    @@ -57,11 +58,17 @@ class Permission extends AccessPluginBase implements CacheableDependencyInterfac
    +   * @param \Drupal\Core\Extension\ModuleExtensionList|null $moduleExtensionList
    +   *   The module extension list.
        */
    -  public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleHandlerInterface $module_handler) {
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleHandlerInterface $module_handler, protected ?ModuleExtensionList $moduleExtensionList = NULL) {
         parent::__construct($configuration, $plugin_id, $plugin_definition);
         $this->permissionHandler = $permission_handler;
         $this->moduleHandler = $module_handler;
    

    We need to deprecate passing in module handler here. We can use a union on the last argument to pass in either a module handler or a module extension list and do the right thing. We can also use the deprecatedServicePropertyTrait to provide BC.

  5. +++ b/core/modules/user/src/Plugin/views/field/UserData.php
    --- a/core/modules/user/src/Plugin/views/filter/Permissions.php
    +++ b/core/modules/user/src/Plugin/views/filter/Permissions.php
    
    +++ b/core/modules/user/src/Plugin/views/filter/Permissions.php
    @@ -44,12 +45,18 @@ class Permissions extends ManyToOne {
    -  public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleHandlerInterface $module_handler) {
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleHandlerInterface $module_handler, protected ?ModuleExtensionList $moduleExtensionList = NULL) {
         parent::__construct($configuration, $plugin_id, $plugin_definition);
     
         $this->permissionHandler = $permission_handler;
         $this->moduleHandler = $module_handler;
    +    if ($this->moduleExtensionList === NULL) {
    +      @trigger_error('Calling ' . __METHOD__ . '() without the $moduleExtensionList argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
    +      $this->moduleExtensionList = \Drupal::service('extension.list.module');
    +    }
    

    Module handler is not longer used... we can use a union and to the same as above here.

andypost’s picture

Status: Needs work » Needs review
Issue tags: +Needs issue summary update
Parent issue: » #2941155: ModuleHandler should not maintain list of installed modules now that ModuleExtensionList exists
StatusFileSize
new11.94 KB
new52.79 KB

I think better to parent the issue to #2941155: ModuleHandler should not maintain list of installed modules now that ModuleExtensionList exists according to #42

needs summary update for newAPI changes at least

Patch to address review #83

andypost’s picture

StatusFileSize
new20.28 KB
new51.93 KB

And re-roll for 10.2 as beta phase + minor clean-up

Status: Needs review » Needs work

The last submitted patch, 85: 2926070-85.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review

Unrelated failure

smustgrave’s picture

Status: Needs review » Needs work

Can't believe we are already in 10.2.

Any idea when a 10.2.x-dev will be opened? This ticket should probably be postponed on that.

But the deprecation looks good.

Moving to NW for the issue summary update you tagged in #84.

kim.pepper’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update

Updated IS.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

IS looks good!

Do we have 10.2 tag?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 85: 2926070-85.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

random

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kim.pepper’s picture

Status: Reviewed & tested by the community » Needs work

Needs a rebase on 11.x

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new51.98 KB
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Reroll looks good

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 95: 2926070-95.patch, failed testing. View results

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

andypost’s picture

Status: Needs work » Reviewed & tested by the community

Thank you for re-roll and updating deprecation to 10.3

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

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

dimitriskr changed the visibility of the branch 11.x to hidden.

dimitriskr’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Updated the versions on the CR

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

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

kim.pepper’s picture

Status: Needs work » Reviewed & tested by the community

Rebased on 11.x. Back to RTBC

catch’s picture

Status: Reviewed & tested by the community » Needs work

Needs another rebase.

andypost’s picture

Status: Needs work » Needs review

Rebased

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems good.

  • catch committed 02bfae8b on 10.3.x
    Issue #2926070 by smustgrave, dimitriskr, andypost, gnuget, zahord,...

  • catch committed 2ab774d6 on 11.x
    Issue #2926070 by smustgrave, dimitriskr, andypost, gnuget, zahord,...
catch’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

chi’s picture

There is something wrong here. ExtensionList is marked as internal. We should not recommend using it in change records.

catch’s picture

From the ExtensionList docs:

therefore there are no guarantees that the
 *   internal implementations including constructor signature and protected
 *   properties / methods will not change over time.

This doesn't apply to the existing public methods.

chi’s picture

As long as it has class level @internal tag the whole class is considered as internal by static analyzers. We might need to move the @internal tag to particular methods in that class.

Status: Fixed » Closed (fixed)

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