Use CategorizingPluginManagerTrait.
Closes #3474533
Merge request reports
Activity
232 236 return $this->moduleHandler->moduleExists($provider) || $this->themeHandler->themeExists($provider); 233 237 } 234 238 239 /** 240 * {@inheritdoc} 241 */ 242 public function processDefinition(&$definition, $plugin_id): void { 243 parent::processDefinition($definition, $plugin_id); 244 $this->processDefinitionCategory($definition); 245 } 246 247 /** 248 * {@inheritdoc} 249 */ 250 protected function processDefinitionCategory(&$definition): void { 251 $definition['category'] = $definition['group'] ?? $this->t('Other'); I'd have preferred
NULL
, but that'd get in the way of all methods:-
\Drupal\Core\Plugin\CategorizingPluginManagerTrait::getCategories()
would be able to returnNULL
, violating its current API, and is hence a BC break -
\Drupal\Core\Plugin\CategorizingPluginManagerTrait::getSortedDefinitions()
and\Drupal\Component\Plugin\CategorizingPluginManagerInterface::getGroupedDefinitions()
would need very special handling.
IMHO picking some category as the default is pragmatic
, and also the only realistic optionWhich string that should be is excellent bike shedding material!
That being said… I think this default should not live here, but in
\Drupal\Core\Theme\ComponentPluginManager::$defaults
-
You can't call a function or
new
when initialising a class property so we can't use$defaults
. We could do it in the constructor if we have to, but it seems just as easy to do it here.If we don't like this we can do what the parent method does:
// Default to the human readable module name if the provider is a module; // otherwise the provider machine name is used. $definition['category'] = $this->getProviderName($definition['provider']);
ie.
Edited by Dave Long
added 85 commits
-
82a85b72...69dc12e1 - 83 commits from branch
project:11.x
- 12f33905 - Use CategorizingPluginManagerTrait.
- de28f245 - Fix baseline.
-
82a85b72...69dc12e1 - 83 commits from branch
- Resolved by Wim Leers
10780 10780 'count' => 1, 10781 10781 'path' => __DIR__ . '/lib/Drupal/Core/Theme/ComponentPluginManager.php', 10782 10782 ]; 10783 $ignoreErrors[] = [ 10784 // identifier: class.notFound 10785 'message' => '#^Call to method getDefinitions\\(\\) on an unknown class Drupal\\\\Core\\\\Plugin\\\\CategorizingPluginManagerTrait\\.$#', 10786 'count' => 1, 10787 'path' => __DIR__ . '/lib/Drupal/Core/Theme/ComponentPluginManager.php', 10788 ]; 10789 $ignoreErrors[] = [ 10790 // identifier: class.notFound 10791 'message' => '#^Call to method getSortedDefinitions\\(\\) on an unknown class Drupal\\\\Core\\\\Plugin\\\\CategorizingPluginManagerTrait\\.$#', 10792 'count' => 1, 10793 'path' => __DIR__ . '/lib/Drupal/Core/Theme/ComponentPluginManager.php', 10794 ]; 10783 10795 $ignoreErrors[] = [ - Comment on lines +10783 to 10795
Are these changes needed? If I run
vendor/bin/phpstan analyse -c core/phpstan.neon.dist core/lib/Drupal/Core/Theme/ComponentPluginManager.php
locally with this branch checked out I get
------ -------------------------------------------------------------------------------------- Ignored error pattern #^Call to method getDefinitions\(\) on an unknown class Drupal\\Core\\Plugin\\CategorizingPluginManagerTrait\.$# in path /home/rowlands/git/core/drupal/core/lib/Drupal/Core/Theme/ComponentPluginManager.php was not matched in reported errors. Ignored error pattern #^Call to method getSortedDefinitions\(\) on an unknown class Drupal\\Core\\Plugin\\CategorizingPluginManagerTrait\.$# in path /home/rowlands/git/core/drupal/core/lib/Drupal/Core/Theme/ComponentPluginManager.php was not matched in reported errors. ------ --------------------------------------------------------------------------------------
If I revert that change it passes
I see we have a green run here 5 days ago so would be good for someone to confirm this is actually needed?
added 33 commits
-
de28f245...bf6900b7 - 30 commits from branch
project:11.x
- 1170681b - Use CategorizingPluginManagerTrait.
- 4e3c9093 - Fix baseline.
- 30dff34a - Revert change
Toggle commit list-
de28f245...bf6900b7 - 30 commits from branch