I need to change the html markup of checkbox and radio inputs in order to allow a cross browser customization.
I know that active field has a ‘template’ option, but i want to avoid change the various views in my system using checkbox and dont want to customize all my gridviews and possible future widgets that render checkbox/radio.
Would bee good if I could override the ‘tag’ method of BaseHtml, so I can check if is a radio or checkbox and change the markup and all checkbox/radio used will have the new markup.
Is this possible with dependency injection? If not, I would like to know if I can use other solution that dont force me to change code in various places.
Hi alirz23, thanks for the sugestion but this is the way I want to avoid (change code in various places). Also, extending ActiveField will not change the CheckboxColumn used in gridview.
You can’t override a single method but you can override a class with a class extending from original one. Create it and then put it in DI container under a name of the original class.
Hi samdark, maybe I’m missing something but I configured the container and nothing happens. The custom class is not being called. There is someting wrong with my code?
//file app/helpers/CustomBaseHtml.php
// >>>>>>> I've other classes in this namespace working properly
namespace app\helpers;
class CustomBaseHtml extends \yii\helpers\BaseHtml
{
public static function tag($name, $content = '', $options = [])
{
var_dump($name);die;
if ($name === null || $name === false) {
return $content;
}
$html = "<$name" . static::renderTagAttributes($options) . '>';
return isset(static::$voidElements[strtolower($name)]) ? $html : "$html$content</$name>";
}
}