Add new option "as_id" to Pick*DynamicType

This option will make the app return a single id of the entity in data, and not the entity json.
This commit is contained in:
2023-11-27 13:23:36 +01:00
parent 1a9af6b0b1
commit f11f7498d7
5 changed files with 30 additions and 8 deletions

View File

@@ -42,6 +42,7 @@ class PickUserDynamicType extends AbstractType
$view->vars['types'] = ['user'];
$view->vars['uniqid'] = uniqid('pick_user_dyn');
$view->vars['suggested'] = [];
$view->vars['as_id'] = true === $options['as_id'] ? '1' : '0';
foreach ($options['suggested'] as $user) {
$view->vars['suggested'][] = $this->normalizer->normalize($user, 'json', ['groups' => 'read']);
@@ -54,7 +55,10 @@ class PickUserDynamicType extends AbstractType
->setDefault('multiple', false)
->setAllowedTypes('multiple', ['bool'])
->setDefault('compound', false)
->setDefault('suggested', []);
->setDefault('suggested', [])
// if set to true, only the id will be set inside the content. The denormalization will not work.
->setDefault('as_id', false)
->setAllowedTypes('as_id', ['bool']);
}
public function getBlockPrefix()