Skip to content
Snippets Groups Projects

Use CategorizingPluginManagerTrait.

Closes #3474533

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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');
  • Why we choose Other among other values? Should not it be Undefined or Missing?

    Also, in case of missing definition for category, why not to log it or put a warning?
    Fully correct definitions should always contain a group, so it will help us to trace such issues better.

  • I'd have preferred NULL, but that'd get in the way of all methods:

    • \Drupal\Core\Plugin\CategorizingPluginManagerTrait::getCategories() would be able to return NULL, 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 :thumbsup:, and also the only realistic option :sweat_smile:

    Which string that should be is excellent bike shedding material! :smile:

    That being said… I think this default should not live here, but in \Drupal\Core\Theme\ComponentPluginManager::$defaults :innocent:

  • Author Maintainer

    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.

    Suggested change
    251 $definition['category'] = $definition['group'] ?? $this->t('Other');
    251 $definition['category'] = $definition['group'] ?? $this->getProviderName($definition['provider']);
    Edited by Dave Long
  • Fair point!

    No more concerns from me then.

    :white_check_mark:

  • Please register or sign in to reply
  • Wim Leers requested changes

    requested changes

  • Dave Long added 85 commits

    added 85 commits

    Compare with previous version

  • Florent Torregrosa
  • Lee Rowlands resolved all threads

    resolved all threads

  • 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?

    • Please register or sign in to reply
  • Lee Rowlands added 33 commits

    added 33 commits

    Compare with previous version

  • closed

  • Please register or sign in to reply
    Loading