Can anybody help me to add a class in getCountryHtmlSelect()
I have tried to override \Magento\Directory\Block\Data file using plugin but i can't extend that so i go for perference. added code in di.xml and created file in Vendor\Module\Block\Data please check the code below
<?php
namespace Vendor\Module\Block;
use Magento\Framework\View\Element\Template;
class Data extends \Magento\Directory\Block\Data
{
public function getCountryHtmlSelect($defValue = null, $name = 'country_id', $id = 'country', $title = 'Country')
{
\Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]);
if ($defValue === null) {
$defValue = $this->getCountryId();
}
$cacheKey = 'DIRECTORY_COUNTRY_SELECT_STORE_' . $this->_storeManager->getStore()->getCode();
$cache = $this->_configCacheType->load($cacheKey);
if ($cache) {
$options = $this->getSerializer()->unserialize($cache);
} else {
$options = $this->getCountryCollection()
->setForegroundCountries($this->getTopDestinations())
->toOptionArray();
$this->_configCacheType->save($this->getSerializer()->serialize($options), $cacheKey);
}
$html = $this->getLayout()->createBlock(
\Magento\Framework\View\Element\Html\Select::class
)->setName(
$name
)->setId(
$id
)->setTitle(
$this->escapeHtmlAttr(__($title))
)->setValue(
$defValue
)->setClass(
'class-name'
)->setOptions(
$options
)->setExtraParams(
'data-validate="{\'validate-select\':true}"'
)->getHtml();
\Magento\Framework\Profiler::stop('TEST: ' . __METHOD__);
return $html;
}
}
and my di.xml file
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Directory\Block\Data" type="Vendor\Module\Block\Data" />
</config>
cleared cache and compile the code shows no error.
can anybody give me an idea about this?
Thnaks in Advance