getRequest()->getParam('id'); try { if ($themeId) { /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ $theme = $this->_objectManager->create( \Magento\Framework\View\Design\ThemeInterface::class )->load($themeId); if (!$theme->getId()) { throw new \InvalidArgumentException(sprintf('We cannot find a theme with id "%1".', $themeId)); } if (!$theme->isVirtual()) { throw new \InvalidArgumentException( sprintf('Only virtual theme is possible to delete and theme "%s" isn\'t virtual', $themeId) ); } $theme->delete(); $this->messageManager->addSuccess(__('You deleted the theme.')); } } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('We cannot delete the theme.')); $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); } $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('adminhtml/*/'); } }