Change isUsingStaticUrlsAllowed via observer
-
05-10-2020 - |
题
I would like to change returned value by this core function:
//vendor\magento\module-cms\Helper\Wysiwyg\Images.php
public function isUsingStaticUrlsAllowed()
{
$checkResult = new \StdClass();
$checkResult->isAllowed = false;
$this->_eventManager->dispatch(
'cms_wysiwyg_images_static_urls_allowed',
['result' => $checkResult, 'store_id' => $this->_storeId]
);
return $checkResult->isAllowed;
}
I created my own observer:
public function execute(\Magento\Framework\Event\Observer $observer)
{
$result = $observer->getEvent()->getResult();
$result->isAllowed = true;
}
But it does not work and does not make sense (?). Can I change this value via observer or i need to use plugin ?
解决方案
Because an observer for this event already exists that is setting the same property (Magento\Catalog\Observer\CatalogCheckIsUsingStaticUrlsAllowedObserver
) you should instead use a plug-in because there's no reliable way to tell Magento to execute your observer after the other one executes.