Cake\View\Helper\FormHelper::widgetRegistry PHP Method

widgetRegistry() public method

Set the widget registry the helper will use.
public widgetRegistry ( Cake\View\Widget\WidgetRegistry $instance = null, array $widgets = [] ) : Cake\View\Widget\WidgetRegistry
$instance Cake\View\Widget\WidgetRegistry The registry instance to set.
$widgets array An array of widgets
return Cake\View\Widget\WidgetRegistry
    public function widgetRegistry(WidgetRegistry $instance = null, $widgets = [])
    {
        if ($instance === null) {
            if ($this->_registry === null) {
                $this->_registry = new WidgetRegistry($this->templater(), $this->_View, $widgets);
            }
            return $this->_registry;
        }
        $this->_registry = $instance;
        return $this->_registry;
    }

Usage Example

 /**
  * Test that when specifying custom widgets config file and it should be
  * added to widgets array. WidgetRegistry will load widgets in constructor.
  *
  * @return void
  */
 public function testConstructWithWidgetsConfig()
 {
     $helper = new FormHelper($this->View, ['widgets' => ['test_widgets']]);
     $registry = $helper->widgetRegistry();
     $this->assertInstanceOf('Cake\\View\\Widget\\LabelWidget', $registry->get('text'));
 }