/** * @return \Magento\Framework\Controller\ResultInterface */ public function executeInternal() { /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->jsonFactory->create(); $error = false; $messages = []; if ($this->getRequest()->getParam('isAjax')) { $postItems = $this->getRequest()->getParam('items', []); if (!count($postItems)) { $messages[] = __('Please correct the data sent.'); $error = true; } else { foreach (array_keys($postItems) as $blockId) { /** @var \Magento\Cms\Model\Block $block */ $block = $this->blockRepository->getById($blockId); try { $block->setData(array_merge($block->getData(), $postItems[$blockId])); $this->blockRepository->save($block); } catch (\Exception $e) { $messages[] = $this->getErrorWithBlockId($block, __($e->getMessage())); $error = true; } } } } return $resultJson->setData(['messages' => $messages, 'error' => $error]); }
/** * Return CMS block ID * * @return int|null */ public function getBlockId() { try { return $this->blockRepository->getById($this->context->getRequest()->getParam('block_id'))->getId(); } catch (NoSuchEntityException $e) { } return null; }
/** * Test delete \Magento\Cms\Api\Data\BlockInterface * @expectedException \Magento\Framework\Exception\NoSuchEntityException */ public function testDelete() { $blockTitle = 'Block title'; $blockIdentifier = 'block-title'; /** @var \Magento\Cms\Api\Data\BlockInterface $blockDataObject */ $blockDataObject = $this->blockFactory->create(); $blockDataObject->setTitle($blockTitle)->setIdentifier($blockIdentifier); $this->currentBlock = $this->blockRepository->save($blockDataObject); $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $this->currentBlock->getId(), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'DeleteById']]; $this->_webApiCall($serviceInfo, [BlockInterface::BLOCK_ID => $this->currentBlock->getId()]); $this->blockRepository->getById($this->currentBlock['id']); }