Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreyu committed Feb 16, 2024
1 parent 189baac commit 5d64089
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"symfony/mime": "^6.0",
"symfony/twig-bundle": "^6.0",
"twig/extra-bundle": "^3.6",
"twig/intl-extra": "^3.6"
"twig/intl-extra": "^3.6",
"symfony/validator": "^6.0"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
Expand Down
12 changes: 12 additions & 0 deletions src/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Kreyu\Bundle\DataTableBundle\Query\ResultSetInterface;
use Kreyu\Bundle\DataTableBundle\Sorting\SortingData;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;

class DataTable implements DataTableInterface
{
Expand Down Expand Up @@ -731,6 +732,17 @@ public function createPersonalizationFormBuilder(?DataTableView $view = null): F
);
}

public function getExportForm(): FormInterface
{
return $this->exportForm ??= $this->config->getExportFormFactory()->createNamed(

Check failure on line 737 in src/DataTable.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Kreyu\Bundle\DataTableBundle\DataTable::$exportForm.
name: $this->config->getExportParameterName(),
type: ExportDataType::class,
options: [
'exporters' => $this->getExporters(),
],
);
}

public function createExportFormBuilder(?DataTableView $view = null): FormBuilderInterface
{
if (!$this->config->isExportingEnabled()) {
Expand Down
30 changes: 18 additions & 12 deletions src/Exporter/Form/Type/ExportDataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints;

class ExportDataType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('filename', TextType::class)
->add('filename', TextType::class, [
'required' => true,
'constraints' => [
new Constraints\NotBlank(),
new Constraints\Callback(function (string $filename): bool {
// TODO: return str_contains($filename, '');

Check failure on line 27 in src/Exporter/Form/Type/ExportDataType.php

View workflow job for this annotation

GitHub Actions / phpstan

Anonymous function should return bool but return statement is missing.
})
],
])
->add('exporter', ChoiceType::class, [
'choices' => array_flip(array_map(
fn (ExporterInterface $exporter) => $exporter->getConfig()->getOption('label', $exporter->getName()),
Expand All @@ -34,16 +43,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => ExportData::class,
'translation_domain' => 'KreyuDataTable',
'exporters' => [],
]);

$resolver->setAllowedTypes('exporters', ExporterInterface::class.'[]');

// TODO: Remove deprecated default filename option
$resolver->setDefault('default_filename', null);
$resolver->setDeprecated('default_filename', 'kreyu/data-table-bundle', '0.14', 'The "%name%" option is deprecated.');
$resolver
->setDefaults([
'data_class' => ExportData::class,
'translation_domain' => 'KreyuDataTable',
'exporters' => [],
])
->setAllowedTypes('exporters', ExporterInterface::class.'[]')
;
}
}
2 changes: 2 additions & 0 deletions src/Request/HttpFoundationRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ private function export(DataTableInterface $dataTable, Request $request): void
return;
}

$dataTable->getExportForm()->handleRequest($request);

Check failure on line 116 in src/Request/HttpFoundationRequestHandler.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Kreyu\Bundle\DataTableBundle\DataTableInterface::getExportForm().

$form = $dataTable->createExportFormBuilder()->getForm();
$form->handleRequest($request);

Expand Down
3 changes: 1 addition & 2 deletions src/Type/DataTableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ private function createPersonalizationFormView(DataTableView $view, DataTableInt

private function createExportFormView(DataTableView $view, DataTableInterface $dataTable): FormView
{
$form = $dataTable->createExportFormBuilder()->getForm();
$form->setData($dataTable->getExportData());
$form = $dataTable->getExportForm();

Check failure on line 378 in src/Type/DataTableType.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Kreyu\Bundle\DataTableBundle\DataTableInterface::getExportForm().

return $this->createFormView($form, $view, $dataTable);
}
Expand Down

0 comments on commit 5d64089

Please sign in to comment.