You are here

protected function AnnotatedClassDiscovery::getAnnotationReader in Typed Data API enhancements 8

Gets the used doctrine annotation reader.

Return value

\Doctrine\Common\Annotations\Reader The annotation reader.

Overrides AnnotatedClassDiscovery::getAnnotationReader

File

src/Context/AnnotatedClassDiscovery.php, line 19

Class

AnnotatedClassDiscovery
Extends the annotation class discovery for usage with Typed Data context.

Namespace

Drupal\typed_data\Context

Code

protected function getAnnotationReader() {
  if (!isset($this->annotationReader)) {

    // Do not call out the parent, but re-configure the simple annotation
    // reader on our own, so we can control the order of namespaces.
    $this->annotationReader = new SimpleAnnotationReader();

    // Make sure to add our namespace first, so our ContextDefinition and
    // Condition annotations gets picked.
    $this->annotationReader
      ->addNamespace('Drupal\\typed_data\\Context\\Annotation');

    // Add the namespaces from the main plugin annotation, like @EntityType.
    $namespace = mb_substr($this->pluginDefinitionAnnotationName, 0, mb_strrpos($this->pluginDefinitionAnnotationName, '\\'));
    $this->annotationReader
      ->addNamespace($namespace);

    // Add general core annotations like @Translation.
    $this->annotationReader
      ->addNamespace('Drupal\\Core\\Annotation');
  }
  return $this->annotationReader;
}