prepareAnnotationDefinition example

// Add the Core annotation classes like @Translation.       $reader->addNamespace('Drupal\Core\Annotation');
      $this->annotationReader = $reader;
    }
    return $this->annotationReader;
  }

  /** * {@inheritdoc} */
  protected function prepareAnnotationDefinition(AnnotationInterface $annotation$class) {
    parent::prepareAnnotationDefinition($annotation$class);

    if (!$annotation->getProvider()) {
      $annotation->setProvider($this->getProviderFromNamespace($class));
    }
  }

  /** * Extracts the provider name from a Drupal namespace. * * @param string $namespace * The namespace to extract the provider from. * * @return string|null * The matching provider name, or NULL otherwise. */
$sub_path = $sub_path ? str_replace(DIRECTORY_SEPARATOR, '\\', $sub_path) . '\\' : '';
              $class = $namespace . '\\' . $sub_path . $fileinfo->getBasename('.php');

              // The filename is already known, so there is no need to find the               // file. However, StaticReflectionParser needs a finder, so use a               // mock version.               $finder = MockFileFinder::create($fileinfo->getPathName());
              $parser = new BaseStaticReflectionParser($class$finder, FALSE);

              /** @var \Drupal\Component\Annotation\AnnotationInterface $annotation */
              if ($annotation = $reader->getClassAnnotation($parser->getReflectionClass()$this->pluginDefinitionAnnotationName)) {
                $this->prepareAnnotationDefinition($annotation$class$parser);

                $id = $annotation->getId();
                $content = $annotation->get();
                $definitions[$id] = $content;
                // Explicitly serialize this to create a new object instance.                 $this->fileCache->set($fileinfo->getPathName()['id' => $id, 'content' => serialize($content)]);
              }
              else {
                // Store a NULL object, so the file is not reparsed again.                 $this->fileCache->set($fileinfo->getPathName()[NULL]);
              }
            }
$sub_path = $sub_path ? str_replace(DIRECTORY_SEPARATOR, '\\', $sub_path) . '\\' : '';
              $class = $namespace . '\\' . $sub_path . $fileinfo->getBasename('.php');

              // The filename is already known, so there is no need to find the               // file. However, StaticReflectionParser needs a finder, so use a               // mock version.               $finder = MockFileFinder::create($fileinfo->getPathName());
              $parser = new StaticReflectionParser($class$finder, TRUE);

              /** @var \Drupal\Component\Annotation\AnnotationInterface $annotation */
              if ($annotation = $reader->getClassAnnotation($parser->getReflectionClass()$this->pluginDefinitionAnnotationName)) {
                $this->prepareAnnotationDefinition($annotation$class);

                $id = $annotation->getId();
                $content = $annotation->get();
                $definitions[$id] = $content;
                // Explicitly serialize this to create a new object instance.                 $this->fileCache->set($fileinfo->getPathName()['id' => $id, 'content' => serialize($content)]);
              }
              else {
                // Store a NULL object, so the file is not reparsed again.                 $this->fileCache->set($fileinfo->getPathName()[NULL]);
              }
            }
Home | Imprint | This part of the site doesn't use cookies.