Skip to content

Commit

Permalink
fix: deprecation warnings about the usage uasort() and filter type op…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
Kreyu committed Nov 24, 2023
1 parent 166f7b3 commit a5cd3c9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
61 changes: 49 additions & 12 deletions src/Filter/Type/FilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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];
})
Expand Down Expand Up @@ -143,30 +152,58 @@ 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']);
}

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;
})
;
Expand Down

0 comments on commit a5cd3c9

Please sign in to comment.