I have three entities Provision
, Gatekeeper
and Data
.
class Provision {
private Gatekeeper $keeper; // ManyToOne
private Collection $points; // ManyToMany
}
class Gatekeeper {
private int $id;
private string $name;
private bool $allowData;
}
class Data {
private int $value;
}
All entities have REST-CRUD logic implemented. In order to edit the Provision
entity I've added configurations to the sulu_admin.yaml
:
sulu_admin:
field_type_options:
selection:
data_selection:
default_type: 'list_overlay'
resource_key: 'data'
types:
list_overlay:
adapter: 'table'
list_key: 'data'
display_properties: ['value']
icon: 'su-plus'
label: 'app.data'
overlay_title: 'app.action.select.data'
single_selection:
single_gatekeeper_selection:
default_type: 'single_select'
resource_key: 'gatekeepers'
types:
single_select:
display_property: 'name'
id_property: 'id'
overlay_title: 'app.action.select.gatekeeper'
Now, in the form configuration file for Provision
entities, I want to include a visibleCondition
for the data list:
<form xmlns="http://schemas.sulu.io/template/template"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd">
<key>provision_details</key>
<properties>
<property name="gatekeeper" type="single_gatekeeper_selection" mandatory="true">
<meta>
<title>app.gatekeeper</title>
</meta>
</property>
<property name="data" type="data_selection" visibleCondition="!!gatekeeper && gatekeeper.allowData">
<meta>
<title>app.data</title>
</meta>
</property>
</properties>
</form>
Is there any possibility to implement this behaviour? I've already tried adding a custom ConditionDataProvider
, but the main problem is that the visibleCondition
is evaluated at Field
-level while the only place I could pull the required data from would be the ResourceListStore
in the SingleSelect
.
This is not possible you only have access to the raw form data. For a single selection the gatekeeper
value contains only the id
of the selected element. Not any data of the element behind this element.
All data you have access to it, you see in save (POST/PUT) request of the form.
The only thing which is possible would be using resource_store_properties_to_request
to filter the result of your data_selection by the gatekeeper id, this requires that your data api need to keep the gatekeeper
parameter in mind to filter by it:
<properties>
<property name="gatekeeper" type="single_gatekeeper_selection" mandatory="true">
<meta>
<title>app.gatekeeper</title>
</meta>
</property>
<property name="data" type="data_selection">
<meta>
<title>app.data</title>
</meta>
<params>
<param name="resource_store_properties_to_request" type="collection">
<param name="gatekeeper" value="gatekeeper"/>
</param>
</params>
</property>
</properties>