Custom Widget : RadioWidget


The way the current form->radio method works, it puts the “checked” attribute on the input box, but, a label is drawn for each of the entries within the radio option.

When it draws the label, it does not have any way to know that the label for a specific entry is the selected entry.

This was very easy to overcome by going into the logic where the option “checked” is defined and adding a [‘templateVars’] option for the label. In my case, I used $radio[‘templateVars’][‘activeClass’] = “active”.

fyi, my solution is in my _renderInput method of RadioWidget

It was a hard learning curve to figure it all out, but, once I did, it was one line of code. Sweet.

I really don’t feel comfortable modifying code in the “vendor” directory, the moment I do that there is going to be an upgrade and I lose my changes, then the code stops working. Bad.

I’ve made a copy of my RadioWidget in a plugin,

class RadioWidget extends \BootstrapUI\View\Widget\RadioWidget implements WidgetInterface

I’ve already got FormHelper in my plugin

class FormHelper extends \BootstrapUI\View\Helper\FormHelper{
     protected $_widgets = 

I’m running into issues of my class is already loaded.

Cannot declare class Dwilbanks\View\Widget\RadioWidget because the name is already in use in D:\wamp\www\tssc\plugins\Dwilbanks\src\View\Widget\RadioWidget.php

My question is, what is the proper way to do what I’m attempting. The core functionality of the cakephp RadioWidget is very close to what I need, but, slightly different. I need one line, but, I don’t want to modify the vendor code. I want to overwrite the specific class in my own code space.



Do I understand correct that you extending \BootstrapUI\View\Helper\FormHelper and totally redifining $_widget with replacing radio option with your widget class.
Did you also replaced UIViewTrait::initializeUI with your own Form helper loader?


I ended up, just allowing the widget to render it the way it likes, then modified the resulting html in javascript after the fact.

I’ve also submitted a feature request on the main code stream on github, that could resolve everything if they make the change.

I do however want to know what the best way to go about it is.

BootstrapUI inherits from cake, cake has the _renderInput method that I wanted to overwrite.

I have not made any changes to the UIViewTrait, it’s my intention that I don’t want to change any of the code in the vendor folder. Any changes I make there will not survive an upgrade.