From 299594bd3991c2da2cfcd4bbe22e81a7dd5ab60d Mon Sep 17 00:00:00 2001 From: Fabien Antoine Date: Thu, 17 Jul 2014 17:50:51 +0200 Subject: [PATCH] Fixed translation extractor to extract all groups --- ...umnTitleAnnotationTranslationExtractor.php | 62 ++++++++++++++++--- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/Translation/ColumnTitleAnnotationTranslationExtractor.php b/Translation/ColumnTitleAnnotationTranslationExtractor.php index 5b0dc7cd..738c656a 100644 --- a/Translation/ColumnTitleAnnotationTranslationExtractor.php +++ b/Translation/ColumnTitleAnnotationTranslationExtractor.php @@ -6,6 +6,8 @@ use APY\DataGridBundle\Grid\Mapping\Driver\Annotation; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; +use APY\DataGridBundle\Grid\Mapping\Source; +use APY\DataGridBundle\Grid\Mapping\Column; use JMS\TranslationBundle\Model\FileSource; use JMS\TranslationBundle\Model\Message; @@ -58,18 +60,60 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar $annotationDriver = new Annotation(new DoctrineAnnotationReader()); $manager = new Manager(); $manager->addDriver($annotationDriver, -1); - $metadata = $manager->getMetadata($this->parsedClassName); - - // Save messages for title - foreach ($metadata->getFields() as $field) { - $mappedField = $metadata->getFieldMapping($field); - if ((! isset($mappedField['visible']) || $mappedField['visible']) && isset($mappedField['title'])) { - $message = new Message($mappedField['title']); - $message->addSource(new FileSource((string) $file)); - $catalogue->add($message); + + // Get all available groups + $groups = $this->extractGroups(); + foreach ($groups as $group) { + $metadata = $manager->getMetadata($this->parsedClassName, $group); + + // Save messages for title + foreach ($metadata->getFields() as $field) { + $mappedField = $metadata->getFieldMapping($field); + if ((! isset($mappedField['visible']) || $mappedField['visible']) && isset($mappedField['title'])) { + $message = new Message($mappedField['title']); + $message->addSource(new FileSource((string) $file)); + $catalogue->add($message); + } + } + } + } + } + + /** + * Extract available grid groups in the current class + * @return array + */ + protected function extractGroups() + { + $reader = new DoctrineAnnotationReader(); + $groups = array('default'); + + $reflectionCollection = array(); + + $reflectionCollection[] = $reflection = new \ReflectionClass($this->parsedClassName); + while (false !== $reflection = $reflection->getParentClass()) { + $reflectionCollection[] = $reflection; + } + + while (!empty($reflectionCollection)) { + $reflection = array_pop($reflectionCollection); + + foreach ($reader->getClassAnnotations($reflection) as $class) { + if ($class instanceof Source) { + $groups = array_merge($groups, $class->getGroups()); + } + } + + foreach ($reflection->getProperties() as $property) { + foreach ($reader->getPropertyAnnotations($property) as $class) { + if ($class instanceof Column) { + $groups = array_merge($groups, $class->getGroups()); + } } } } + + return $groups; } public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, \Twig_Node $node) { }