diff --git a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php index d9c1bc3dd74e2ab1e9cb4e33561204077490ef8c..5648b0dedf5a358e8db6fe46d07bc85f5c893148 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -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(); diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php index e033cafd2a742533de0a11350a66d72438c08182..b66118b05af1455b40c72582fe2732380c47fec9 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -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} */ diff --git a/core/modules/contact/lib/Drupal/contact/Entity/Message.php b/core/modules/contact/lib/Drupal/contact/Entity/Message.php index 0c3c6227b66d0249b8635c5651ac4fda626424e6..f81b456e4dff4aa5e4302d242f5ca373c5e07b84 100644 --- a/core/modules/contact/lib/Drupal/contact/Entity/Message.php +++ b/core/modules/contact/lib/Drupal/contact/Entity/Message.php @@ -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; diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php index f27d051af0e1680a1ff7e31c84609948a5199d75..0fc739aa7db6b761dd42c1ae38eed1d1c62def01 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php @@ -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; diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php index 8367e16a8c8f470cbff2053a91d0c70dee8a3fd9..9071cac594edd9c6bae206c0fee533badffd8bfe 100644 --- a/core/modules/node/lib/Drupal/node/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Entity/Node.php @@ -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; diff --git a/core/modules/user/lib/Drupal/user/Entity/Role.php b/core/modules/user/lib/Drupal/user/Entity/Role.php index 83e4e5ebedfe481c818ebd20492ffbd890b5e5a5..0f8e90e831edc961d52eb012f9064e4face20140 100644 --- a/core/modules/user/lib/Drupal/user/Entity/Role.php +++ b/core/modules/user/lib/Drupal/user/Entity/Role.php @@ -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; diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php index 748c8f1377f5b4cdcb80fb6ca8623fcc7866f95a..d9751771c6d5cf46467a98d51cebf1aa08cd6c57 100644 --- a/core/modules/user/lib/Drupal/user/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Entity/User.php @@ -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; /** diff --git a/core/modules/views/lib/Drupal/views/Entity/View.php b/core/modules/views/lib/Drupal/views/Entity/View.php index e1f9873bcb8c3b25cb611dfa4ba8cddc88810fcb..f5507e60c7c313dd225754f8bae27b5024767144 100644 --- a/core/modules/views/lib/Drupal/views/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Entity/View.php @@ -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. diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/row/EntityRow.php b/core/modules/views/lib/Drupal/views/Plugin/views/row/EntityRow.php index 293d6f6b905efc961c7767c9a622fa67200ad526..8acef0b203f03c2f9c9b19648351d350e72a62b1 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/row/EntityRow.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/row/EntityRow.php @@ -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; /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/style/DefaultStyle.php b/core/modules/views/lib/Drupal/views/Plugin/views/style/DefaultStyle.php index d379cde0ab225f3c20301223aa4a6c40a77ad64b..e315c1c0c0f83a3f0b4add9a453613c202d807b2 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/style/DefaultStyle.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/DefaultStyle.php @@ -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.