Generic Widgets : LIST
YAML Configuration
If you want to use a list widget inside a page, please use the following code :
the service alias for the widget is : sunshine.widgets.list
The class used is : Tellaw\SunshineAdminBundle\Service\Widgets\ListWidget
Configuration Inheritance
The entity configuration handle all the details for list, filters and every configuration elements. But you can also customize its configuration in any page to customize :
Which fields should be rendered.
Which filters should be rendered.
What datasources, filters may use.
Section Filters
This section make possible for you to set the default values of the filters. Two options to do it :
Using a property of the entity.
Writing a method returning a set of datas.
Method 1 : Using an attribute of the entity
Using this configuration, the filter 'status' will load by default the data 'pending' of its property 'code'.
This is like writing :
The data used by the framework to render the value in the list, will be the field 'filterAttribute' defined in the entity.
Note, that the Status entity has to define a getId() method, returning a uniq ID.
Method 2 : Writing a custom method.
This method make it possible for you to write a method used by the framework to load default values.
Imagine that your users are linked to companies and departments. You may want to preset in the filter every company of the user.
In the configuration specify the method to use :
And the implement the function in the repository of the entity used by the list :
Note the interface of the function :
$filterKey is the id of the filter requiring datas. In this case : 'societe'
$filtersConfiguration is an array with the configuration of the filters of the page.
Note also that the method has to return an array with the format :
SearchKey
The search key attribute makes possible to preset the search field.
Override (List & Filters)
With overrides, you can add or remove element on :
Columns of the list.
Filters.
The override section must be located in parameter's section of the page :
This configuration will :
Add the societe column in the list.
Remove the lastname column from the list
Add the societe filter to the filters tab.
Remove the status filter from the filter tab.
include
This directive will try to add the filter or the column in the widget. The column must be configured correctly in the entity.
exclude
This directive will remove a filter or column from the widget.
Configure the data source of the list
You need also to be able to configure your datasource for the list. The configuration described previously makes possible to set defaults values, but it doesn't filter the resultset.
This can be done in the entity configuration. At the relation, define a 'callback' method.
In the configuration, the list 'societe' will load its data from the callbackFunction : 'getAvailableSocietes'
Implement this method in the repository of the parent entity.
Please read the documentation : Filtering : Custom values in Select2 lists
Last updated