Commit 5a7f9301 authored by webchick's avatar webchick

Issue #2090353 by dawehner: Don't require to put the use statement into plugin classes.

parent f384cbdc
......@@ -7,9 +7,8 @@
namespace Drupal\Component\Plugin\Discovery;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Doctrine\Common\Annotations\SimpleAnnotationReader;
use Drupal\Component\Reflection\MockFileFinder;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Reflection\StaticReflectionParser;
......@@ -35,6 +34,13 @@ class AnnotatedClassDiscovery implements DiscoveryInterface {
*/
protected $pluginDefinitionAnnotationName;
/**
* The doctrine annotation reader.
*
* @var \Doctrine\Common\Annotations\Reader
*/
protected $annotationReader;
/**
* Constructs an AnnotatedClassDiscovery object.
*
......@@ -50,6 +56,23 @@ function __construct($plugin_namespaces = array(), $plugin_definition_annotation
$this->pluginDefinitionAnnotationName = $plugin_definition_annotation_name;
}
/**
* Returns the used doctrine annotation reader.
*
* @return \Doctrine\Common\Annotations\Reader
* The annotation reader.
*/
protected function getAnnotationReader() {
if (!isset($this->annotationReader)) {
$this->annotationReader = new SimpleAnnotationReader();
// Add the namespaces from the main plugin annotation, like @EntityType.
$namespace = substr($this->pluginDefinitionAnnotationName, 0, strrpos($this->pluginDefinitionAnnotationName, '\\'));
$this->annotationReader->addNamespace($namespace);
}
return $this->annotationReader;
}
/**
* Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition().
*/
......@@ -63,10 +86,8 @@ public function getDefinition($plugin_id) {
*/
public function getDefinitions() {
$definitions = array();
$reader = new AnnotationReader();
// Prevent @endlink from being parsed as an annotation.
$reader->addGlobalIgnoredName('endlink');
$reader->addGlobalIgnoredName('file');
$reader = $this->getAnnotationReader();
// Clear the annotation loaders of any previous annotation classes.
AnnotationRegistry::reset();
......
......@@ -54,6 +54,20 @@ function __construct($subdir, \Traversable $root_namespaces, $plugin_definition_
parent::__construct($plugin_namespaces, $plugin_definition_annotation_name);
}
/**
* {@inheritdoc}
*/
protected function getAnnotationReader() {
if (!isset($this->annotationReader)) {
$reader = parent::getAnnotationReader();
// Add the Core annotation classes like @Translation.
$reader->addNamespace('Drupal\Core\Annotation', array(DRUPAL_ROOT . '/core/lib/Drupal/Core/Annotation'));
$this->annotationReader = $reader;
}
return $this->annotationReader;
}
/**
* {@inheritdoc}
*/
......
......@@ -7,8 +7,6 @@
namespace Drupal\contact\Entity;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\EntityNG;
use Drupal\contact\MessageInterface;
......
......@@ -11,8 +11,6 @@
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
......
......@@ -9,8 +9,6 @@
use Drupal\Core\Entity\EntityNG;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Language\Language;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
......
......@@ -7,8 +7,6 @@
namespace Drupal\user\Entity;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\user\RoleInterface;
......
......@@ -10,8 +10,6 @@
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Entity\EntityMalformedException;
use Drupal\Core\Entity\EntityNG;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\user\UserInterface;
/**
......
......@@ -13,8 +13,6 @@
use Drupal\views_ui\ViewUI;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewExecutable;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
/**
* Defines a View configuration entity class.
......
......@@ -10,7 +10,6 @@
use Drupal\Core\Entity\EntityManager;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable;
use Drupal\views\Annotation\ViewsRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......
......@@ -7,9 +7,6 @@
namespace Drupal\views\Plugin\views\style;
use Drupal\views\Annotation\ViewsStyle;
use Drupal\Core\Annotation\Translation;
/**
* Unformatted style plugin to render rows one after another with no
* decorations.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment