I am preparing one common array which returns the complete details of all CMS pages. In this array, I need to pass the URL of all cms pages. I do have an identifier of all pages. How can I get the URL from it? Does anyone have an idea? Though it looks simple but bit tricky.
I have already used getPageUrl()
function extending \Magento\Cms\Helper\Page
helper class. But it simply adds the page identifier behind the store URL. Like for homepage, it returns http://127.0.0.1/magento2/home same as for 404 page it returns http://127.0.0.1/magento2/no-route.
Here is the code snippet I have used:
<?php
namespace Sample\Core\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
*
* @var \Magento\Cms\Helper\Page
*/
protected $cmsHelper;
public function __construct(
\Magento\Cms\Helper\Page $cmsHelper
) {
$this->cmsHelper = $cmsHelper;
}
public function getSeoData($cmsData)
{
$url = $this->cmsHelper->getPageUrl($cmsData->getPageId());
}
}
Here is the screen-shot of backend configuration,
Is there any intelligent function available in Magento2 which automatically understand this return the correct URL of all cms pages?
Any help into this would be highly appreciated.
Thanks,