I think the answer to this question is very similar to your other question (Sulu CMF - CRUD Filtered Multi-Item-Selection for association entities). It sounds like you want to implement a selection for the DataGroup
entity. As already included in the answer to your other question, the Sulu Workshop and the Sulu Demo both contain a code example how to do this.
You can check all available configuration options for you selection field-type by printing the configuration reference for the SuluAdminBundle
with the following command:
bin/console config:dump-reference sulu_admin
Sulu uses the same mechanism for registering selection field-types for built-in entities like the contact_selection
or the single_account_selection
. This means that your custom selection field-type supports the same parameters that are supported by the built-in field types and can be found in the Sulu documentation.
For example, if you want to add a parameter that is sent to the server when loading the selectable items, you can use the request_parameters
param or the resource_store_properties_to_request
param in your form configuration. An example for this could look like this:
<property name="custom_selection" type="custom_selection">
<params>
<param name="request_parameters" type="collection">
<param name="static-parameter" value="static-value" />
</param>
<param name="resource_store_properties_to_request" type="collection">
<param name="dynamic-parameter" value="other-property-name" />
</param>
</params>
</property>
This selection field-type will use the list route of the configured resource key to load the selectable items. To actually filter the selectable items, you need to handle the parameter that is sent by the selection field-type in the controller of the list route. If you use the Sulu ListBuilder
service in this controller, the filtering could look something like this:
$filterValue = $request->query->get('static-parameter');
$listBuilder->where($fieldDescriptors['filtered-property-name'], $filterValue);