From a5cd3c91fd301181f6d423052562935b00423ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Wr=C3=B3blewski?= Date: Fri, 24 Nov 2023 10:09:26 +0100 Subject: [PATCH] fix: deprecation warnings about the usage uasort() and filter type options --- src/DataTable.php | 2 +- src/Filter/Type/FilterType.php | 61 +++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/DataTable.php b/src/DataTable.php index db327025..cb7dbc9c 100755 --- a/src/DataTable.php +++ b/src/DataTable.php @@ -166,7 +166,7 @@ public function getColumns(): array $columns = $this->columns; uasort($columns, static function (ColumnInterface $columnA, ColumnInterface $columnB) { - return $columnA->getPriority() < $columnB->getPriority(); + return $columnB->getPriority() <=> $columnA->getPriority(); }); return $columns; diff --git a/src/Filter/Type/FilterType.php b/src/Filter/Type/FilterType.php index d142f637..cf7121f3 100755 --- a/src/Filter/Type/FilterType.php +++ b/src/Filter/Type/FilterType.php @@ -59,10 +59,11 @@ public function buildView(FilterView $view, FilterInterface $filter, FilterData 'label_translation_parameters' => $options['label_translation_parameters'], 'translation_domain' => $options['translation_domain'] ?? $view->parent->vars['translation_domain'], 'query_path' => $options['query_path'] ?? $filter->getName(), - 'field_Type' => $options['field_type'], - 'field_options' => $options['field_options'], - 'operator_type' => $options['operator_type'], - 'operator_options' => $options['operator_options'], + 'field_Type' => $options['field_type'] ?? $options['form_type'], + 'field_type' => $options['field_type'] ?? $options['form_type'], + 'field_options' => $options['field_options'] ?? $options['form_options'], + 'operator_type' => $options['operator_type'] ?? $options['operator_form_type'], + 'operator_options' => $options['operator_options'] ?? $options['operator_form_options'], 'active_filter_formatter' => $options['active_filter_formatter'], 'data' => $view->data, 'value' => $view->value, @@ -95,15 +96,23 @@ public function configureOptions(OptionsResolver $resolver): void 'empty_data' => '', // TODO: Remove deprecated options - 'auto_alias_resolving' => true, - 'field_type' => null, - 'field_options' => [], - 'operator_type' => null, - 'operator_options' => [ - 'visible' => null, - 'choices' => [], - ], +// 'auto_alias_resolving' => true, +// 'field_type' => null, +// 'field_options' => [], +// 'operator_type' => null, +// 'operator_options' => [ +// 'visible' => null, +// 'choices' => [], +// ], ]) + ->setDefined([ + 'auto_alias_resolving', + 'field_type', + 'field_options', + 'operator_type', + 'operator_options', + ]) + ->addNormalizer('form_options', function (Options $options, array $value): array { return $value + ['required' => false]; }) @@ -143,15 +152,31 @@ public function configureOptions(OptionsResolver $resolver): void ->setDeprecated('operator_type', 'kreyu/data-table-bundle', '0.14', 'The "%name%" option is deprecated, use "operator_form_type" instead.') ->setDeprecated('operator_options', 'kreyu/data-table-bundle', '0.14', 'The "%name%" option is deprecated, use "operator_form_options", "supported_operators", "operator_selectable" and "default_operator" instead.') ->addNormalizer('form_type', function (Options $options, mixed $value) { + if (!$options->offsetExists('field_type')) { + return $value; + } + return $options['field_type'] ?? $value; }) ->addNormalizer('form_options', function (Options $options, mixed $value) { + if (!$options->offsetExists('field_options')) { + return $value; + } + return $options['field_options'] ?: $value; }) ->addNormalizer('operator_form_type', function (Options $options, mixed $value) { + if (!$options->offsetExists('operator_type')) { + return $value; + } + return $options['operator_type'] ?? $value; }) ->addNormalizer('operator_form_options', function (Options $options, mixed $value) { + if (!$options->offsetExists('operator_options')) { + return $value; + } + if ($deprecatedValue = $options['operator_options']) { unset($deprecatedValue['visible'], $deprecatedValue['choices']); } @@ -159,14 +184,26 @@ public function configureOptions(OptionsResolver $resolver): void return $deprecatedValue ?: $value; }) ->addNormalizer('supported_operators', function (Options $options, mixed $value) { + if (!$options->offsetExists('operator_options')) { + return $value; + } + return ($options['operator_options']['choices'] ?? []) ?: $value; }) ->addNormalizer('default_operator', function (Options $options, mixed $value) { + if (!$options->offsetExists('operator_options')) { + return $value; + } + $deprecatedChoices = $options['operator_options']['choices'] ?? []; return reset($deprecatedChoices) ?: $value; }) ->addNormalizer('operator_selectable', function (Options $options, mixed $value) { + if (!$options->offsetExists('operator_options')) { + return $value; + } + return ($options['operator_options']['visible'] ?? null) ?: $value; }) ;