diff --git a/core/lib/Drupal/Core/Annotation/DrupalAnnotation.php b/core/lib/Drupal/Core/Annotation/DrupalAnnotation.php new file mode 100644 index 0000000..37b0102 --- /dev/null +++ b/core/lib/Drupal/Core/Annotation/DrupalAnnotation.php @@ -0,0 +1,17 @@ + $value) { + if ($value instanceof DrupalAnnotation) { + $this->definition[$key] = $value->get(); + } + else { + $this->definition[$key] = $value; + } + } + } + + /** + * Implements DrupalAnnotation::get(). + */ + public function get() { + return $this->definition; + } +} diff --git a/core/lib/Drupal/Core/Annotation/Translation.php b/core/lib/Drupal/Core/Annotation/Translation.php new file mode 100644 index 0000000..dee3e87 --- /dev/null +++ b/core/lib/Drupal/Core/Annotation/Translation.php @@ -0,0 +1,34 @@ + $values['context'], + ); + } + $this->translation = t($string, array(), $options); + } + + /** + * Implements DrupalAnnotation::get(). + */ + public function get() { + return $this->translation; + } +} diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php new file mode 100644 index 0000000..ec5ce24 --- /dev/null +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -0,0 +1,69 @@ +owner = $owner; + $this->type = $type; + } + + /** + * Implements DiscoveryInterface::getDefinition(). + */ + public function getDefinition($plugin_id) { + $plugins = $this->getDefinitions(); + return isset($plugins[$plugin_id]) ? $plugins[$plugin_id] : array(); + } + + /** + * Implements DiscoveryInterface::getDefinitions(). + */ + public function getDefinitions() { + $definitions = array(); + $reader = new AnnotationReader(); + AnnotationRegistry::registerAutoloadNamespace('Drupal\Core\Annotation', array(DRUPAL_ROOT . '/core/lib')); + $namespaces = drupal_classloader()->getNamespaces(); + foreach ($namespaces as $ns => $namespace_dirs) { + $ns = str_replace('\\', DIRECTORY_SEPARATOR, $ns); + foreach ($namespace_dirs as $dir) { + $prefix = implode(DIRECTORY_SEPARATOR, array( + $ns, + 'Plugin', + $this->owner, + $this->type + )); + $dir .= DIRECTORY_SEPARATOR . $prefix; + if (file_exists($dir)) { + foreach (new DirectoryIterator($dir) as $fileinfo) { + if ($fileinfo->getExtension() == 'php') { + $reflectionClass = new ReflectionClass(str_replace(DIRECTORY_SEPARATOR, '\\', "$prefix/". $fileinfo->getBasename('.php'))); + if ($annotation = $reader->getClassAnnotation($reflectionClass, 'Drupal\Core\Annotation\Plugin')) { + $definition = $annotation->get(); + $definition['class'] = $reflectionClass->name; + $definitions[$definition['plugin_id']] = $definition; + } + } + } + } + } + } + return $definitions; + } +} + diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index e74cbb1..f566ae8 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -801,19 +801,6 @@ function _aggregator_items($count) { } /** - * Implements hook_aggregator_fetch_info(). - */ -function aggregator_aggregator_fetch_info() { - return array( - 'aggregator' => array( - 'class' => 'Drupal\aggregator\Plugin\aggregator\fetcher\DefaultFetcher', - 'title' => t('Default fetcher'), - 'description' => t('Downloads data from a URL using Drupal\'s HTTP request handler.'), - ), - ); -} - -/** * Implements hook_preprocess_HOOK() for block.tpl.php. */ function aggregator_preprocess_block(&$variables) { diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php index ae24934..a95fc33 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php @@ -8,7 +8,7 @@ namespace Drupal\aggregator\Plugin; use Drupal\Component\Plugin\PluginManagerBase; -use Drupal\Core\Plugin\Discovery\HookDiscovery; +use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Component\Plugin\Factory\DefaultFactory; /** @@ -17,7 +17,7 @@ use Drupal\Component\Plugin\Factory\DefaultFactory; class FetcherManager extends PluginManagerBase { public function __construct() { - $this->discovery = new HookDiscovery('aggregator_fetch_info'); + $this->discovery = new AnnotatedClassDiscovery('aggregator', 'fetcher'); $this->factory = new DefaultFactory($this->discovery); } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/fetcher/DefaultFetcher.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/fetcher/DefaultFetcher.php index e4b663b..e1ad377 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/fetcher/DefaultFetcher.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/fetcher/DefaultFetcher.php @@ -8,12 +8,22 @@ namespace Drupal\aggregator\Plugin\aggregator\fetcher; use Drupal\aggregator\Plugin\FetcherInterface; +use Drupal\Core\Annotation\Plugin; +use Drupal\Core\Annotation\Translation; /** * Defines a default fetcher implementation. * * Uses drupal_http_request() to download the feed. */ + +/** + * @Plugin( + * plugin_id = "aggregator", + * title = @Translation("Default fetcher"), + * description = @Translation("Downloads data from a URL using Drupal\'s HTTP request handler.") + * ) + */ class DefaultFetcher implements FetcherInterface { /**