getRequest()->getParam('entity_type'); $this->assertBlogPermission($entityType); $collection = $this->collection($entityType); $selected = $this->filter->getCollection($collection)->getAllIds(); if ($selected === []) { throw new \InvalidArgumentException((string)__('Select at least one item.')); } $token = $this->selectionRegistry->save($entityType, array_map('intval', $selected)); return $this->resultRedirectFactory->create()->setPath('*/*/new', ['token' => $token]); } catch (\Throwable $exception) { $this->messageManager->addErrorMessage($exception->getMessage()); return $this->resultRedirectFactory->create()->setPath('*/*/new'); } } private function collection(string $entityType): AbstractDb { return match ($entityType) { 'product' => $this->productCollectionFactory->create(), 'cms_page' => $this->pageCollectionFactory->create(), 'cms_block' => $this->blockCollectionFactory->create(), 'blog_post' => $this->blogPostCollectionFactory->create(), default => throw new \InvalidArgumentException((string)__('Unsupported batch entity type.')), }; } private function assertBlogPermission(string $entityType): void { if ($entityType === 'blog_post' && !$this->_authorization->isAllowed('Esun_MultiLocaleTranslation::translate_blog') ) { throw new \InvalidArgumentException((string)__('You are not allowed to translate blog posts.')); } } }