resource = $resource; $this->pageFactory = $pageFactory; $this->pageCollectionFactory = $pageCollectionFactory; $this->searchResultsFactory = $searchResultsFactory; $this->dataObjectHelper = $dataObjectHelper; $this->dataPageFactory = $dataPageFactory; $this->dataObjectProcessor = $dataObjectProcessor; $this->storeManager = $storeManager; $this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor(); } /** * Save Page data * * @param \Magento\Cms\Api\Data\PageInterface $page * @return Page * @throws CouldNotSaveException */ public function save(\Magento\Cms\Api\Data\PageInterface $page) { if ($page->getStoreId() === null) { $storeId = $this->storeManager->getStore()->getId(); $page->setStoreId($storeId); } try { $this->resource->save($page); } catch (\Exception $exception) { throw new CouldNotSaveException( __('Could not save the page: %1', $exception->getMessage()), $exception ); } return $page; } /** * Load Page data by given Page Identity * * @param string $pageId * @return Page * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function getById($pageId) { $page = $this->pageFactory->create(); $page->load($pageId); if (!$page->getId()) { throw new NoSuchEntityException(__('The CMS page with the "%1" ID doesn\'t exist.', $pageId)); } return $page; } /** * Load Page data collection by given search criteria * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @param \Magento\Framework\Api\SearchCriteriaInterface $criteria * @return \Magento\Cms\Api\Data\PageSearchResultsInterface */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $criteria) { /** @var \Magento\Cms\Model\ResourceModel\Page\Collection $collection */ $collection = $this->pageCollectionFactory->create(); $this->collectionProcessor->process($criteria, $collection); /** @var Data\PageSearchResultsInterface $searchResults */ $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($criteria); $searchResults->setItems($collection->getItems()); $searchResults->setTotalCount($collection->getSize()); return $searchResults; } /** * Delete Page * * @param \Magento\Cms\Api\Data\PageInterface $page * @return bool * @throws CouldNotDeleteException */ public function delete(\Magento\Cms\Api\Data\PageInterface $page) { try { $this->resource->delete($page); } catch (\Exception $exception) { throw new CouldNotDeleteException(__( 'Could not delete the page: %1', $exception->getMessage() )); } return true; } /** * Delete Page by given Page Identity * * @param string $pageId * @return bool * @throws CouldNotDeleteException * @throws NoSuchEntityException */ public function deleteById($pageId) { return $this->delete($this->getById($pageId)); } /** * Retrieve collection processor * * @deprecated 102.0.0 * @return CollectionProcessorInterface */ private function getCollectionProcessor() { if (!$this->collectionProcessor) { $this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get( 'Magento\Cms\Model\Api\SearchCriteria\PageCollectionProcessor' ); } return $this->collectionProcessor; } }