Skip to content

Commit 4dcf52f

Browse files
committed
Add support for default values in nonpersisted fields
1 parent c145e1e commit 4dcf52f

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

src/midcom/datamanager/extension/type/autocompleteType.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,22 @@ public function buildForm(FormBuilderInterface $builder, array $options) : void
108108
public function finishView(FormView $view, FormInterface $form, array $options) : void
109109
{
110110
$preset = [];
111-
if ( !empty($view->children['selection']->vars['data'])
112-
&& !empty($options['widget_config']['class'])) {
113-
foreach (array_filter((array) $view->children['selection']->vars['data']) as $identifier) {
114-
if ($options['widget_config']['id_field'] == 'id') {
115-
$identifier = (int) $identifier;
116-
}
117-
try {
118-
$object = $options['widget_config']['class']::get_cached($identifier);
119-
$preset[$identifier] = autocomplete_helper::create_item_label($object, $options['widget_config']['result_headers'], $options['widget_config']['titlefield']);
120-
} catch (midcom_error $e) {
121-
$e->log();
111+
if (!empty($view->children['selection']->vars['data'])) {
112+
$identifiers = array_filter((array) $view->children['selection']->vars['data']);
113+
if (!empty($options['widget_config']['class'])) {
114+
foreach ($identifiers as $identifier) {
115+
if ($options['widget_config']['id_field'] == 'id') {
116+
$identifier = (int) $identifier;
117+
}
118+
try {
119+
$object = $options['widget_config']['class']::get_cached($identifier);
120+
$preset[$identifier] = autocomplete_helper::create_item_label($object, $options['widget_config']['result_headers'], $options['widget_config']['titlefield']);
121+
} catch (midcom_error $e) {
122+
$e->log();
123+
}
122124
}
125+
} else {
126+
$preset = array_combine($identifiers, $identifiers);
123127
}
124128
}
125129

0 commit comments

Comments
 (0)