1.Copy that block to your Module in Block Folder and override Using di.xml file in your custom module like :
1 : Copy that block to your Module in Block Folder and override Using di.xml file in your custom module like :
A. find or add di.xml file at below location :
/app/code/Vendor/Module/etc/frontend/di.xml
B. Add Code Like Below in di.xml file :
<?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\Store\Block\Switcher" type="Vendor\Module\Block\Switcher" />
</config>
2.Change namespace According to your module on top
2 : Change namespace According to your module on top
namespace Magento\Store\Block\Switcher => namespace Vendor\Module\Block\Switcher
3.Defining New Protected Variable , Injecting New Class, Defining New Function, Calling New function in Template File
3 : Defining New Protected Variable , Injecting New Class, Defining New Function, Calling New function in Template File
namespace Vendor\Module\Block\Switcher;
class Index extends \Magento\Framework\View\Element\Template
{
protected $newVariable; //new variable
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
/** All already injected classes**/,
\Vendor\Module\Model\ModelClass $modelClassObject, // Inject New Class Just before Data array if you want to inject
array $data = []
) {
/** All Alreay Defined Variable**/
$this->newVariable = $modelClassObject; //New object Get of Injected Class
parent::__construct($context, $data);
}
/** New Function **/
public function newFunction(){
}
}
4. You Can get New Function in Associated template/view file like :
4 : You Can get New Function in Associated template/view file like :
$this->newFunction(); or $block->newFunction();