1

I have two entities:

class DataSet {
  string $name;
  Collection $groups; // List<DataGroup>
}
class DataGroup {
  string $name;
  DataSet $set;
  DataGroup $nextGroup;
}

I created some basic Admin UI extensions for CRUD operations on DataSets, as per docs. Now I also want to perform CRUD operations on the associated DataGroups of a DataSet. For that, I first looked at the ContactBundle Javascript extension and registered a CardCollection for the $groups field, which came with an overlay form (providing a form schema, etc).

DataGroup::nextGroup is supposed to be any other DataGroup entity sharing the same DataSet. How can I provide all matching entities to the component in a SingleAutoComplete?

UPDATE 2021-09-09

I switched to the intended approach of configuration-wise implementation.

I also made a followup question to narrow down my exact problem.

Leon Willens
  • 356
  • 1
  • 16

1 Answers1

1

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);
nnatter
  • 111
  • 3
  • Thank you for the tip on the configuration options. However, as of [my comment to the answer](https://stackoverflow.com/questions/68943054/sulu-cmf-crud-multi-item-selection-for-association-entities/68951117#121919962), I fail to see a possibility to implement additional respository filters for these approaches. Is there a way? – Leon Willens Sep 02 '21 at 09:58
  • Yes, you can use the `request_parameters` param or `resource_store_properties_to_request` param to add a parameter to the request that loads the selectable items. I have added an example for this to my answer. – nnatter Sep 02 '21 at 12:18
  • Thank you for the example. I've gained significant insight from your explanations and updated my question with my current approach. Both `data_groups.xml` and the `data_group.xml` form are now within a `FormOverlayList` in a separate tab, and rendering is fine - however, when trying to add a new `DataGroup`, I fail to pass `DataSet.id` into the `nextGroup` property, and the Route declines the list route request - did I use `resource_store_properties_to_request` correct? – Leon Willens Sep 09 '21 at 10:27
  • I am sorry, I do not understand what you are trying to do. I think it would be helpful to create a new question that includes screenshots, a description of the desired behaviour and your existing code (including the code of your controller). – nnatter Sep 09 '21 at 12:33
  • I see. I'll link you the question. – Leon Willens Sep 09 '21 at 13:40
  • I posted the new question with all pieces of sourcecode relevant to my remaining problem. See [here](https://stackoverflow.com/questions/69120159/sulu-cmf-pass-parameter-to-autocomplete-field-in-formoverlaylist-add-form). – Leon Willens Sep 09 '21 at 14:37