简体   繁体   中英

Magento 2 override core framework

i want to override AbstractBlock class, i tried with my custom module but it not working

di.xml

<?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="Magento\Framework\View\Element\AbstractBlock" type="YourCompany\YourModule\Framework\View\Element\AbstractBlock" />
</config>

AbstractBlock.php

<?php
namespace YourCompany\YourModule\Framework\View\Element;

abstract class AbstractBlock extends \Magento\Framework\View\Element\AbstractBlock {

    /**
     * Retrieve child block HTML
     *
     * @param   string $alias
     * @param   boolean $useCache
     * @return  string
     */
    public function getChildHtml($alias = '', $useCache = true)
    {
        die("here");
    }

}

You cannot replace a class in the middle of the hierarchy. Meaning, exchanging an existing parent (abstract) class by another abstract class.

May be you can show how are you using the original class (I guess in a constructor) and that would help a little bit to give a better answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM