I seem to be missing something when it comes to overriding controllers. This is a somewhat recurring question in here, but nothing I’ve found in other questions worked for me, so either they might be a bit outdated or I am missing something obvious.
I am on Magento 2.3.4, trying to override Magento’s module-contact functionality.
Here’s what I’ve done:
Created a new module in /app/code/vendor/module.
Checked that the module shows up in module manager / php magento module:status.
Created etc/di.xml with the following code
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactControllerIndexPost" type="VendorModuleControllerIndexExtendIndex" />
</config>
Created etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Module" setup_version="1.0.0">
<sequence>
<module name="Magento_Contact"/>
</sequence>
</module>
</config>
Created /Controller/Index/ExtendIndex.php with minor functionality for testing
namespace VendorModuleControllerIndex;
class ExtendIndex extends MagentoContactControllerIndexPost
{
public function execute($coreRoute = null)
{
echo "1";
$this->messageManager->addSuccess('Message from new controller.');
return parent::execute($coreRoute);
}
}
Then flushed Magento Cache
Despite all that, which seems to be every step needed for this to work, it hasn’t, and I’ve tried all minor variations in terms of code I could think, as it could simply be a “” somewhere that shouldn’t be be or similar.
What am I missing here?