Skip to content

Commit

Permalink
Updated configuration key that delays the ajax requests. (#7661)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gasjki authored Dec 20, 2021
1 parent 52b0e3a commit 64f7f80
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
41 changes: 39 additions & 2 deletions src/Form/Type/ModelAutocompleteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function buildView(FormView $view, FormInterface $form, array $options):
'req_param_name_search',
'req_param_name_page_number',
'req_param_name_items_per_page',
'quiet_millis',
'quiet_millis', // NEXT_MAJOR: Remove this line.
'delay',
'cache',
// CSS classes
'container_css_class',
Expand Down Expand Up @@ -118,7 +119,8 @@ public function configureOptions(OptionsResolver $resolver): void
'placeholder' => '',
'minimum_input_length' => 3, //minimum 3 chars should be typed to load ajax data
'items_per_page' => 10, //number of items per page
'quiet_millis' => 100,
'quiet_millis' => 100, // NEXT_MAJOR: Remove this line.
'delay' => 100,
'cache' => false,

'to_string_callback' => null,
Expand Down Expand Up @@ -156,10 +158,45 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedTypes('model_manager', ModelManagerInterface::class);
$resolver->setAllowedTypes('class', 'string');
$resolver->setAllowedTypes('property', ['string', 'array']);
$resolver->setDeprecated(
'quiet_millis',
...$this->deprecationParameters(
'4.x',
static function (Options $options, $value): string {
if (100 !== $value) {
return 'Passing a value to option "quiet_millis" is deprecated! Use "delay" instead!';
}

return '';
}
)
); // NEXT_MAJOR: Remove this deprecation notice.
}

public function getBlockPrefix(): string
{
return 'sonata_type_model_autocomplete';
}

/**
* This class is a BC layer for deprecation messages for symfony/options-resolver < 5.1.
* Remove this class when dropping support for symfony/options-resolver < 5.1.
*
* @param string|\Closure $message
*
* @return mixed[]
*/
private function deprecationParameters(string $version, $message): array
{
// @phpstan-ignore-next-line
if (method_exists(OptionsResolver::class, 'define')) {
return [
'sonata-project/admin-bundle',
$version,
$message,
];
}

return [$message];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ file that was distributed with this source code.
ajax: {
url: '{{ url ?: path(route.name, route.parameters|default([])) }}',
dataType: 'json',
quietMillis: {{ quiet_millis }},
delay: {{ delay === 100 and quiet_millis !== 100 ? quiet_millis : delay }}, // NEXT_MAJOR: Replace by `{{ delay }}` instead.
cache: {{ cache ? 'true' : 'false' }},
processResults: function (data, params) {
return {
Expand Down

0 comments on commit 64f7f80

Please sign in to comment.