Overriding Block in Magento 2

blocksmagento2-dev-betaoverridesphp-5.4

I'm playing overriding the blocks in magento 2, extended block constructor is calling but inside method is not working?

my code is

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Block\Account\Dashboard\Info" type="Learning\Customers\Block\Info" />
</config>

Info.php

  <?php

namespace Learning\Customers\Block;

use Magento\Framework\View\Element\Template;

class Info extends \Magento\Customer\Block\Account\Dashboard\Info
{

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
        \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
        \Magento\Customer\Helper\View $helperView,
        array $data = []
    ) {

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/Info.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info($this->getName());

        parent::__construct($context,$currentCustomer,$subscriberFactory,$helperView, $data);
    }

    public function getName()
    {
        return 'Magento 2';
    }

}

Any suggestions?

Thanks.

Best Answer

add below method to Info.php

protected function _toHtml()
    {
        $this->setModuleName($this->extractModuleName('Magento\Customer\Block\Account\Dashboard\Info'));
        return parent::_toHtml();
    }

see reference Link How to Overriding block in Magento 2