Last active
December 14, 2015 06:28
-
-
Save Berdir/5042373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Definition of Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery. | |
*/ | |
namespace Drupal\Core\Plugin\Discovery; | |
use Drupal\Component\Plugin\Discovery\AnnotatedClassDiscovery as ComponentAnnotatedClassDiscovery; | |
use Drupal\Core\Extension\ModuleHandlerInterface; | |
/** | |
* Defines a discovery mechanism to find annotated plugins in PSR-0 namespaces. | |
*/ | |
class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery { | |
/** | |
* Module handler. | |
* | |
* @var \Drupal\Core\Extension\ModuleHandlerInterface | |
*/ | |
protected $moduleHandler; | |
/** | |
* Constructs an AnnotatedClassDiscovery object. | |
* | |
* @param string $owner | |
* The plugin type owner. | |
* @param string $type | |
* The plugin type name. | |
* @param Drupal\Core\Extension\ModuleHandlerInterfac $module_handler | |
* Module handler | |
* @param array $plugin_namespaces | |
* An array of paths keyed by it's corresponding namespaces. | |
*/ | |
function __construct($owner, $type, ModuleHandlerInterface $module_handler, array $plugin_namespaces = array()) { | |
$this->owner = $owner; | |
$this->type = $type; | |
$this->moduleHandler = $module_handler; | |
$annotation_namespaces = array( | |
'Drupal\Component\Annotation' => DRUPAL_ROOT . '/core/lib', | |
'Drupal\Core\Annotation' => DRUPAL_ROOT . '/core/lib', | |
); | |
parent::__construct($plugin_namespaces, $annotation_namespaces, 'Drupal\Core\Annotation\Plugin'); | |
} | |
/** | |
* Overrides Drupal\Component\Plugin\Discovery\AnnotatedClassDiscovery::getPluginNamespaces(). | |
* | |
* This is overridden rather than set in the constructor, because Drupal | |
* modules can be enabled (and therefore, namespaces registered) during the | |
* lifetime of a plugin manager. | |
*/ | |
protected function getPluginNamespaces() { | |
$plugin_namespaces = parent::getPluginNamespaces(); | |
$plugin_namespaces += array( | |
"Drupal\\Component\\Plugin\\{$this->owner}\\{$this->type}" => array(DRUPAL_ROOT . '/core/lib'), | |
"Drupal\\Core\\Plugin\\{$this->owner}\\{$this->type}" => array(DRUPAL_ROOT . '/core/lib'), | |
); | |
foreach ($this->moduleHandler->getModuleList() as $filename => $module) { | |
$plugin_namespaces["Drupal\\$module\\Plugin\\{$this->owner}\\{$this->type}"] = array(dirname($filename) . '/lib'); | |
} | |
return $plugin_namespaces; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When modules get enabled or disabled, we're invoking DrupalKernel::updateModules()... Perhaps we should/need to trigger an event there?
Recalculating the list on every invocation looks bad to me.