cmsPageUrlPathGenerator = $cmsPageUrlPathGenerator; $this->urlPersist = $urlPersist; } /** * Before save handler * * @param \Magento\Cms\Model\ResourceModel\Page $subject * @param \Magento\Framework\Model\AbstractModel $object * * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeSave( \Magento\Cms\Model\ResourceModel\Page $subject, \Magento\Framework\Model\AbstractModel $object ) { /** @var $object \Magento\Cms\Model\Page */ $urlKey = $object->getData('identifier'); if ($urlKey === '' || $urlKey === null) { $object->setData('identifier', $this->cmsPageUrlPathGenerator->generateUrlKey($object)); } } /** * On delete handler to remove related url rewrites * * @param \Magento\Cms\Model\ResourceModel\Page $subject * @param \Closure $proceed * @param \Magento\Framework\Model\AbstractModel $page * @return \Magento\Cms\Model\ResourceModel\Page * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDelete( \Magento\Cms\Model\ResourceModel\Page $subject, \Closure $proceed, \Magento\Framework\Model\AbstractModel $page ) { $result = $proceed($page); if ($page->isDeleted()) { $this->urlPersist->deleteByData( [ UrlRewrite::ENTITY_ID => $page->getId(), UrlRewrite::ENTITY_TYPE => CmsPageUrlRewriteGenerator::ENTITY_TYPE, ] ); } return $result; } }