diff --git a/src/Translator/Extractor/AdminExtractor.php b/src/Translator/Extractor/AdminExtractor.php index bf70f3b65d..6b3963f2df 100644 --- a/src/Translator/Extractor/AdminExtractor.php +++ b/src/Translator/Extractor/AdminExtractor.php @@ -13,6 +13,7 @@ namespace Sonata\AdminBundle\Translator\Extractor; +use Sonata\AdminBundle\Admin\AdminInterface; use Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface; use Sonata\AdminBundle\Admin\Pool; use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface; @@ -70,6 +71,10 @@ public function extract($resource, MessageCatalogue $catalogue): void foreach ($this->adminPool->getAdminServiceCodes() as $code) { $admin = $this->adminPool->getInstance($code); + if (!$this->isValidAdmin($admin)) { + continue; + } + $this->labelStrategy = $admin->getLabelTranslatorStrategy(); $this->domain = $admin->getTranslationDomain(); @@ -79,6 +84,7 @@ public function extract($resource, MessageCatalogue $catalogue): void } $admin->setLabelTranslatorStrategy($this); + $admin->setSubject($admin->getNewInstance()); foreach (self::PUBLIC_ADMIN_METHODS as $method) { @@ -117,4 +123,18 @@ public function getLabel(string $label, string $context = '', string $type = '') return $label; } + + /** + * @param AdminInterface $admin + */ + private function isValidAdmin(AdminInterface $admin): bool + { + $class = $admin->getClass(); + + if (!class_exists($class)) { + return false; + } + + return !(new \ReflectionClass($class))->isAbstract(); + } } diff --git a/tests/Translator/Extractor/AdminExtractorTest.php b/tests/Translator/Extractor/AdminExtractorTest.php index 464c679c41..a2663eaefa 100644 --- a/tests/Translator/Extractor/AdminExtractorTest.php +++ b/tests/Translator/Extractor/AdminExtractorTest.php @@ -51,8 +51,14 @@ protected function setUp(): void $this->fooAdmin->method('getShow')->willReturn(new FieldDescriptionCollection()); $this->fooAdmin->method('getList')->willReturn(new FieldDescriptionCollection()); + $this->fooAdmin + ->method('getClass') + ->willReturn(\stdClass::class); $this->barAdmin->method('getShow')->willReturn(new FieldDescriptionCollection()); $this->barAdmin->method('getList')->willReturn(new FieldDescriptionCollection()); + $this->barAdmin + ->method('getClass') + ->willReturn(\stdClass::class); $container = new Container(); $container->set('foo_admin', $this->fooAdmin);