Class WidgetLocator A registry/factory for input widgets. Can be used by helpers/view logic to build form widgets and other HTML widgets. This class handles the mapping between names and concrete classes. It also has a basic name based dependency resolver that allows widgets to depend on each other. Each widget should expect a StringTemplate instance as their first argument. All other dependencies will be included after. Widgets can ask for the current view by using the _view widget.  Namespace: Cake\View\Widget Location: View/Widget/WidgetLocator.php  Properties summary    $_templates protected  Cake\View\StringTemplate  Templates to use.     $_widgets protected  array  Array of widgets + widget configuration.    Method Summary    __construct() public   Constructor     _resolveWidget() protected   Resolves a widget spec into an instance.     add() public   Adds or replaces existing widget instances/configuration with new ones.     clear() public   Clear the registry and reset the widgets.     get() public   Get a widget.     load() public   Load a config file containing widgets.    Method Detail   __construct()source public  __construct( Cake\View\StringTemplate $templates , Cake\View\View $view , string|array $widgets = [] ) Constructor Parameters   Cake\View\StringTemplate $templates  Templates instance to use.  Cake\View\View $view  The view instance to set as a widget.  string|array $widgets optional []  See add() method for more information.     _resolveWidget()source protected  _resolveWidget( mixed $widget ) Resolves a widget spec into an instance. Parameters   mixed $widget  The widget to get  Returns Cake\View\Widget\WidgetInterface Throws  RuntimeExceptionwhen class cannot be loaded or does not implement WidgetInterface. ReflectionException    add()source public  add( array $widgets ) Adds or replaces existing widget instances/configuration with new ones. Widget arrays can either be descriptions or instances. For example: $registry->add([
  'label' => new MyLabelWidget($templates),
  'checkbox' => ['Fancy.MyCheckbox', 'label']
]); The above shows how to define widgets as instances or as descriptions including dependencies. Classes can be defined with plugin notation, or fully namespaced class names. Parameters   array $widgets  Array of widgets to use.  Throws  RuntimeExceptionWhen class does not implement WidgetInterface.    clear()source public  clear( ) Clear the registry and reset the widgets.    get()source public  get( string $name ) Get a widget. Will either fetch an already created widget, or create a new instance if the widget has been defined. If the widget is undefined an instance of the _default widget will be returned. An exception will be thrown if the _default widget is undefined. Parameters   string $name  The widget name to get.  Returns Cake\View\Widget\WidgetInterfacewidget interface class. Throws  RuntimeExceptionwhen widget is undefined. ReflectionException    load()source public  load( string $file ) Load a config file containing widgets. Widget files should define a $config variable containing all the widgets to load. Loaded widgets will be merged with existing widgets. Parameters   string $file  The file to load   Properties detail   $_templatessource   protected Cake\View\StringTemplate  Templates to use.    $_widgetssource   protected array  Array of widgets + widget configuration.  []  

    
{'path': 'public/docs/cakephp~3.7/class-cake.view.widget.widgetlocator.html', 'source': 'DevDocs.IO'}