Loading core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php +1 −1 Original line number Diff line number Diff line Loading @@ -91,7 +91,7 @@ public function getSortedDefinitions(array $definitions = NULL, $label_key = 'la /** @var \Drupal\Core\Plugin\CategorizingPluginManagerTrait|\Drupal\Component\Plugin\PluginManagerInterface $this */ $definitions = $definitions ?? $this->getDefinitions(); uasort($definitions, function ($a, $b) use ($label_key) { if ($a['category'] != $b['category']) { if ((string) $a['category'] != (string) $b['category']) { return strnatcasecmp($a['category'], $b['category']); } return strnatcasecmp($a[$label_key], $b[$label_key]); Loading core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php +12 −8 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ use Drupal\Tests\UnitTestCase; use Psr\Log\LoggerInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\StringTranslation\StringTranslationTrait; /** * @coversDefaultClass \Drupal\Core\Block\BlockManager Loading @@ -19,6 +20,8 @@ */ class BlockManagerTest extends UnitTestCase { use StringTranslationTrait; /** * The block manager under test. * Loading @@ -42,6 +45,7 @@ protected function setUp(): void { $container = new ContainerBuilder(); $current_user = $this->prophesize(AccountInterface::class); $container->set('current_user', $current_user->reveal()); $container->set('string_translation', $this->getStringTranslationStub()); \Drupal::setContainer($container); $cache_backend = $this->prophesize(CacheBackendInterface::class); Loading @@ -55,22 +59,22 @@ protected function setUp(): void { // that are purposefully not in alphabetical order. $discovery->getDefinitions()->willReturn([ 'broken' => [ 'admin_label' => 'Broken/Missing', 'category' => 'Block', 'admin_label' => $this->t('Broken/Missing'), 'category' => $this->t('Block'), 'class' => Broken::class, 'provider' => 'core', ], 'block1' => [ 'admin_label' => 'Coconut', 'category' => 'Group 2', 'admin_label' => $this->t('Coconut'), 'category' => $this->t('Group 2'), ], 'block2' => [ 'admin_label' => 'Apple', 'category' => 'Group 1', 'admin_label' => $this->t('Apple'), 'category' => $this->t('Group 1'), ], 'block3' => [ 'admin_label' => 'Banana', 'category' => 'Group 2', 'admin_label' => $this->t('Banana'), 'category' => $this->t('Group 2'), ], ]); // Force the discovery object onto the block manager. Loading Loading
core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php +1 −1 Original line number Diff line number Diff line Loading @@ -91,7 +91,7 @@ public function getSortedDefinitions(array $definitions = NULL, $label_key = 'la /** @var \Drupal\Core\Plugin\CategorizingPluginManagerTrait|\Drupal\Component\Plugin\PluginManagerInterface $this */ $definitions = $definitions ?? $this->getDefinitions(); uasort($definitions, function ($a, $b) use ($label_key) { if ($a['category'] != $b['category']) { if ((string) $a['category'] != (string) $b['category']) { return strnatcasecmp($a['category'], $b['category']); } return strnatcasecmp($a[$label_key], $b[$label_key]); Loading
core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php +12 −8 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ use Drupal\Tests\UnitTestCase; use Psr\Log\LoggerInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\StringTranslation\StringTranslationTrait; /** * @coversDefaultClass \Drupal\Core\Block\BlockManager Loading @@ -19,6 +20,8 @@ */ class BlockManagerTest extends UnitTestCase { use StringTranslationTrait; /** * The block manager under test. * Loading @@ -42,6 +45,7 @@ protected function setUp(): void { $container = new ContainerBuilder(); $current_user = $this->prophesize(AccountInterface::class); $container->set('current_user', $current_user->reveal()); $container->set('string_translation', $this->getStringTranslationStub()); \Drupal::setContainer($container); $cache_backend = $this->prophesize(CacheBackendInterface::class); Loading @@ -55,22 +59,22 @@ protected function setUp(): void { // that are purposefully not in alphabetical order. $discovery->getDefinitions()->willReturn([ 'broken' => [ 'admin_label' => 'Broken/Missing', 'category' => 'Block', 'admin_label' => $this->t('Broken/Missing'), 'category' => $this->t('Block'), 'class' => Broken::class, 'provider' => 'core', ], 'block1' => [ 'admin_label' => 'Coconut', 'category' => 'Group 2', 'admin_label' => $this->t('Coconut'), 'category' => $this->t('Group 2'), ], 'block2' => [ 'admin_label' => 'Apple', 'category' => 'Group 1', 'admin_label' => $this->t('Apple'), 'category' => $this->t('Group 1'), ], 'block3' => [ 'admin_label' => 'Banana', 'category' => 'Group 2', 'admin_label' => $this->t('Banana'), 'category' => $this->t('Group 2'), ], ]); // Force the discovery object onto the block manager. Loading