app/code/Foo/Review/Block/View.php
<?php
// Since we are overriding the "Review" module, let's name our module "Review".
namespace Foo\Review\Block;
// We also want to name our class the same as the class we are overriding.
class View extends \Magento\Review\Block\View
{
// Only define the functions you wish to modify, as every other function
// call falls back to the parent class.
/**
* Format date in medium format (core returns long format).
*
* @param string $date
* @return string
*/
public function dateFormat($date)
{
return $this->formatDate($date, \IntlDateFormatter::MEDIUM);
}
}
app/code/Foo/Review/etc/frontend/di.xml
<?xml version="1.0"?>
<!-- Place this file in either the "frontend" or "adminhtml" folder -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- The "preference" node tells Magento which class to load -->
<!-- "for" = the class you wish to override -->
<!-- "type" = your customized class -->
<preference for="Magento\Review\Block\View" type="Foo\Review\Block\View" />
</config>
app/code/Foo/Review/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="Foo_Review">
<sequence>
<!-- Add the module we are overriding to the sequence node. -->
<!-- This ensures our module loads after and takes precedence. -->
<module name="Magento_Review"/>
</sequence>
</module>
</config>
Visit M.academy to learn much more about Magento, Laravel, PHP, Javascript, & Docker.