Skip to content

Commit d8d7b8f

Browse files
committed
The "property" option is deprecated in ecommit_javascript_jqueryautocompleteentityajax, ecommit_javascript_select2entityajax and ecommit_javascript_tokeninputentitiesajax. Use "choice_label" instead
1 parent 5d660a9 commit d8d7b8f

5 files changed

Lines changed: 18 additions & 8 deletions

File tree

Form/DataTransformer/Entity/AbstractEntityTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function extractLabel($object)
8888
} elseif (method_exists($object, '__toString')) {
8989
return (string)$object;
9090
} else {
91-
throw new \Exception('"property" option or "__toString" method must be defined"');
91+
throw new \Exception('"choice_label" option or "__toString" method must be defined"');
9292
}
9393
}
9494
}

Form/Type/EntityNormalizerTrait.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,17 @@ public function addCommonDefaultOptions(OptionsResolver $resolver, ManagerRegist
9696
'em' => null,
9797
'query_builder' => null,
9898
'identifier' => null,
99-
'property' => null,
99+
'property' => null, // deprecated since 2.2, use "choice_label"
100+
'choice_label' => function (Options $options) {
101+
// BC with the "property" option
102+
if ($options['property']) {
103+
trigger_error('The "property" option is deprecated since version 2.2. Use "choice_label" instead.', E_USER_DEPRECATED);
104+
105+
return $options['property'];
106+
}
107+
108+
return null;
109+
},
100110
'min_chars' => 1,
101111
'route_name' => null,
102112
'route_params' => array(),

Form/Type/JqueryAutocompleteEntityAjaxType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
6969
new EntityToArrayTransformer(
7070
$options['query_builder'],
7171
$options['identifier'],
72-
$options['property']
72+
$options['choice_label']
7373
)
7474
);
7575
}

Form/Type/Select2/Select2EntityAjaxType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function multipleAddTransformers(FormBuilderInterface $builder, array
7878
new EntitiesToJsonTransformer(
7979
$options['query_builder'],
8080
$options['identifier'],
81-
$options['property'],
81+
$options['choice_label'],
8282
'key',
8383
'label',
8484
$options['max'],
@@ -121,9 +121,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
121121

122122
$dataSelected = '';
123123
if (!$options['multiple'] && $options['input'] == 'entity' && $form->getData() && is_object($form->getData())) {
124-
$dataSelected = $this->extractLabel($form->getData(), $options['property']);
124+
$dataSelected = $this->extractLabel($form->getData(), $options['choice_label']);
125125
} elseif (!$options['multiple'] && $options['input'] == 'key' && $form->getNormData() && is_object($form->getNormData())) {
126-
$dataSelected = $this->extractLabel($form->getNormData(), $options['property']);
126+
$dataSelected = $this->extractLabel($form->getNormData(), $options['choice_label']);
127127
}
128128

129129
$view->vars['url'] = $options['url'];
@@ -148,7 +148,7 @@ protected function extractLabel($object, $property)
148148
} elseif (method_exists($object, '__toString')) {
149149
return (string)$object;
150150
} else {
151-
throw new \Exception('"property" option or "__toString" method must be defined"');
151+
throw new \Exception('"choice_label" option or "__toString" method must be defined"');
152152
}
153153
}
154154

Form/Type/TokenInputEntitiesAjaxType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
6666
new EntitiesToJsonTransformer(
6767
$options['query_builder'],
6868
$options['identifier'],
69-
$options['property'],
69+
$options['choice_label'],
7070
'id',
7171
'name',
7272
$options['max'],

0 commit comments

Comments
 (0)