Problem/Motivation

system_sort_modules_by_info_name() is also used to sort themes, and is thus misnamed.

Proposed resolution

Rename the function to system_sort_by_info_name().

Remaining tasks

Discuss whether we should add backwards-compatible, deprecated "wrappers" to help transition to the new function names. See #778346-5: system_sort_modules_by_info_name() is misnamed (which includes a D7 patch using this method) and #1221904: RFC: forwards compatibility in D7 / 'backports' defgroup (for a broader discussion).

If not, the D8 patch can go in by itself.

User interface changes

None.

API changes

system_sort_modules_by_info_name()
will be renamed to:
system_sort_by_info_name()
optionally with backwards-compatible wrappers that make backportable.

Original report by @cwgordon7

system_sort_modules_by_info_name() is also used to sort themes, so perhaps it should be renamed to system_sort_by_info_name()?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pillarsdotnet’s picture

Status: Active » Needs review
FileSize
2.46 KB

Patch.

cwgordon7’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, looks good. This has always bugged me.

Dries’s picture

This looks good but can't be backported to D7. Thus, I'm going to wait a bit with committing it to D8.

catch’s picture

Issue tags: +Needs backport to D7

We could consider adding wrapper functions to D7 when there is a straight switch like this, so that people can make modules 'forwards compatible' to the extent possible. So I'm tagging for backport but that likely needs wider discussion.

xjm’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Needs review
FileSize
2.41 KB

Attached variant would add a backwards-compatible wrapper to promote forwards compatibility. (To the DeLorean!)

This is patterned on the solution in #1174444: Make the _element_validate_* functions in field.module available for all contrib modules to use.

Dropping to 7.x temporarily for testbot.

xjm’s picture

Version: 7.x-dev » 8.x-dev

Patch passed; back to 8.x

Added issue summary.

xjm’s picture

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Adding link to meta issue.

xjm’s picture

xjm’s picture

Reroll of the D8 patch for core/.

kscheirer’s picture

Issue tags: -Needs backport to D7

Status: Needs review » Needs work

The last submitted patch, system_sort_by_info_name-778346-9.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Clarification.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

catch’s picture

Category: Bug report » Task
Priority: Normal » Minor
Issue summary: View changes
Issue tags: +Novice, +Bug Smash Initiative

Still valid, but this is a task. Should also consider whether this should move to the extension system.

sudiptadas19’s picture

Status: Needs work » Needs review
FileSize
3.57 KB

Proposed changes have been addressed. Please review it.

tim.plunkett’s picture

Version: 8.9.x-dev » 9.3.x-dev
Status: Needs review » Needs work
+++ b/core/modules/system/system.module
@@ -1056,7 +1056,7 @@ function system_region_list($theme, $show = REGIONS_ALL) {
-function system_sort_modules_by_info_name($a, $b) {
+function system_sort_by_info_name($a, $b) {

The original function needs to be left as a wrapper around the new one, with deprecation warnings.

vsujeetkumar’s picture

Status: Needs work » Needs review
FileSize
3.96 KB
3.7 KB

Added deprecation warnings with the wrapper function for 9.3.x. As mentioned in #22, Please have a look.

vsujeetkumar’s picture

Fixed the above(#23) issue. Please have a look.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This needs a test of the deprecation, see item #3 in How we deprecate.

vsujeetkumar’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
5.11 KB
1.01 KB

Added test as mentioned in #25.

vikashsoni’s picture

FileSize
96.62 KB

@vsujeetkumar thanks for the patch
patch apply successfully

bnjmnm’s picture

Re #27 @vikashsoni adding a screenshot that shows a patch applies provides zero benefit. In the previous comment, the Drupal test runner automatically confirms a patch applies:

I notice this has been pointed out to you before:

I encourage you to use Slack to work with some of the contributors involved in these issues. We'd be happy to help you find ways to contribute to issues that benefits them and would actually get you credited (providing screenshots of a patch applying does not qualify for issue credit)

daffie’s picture

The patch looks good. Just a little bit more work:

  1. +++ b/core/modules/system/system.module
    @@ -890,9 +890,17 @@ function system_region_list($theme, $show = REGIONS_ALL) {
    - * Array sorting callback; sorts modules by their name.
    + * {@inheritdoc}
    

    I think that this change is wrong. If I am wrong, then where does this method inherit its docblock from?

  2. +++ b/core/modules/system/tests/src/Kernel/SystemDeprecationTest.php
    @@ -0,0 +1,30 @@
    +    foreach (\Drupal::service('extension.list.module')->getAllInstalledInfo() as $module => $info) {
    +      $module_info[$module] = new \stdClass();
    +      $module_info[$module]->info = $info;
    +    }
    

    Could we initialize the array before we start using it by adding: $module_info = [];

  3. +++ b/core/modules/system/system.module
    @@ -890,9 +890,17 @@ function system_region_list($theme, $show = REGIONS_ALL) {
    +  @trigger_error('system_sort_modules_by_info_name() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Implement system_sort_by_info_name() instead. See https://www.drupal.org/project/drupal/issues/778346', E_USER_DEPRECATED);
    
    +++ b/core/modules/system/tests/src/Kernel/SystemDeprecationTest.php
    @@ -0,0 +1,30 @@
    +    $this->expectDeprecation('system_sort_modules_by_info_name() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Implement system_sort_by_info_name() instead. See https://www.drupal.org/project/drupal/issues/778346');
    

    The deprecation message must link to the change record (https://www.drupal.org/node/3225624) not the original issue.

dhirendra.mishra’s picture

Assigned: Unassigned » dhirendra.mishra

let me work on above feedback

dhirendra.mishra’s picture

Status: Needs work » Needs review
FileSize
1.95 KB
5.07 KB

Kindly review the patch.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

catch’s picture

Status: Reviewed & tested by the community » Fixed

There are some possible follow-ups to this:

1. Move it to a utility class or trait out of system.module

2. Inline the logic in the closure in the three places it's used and remove the public function altogether.

At three usages it's a bit borderline which of these is the better option, so going ahead and committing this one.

  • catch committed 16f9ca2 on 9.3.x
    Issue #778346 by vsujeetkumar, xjm, dhirendra.mishra, pillarsdotnet,...
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This is always being used to sort lists of Extension objects. We should add a public static function sort to \Drupal\Core\Extension\Extension and use that instead.

alexpott’s picture

+++ b/core/modules/system/src/Controller/AdminController.php
@@ -50,7 +50,7 @@ public function index() {
       $module_info[$module]->info = $info;
     }
 
-    uasort($module_info, 'system_sort_modules_by_info_name');
+    uasort($module_info, 'system_sort_by_info_name');
     $menu_items = [];

This method should get the installed module list as extensions form \Drupal\Core\Extension\ModuleHandlerInterface::getModuleList() instead of

    $module_info = $this->moduleExtensionList->getAllInstalledInfo();
    foreach ($module_info as $module => $info) {
      $module_info[$module] = new \stdClass();
      $module_info[$module]->info = $info;
    }

Which is really odd code.

alexpott’s picture

Status: Needs work » Fixed

lol funny xpost - I'll open a follow-up when I have a moment.

+++ b/core/modules/system/system.module
@@ -893,6 +893,14 @@ function system_region_list($theme, $show = REGIONS_ALL) {
+/**
+ * Array sorting callback; sorts modules by their name.
+ */
+function system_sort_by_info_name($a, $b) {

If we don't move this to an object then documentation should be improved... the whole point of this change is that this is not only about modules.

alexpott’s picture

Created a follow-up to deal with #35 / #36 / #37...
See #3225779: Provide sort callback on ExtensionList class

Status: Fixed » Closed (fixed)

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