- /**
- * Validate and Match Cms Page and modify request
- *
- * @param \Magento\Framework\App\RequestInterface $request
- * @return bool
- */
- public function match(\Magento\Framework\App\RequestInterface $request)
- {
- $identifier = trim($request->getPathInfo(), '/');
-
- $condition = new \Magento\Framework\DataObject(['identifier' => $identifier, 'continue' => true]);
- $this->_eventManager->dispatch(
- 'cms_controller_router_match_before',
- ['router' => $this, 'condition' => $condition]
- );
- $identifier = $condition->getIdentifier();
-
- if ($condition->getRedirectUrl()) {
- $this->_response->setRedirect($condition->getRedirectUrl());
- $request->setDispatched(true);
- return $this->actionFactory->create('Magento\Framework\App\Action\Redirect');
- }
-
- if (!$condition->getContinue()) {
- return null;
- }
-
- /** @var \Magento\Cms\Model\Page $page */
- $page = $this->_pageFactory->create();
- $pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId());
- if (!$pageId) {
- return null;
- }
-
- $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId);
- $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
-
- return $this->actionFactory->create('Magento\Framework\App\Action\Forward');
- }