Skip to content

Commit 4182d9a

Browse files
-
1 parent 5baa816 commit 4182d9a

File tree

5 files changed

+110
-67
lines changed

5 files changed

+110
-67
lines changed

src/Controller/ElasticsearchComponentTemplateController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use App\Controller\AbstractAppController;
66
use App\Exception\CallException;
77
use App\Form\Type\ElasticsearchComponentTemplateType;
8-
use App\Form\Type\ElasticsearchComponentTemplateFilterType;
8+
use App\Form\Type\ElasticsearchTemplateFilterType;
99
use App\Manager\ElasticsearchComponentTemplateManager;
1010
use App\Model\ElasticsearchComponentTemplateModel;
1111
use Symfony\Component\Routing\Annotation\Route;
@@ -35,7 +35,7 @@ public function index(Request $request): Response
3535
throw new AccessDeniedException();
3636
}
3737

38-
$form = $this->createForm(ElasticsearchComponentTemplateFilterType::class);
38+
$form = $this->createForm(ElasticsearchTemplateFilterType::class, null, ['context' => 'component_template']);
3939

4040
$form->handleRequest($request);
4141

src/Controller/ElasticsearchIndexTemplateController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use App\Controller\AbstractAppController;
66
use App\Exception\CallException;
77
use App\Form\Type\ElasticsearchIndexTemplateType;
8-
use App\Form\Type\ElasticsearchIndexTemplateFilterType;
8+
use App\Form\Type\ElasticsearchTemplateFilterType;
99
use App\Manager\ElasticsearchComponentTemplateManager;
1010
use App\Manager\ElasticsearchIndexTemplateManager;
1111
use App\Model\CallRequestModel;
@@ -38,7 +38,7 @@ public function index(Request $request): Response
3838
throw new AccessDeniedException();
3939
}
4040

41-
$form = $this->createForm(ElasticsearchIndexTemplateFilterType::class);
41+
$form = $this->createForm(ElasticsearchTemplateFilterType::class, null, ['context' => 'index_template']);
4242

4343
$form->handleRequest($request);
4444

src/Controller/ElasticsearchIndexTemplateLegacyController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use App\Controller\AbstractAppController;
66
use App\Exception\CallException;
77
use App\Form\Type\ElasticsearchIndexTemplateLegacyType;
8-
use App\Form\Type\NameFilterType;
8+
use App\Form\Type\ElasticsearchTemplateFilterType;
99
use App\Manager\ElasticsearchIndexTemplateLegacyManager;
1010
use App\Model\ElasticsearchIndexTemplateLegacyModel;
1111
use Symfony\Component\Routing\Annotation\Route;
@@ -31,7 +31,7 @@ public function index(Request $request): Response
3131
{
3232
$this->denyAccessUnlessGranted('INDEX_TEMPLATES_LEGACY', 'global');
3333

34-
$form = $this->createForm(NameFilterType::class);
34+
$form = $this->createForm(ElasticsearchTemplateFilterType::class, null, ['context' => 'index_template_legacy']);
3535

3636
$form->handleRequest($request);
3737

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace App\Form\Type;
4+
5+
use App\Manager\CallManager;
6+
use Symfony\Component\Form\AbstractType;
7+
use Symfony\Component\Form\FormBuilderInterface;
8+
use Symfony\Component\Form\Extension\Core\Type\TextType;
9+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
10+
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
11+
use Symfony\Component\OptionsResolver\OptionsResolver;
12+
13+
class ElasticsearchTemplateFilterType extends AbstractType
14+
{
15+
public function __construct(CallManager $callManager)
16+
{
17+
$this->callManager = $callManager;
18+
}
19+
20+
public function buildForm(FormBuilderInterface $builder, array $options)
21+
{
22+
$builder->setMethod('GET');
23+
24+
$fields = [];
25+
26+
$fields[] = 'name';
27+
if ('index_template' == $options['context'] && true === $this->callManager->hasFeature('data_streams')) {
28+
$fields[] = 'data_stream';
29+
}
30+
if ('index_template_legacy' != $options['context']) {
31+
$fields[] = 'managed';
32+
}
33+
$fields[] = 'sort';
34+
$fields[] = 'page';
35+
36+
foreach ($fields as $field) {
37+
switch ($field) {
38+
case 'name':
39+
$builder->add('name', TextType::class, [
40+
'label' => 'name',
41+
'required' => false,
42+
'attr' => [
43+
'data-break-after' => 'yes',
44+
],
45+
]);
46+
break;
47+
case 'data_stream':
48+
$builder->add('data_stream', ChoiceType::class, [
49+
'placeholder' => '-',
50+
'choices' => $options['question'],
51+
'choice_label' => function ($choice, $key, $value) use ($options) {
52+
return $options['question'][$key];
53+
},
54+
'label' => 'data_stream',
55+
'required' => false,
56+
'attr' => [
57+
'data-break-after' => 'yes',
58+
],
59+
]);
60+
break;
61+
case 'managed':
62+
$builder->add('managed', ChoiceType::class, [
63+
'placeholder' => '-',
64+
'choices' => $options['question'],
65+
'choice_label' => function ($choice, $key, $value) use ($options) {
66+
return $options['question'][$key];
67+
},
68+
'label' => 'managed',
69+
'required' => false,
70+
'attr' => [
71+
'data-break-after' => 'yes',
72+
],
73+
]);
74+
break;
75+
case 'sort':
76+
$builder->add('sort', HiddenType::class, [
77+
'label' => 'sort',
78+
'required' => false,
79+
]);
80+
break;
81+
case 'page':
82+
$builder->add('page', HiddenType::class, [
83+
'label' => 'page',
84+
'required' => false,
85+
]);
86+
break;
87+
}
88+
}
89+
}
90+
91+
public function configureOptions(OptionsResolver $resolver)
92+
{
93+
$resolver->setDefaults([
94+
'csrf_protection' => false,
95+
'question' => ['yes', 'no'],
96+
'context' => null,
97+
]);
98+
}
99+
100+
public function getBlockPrefix()
101+
{
102+
return '';
103+
}
104+
}

src/Form/Type/NameFilterType.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)