Skip to content

Commit ed1520a

Browse files
authored
Add dynamic field type Hidden (#362)
1 parent b3c3bd4 commit ed1520a

File tree

7 files changed

+82
-4
lines changed

7 files changed

+82
-4
lines changed

Dynamic/Types/HiddenType.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Sulu.
5+
*
6+
* (c) Sulu GmbH
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Sulu\Bundle\FormBundle\Dynamic\Types;
13+
14+
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeConfiguration;
15+
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeInterface;
16+
use Sulu\Bundle\FormBundle\Entity\FormField;
17+
use Symfony\Component\Form\Extension\Core\Type\HiddenType as TypeHiddenType;
18+
use Symfony\Component\Form\FormBuilderInterface;
19+
20+
/**
21+
* The Hidden form field type.
22+
*/
23+
class HiddenType implements FormFieldTypeInterface
24+
{
25+
use SimpleTypeTrait;
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function getConfiguration(): FormFieldTypeConfiguration
31+
{
32+
return new FormFieldTypeConfiguration(
33+
'sulu_form.type.hidden',
34+
__DIR__ . '/../../Resources/config/form-fields/field_hidden.xml'
35+
);
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void
42+
{
43+
$type = TypeHiddenType::class;
44+
$builder->add($field->getKey(), $type, $options);
45+
}
46+
}

Entity/Dynamic.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Dynamic implements AuditableInterface
3838
'headline',
3939
'freeText',
4040
'recaptcha',
41+
'hidden',
4142
];
4243

4344
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" ?>
2+
<properties xmlns="http://schemas.sulu.io/template/template"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/properties-1.0.xsd">
5+
<property name="title" type="text_editor" mandatory="true">
6+
<meta>
7+
<title>sulu_form.title</title>
8+
</meta>
9+
</property>
10+
11+
<property name="shortTitle" type="text_line" colspan="6">
12+
<meta>
13+
<title>sulu_form.short_title</title>
14+
<info_text>sulu_form.short_title_description</info_text>
15+
</meta>
16+
</property>
17+
18+
<property name="defaultValue" type="text_line" colspan="6">
19+
<meta>
20+
<title>sulu_form.default</title>
21+
</meta>
22+
</property>
23+
</properties>

Resources/config/types.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,9 @@
111111
<service id="sulu_form.dynamic.type_attachment" class="Sulu\Bundle\FormBundle\Dynamic\Types\AttachmentType">
112112
<tag name="sulu_form.dynamic.type" alias="attachment"/>
113113
</service>
114+
115+
<service id="sulu_form.dynamic.type_hidden" class="Sulu\Bundle\FormBundle\Dynamic\Types\HiddenType">
116+
<tag name="sulu_form.dynamic.type" alias="hidden"/>
117+
</service>
114118
</services>
115119
</container>

Resources/translations/admin.de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"sulu_form.type.radiobuttons": "Radio Buttons",
6868
"sulu_form.type.recaptcha": "Captcha",
6969
"sulu_form.type.mailchimp": "Mailchimp",
70+
"sulu_form.type.hidden": "Hidden",
7071
"sulu_form.type.sendinblue": "Sendinblue",
7172
"sulu_form.width.full": "Voll",
7273
"sulu_form.width.half": "Halb",

Resources/translations/admin.en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"sulu_form.type.radiobuttons": "Radio Buttons",
6868
"sulu_form.type.recaptcha": "Captcha",
6969
"sulu_form.type.mailchimp": "Mailchimp",
70+
"sulu_form.type.hidden": "Hidden",
7071
"sulu_form.type.sendinblue": "Sendinblue",
7172
"sulu_form.width.full": "Full",
7273
"sulu_form.width.half": "Half",

Tests/Functional/Metadata/DynamicFormMetadataLoaderTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testGetMetadataEnglish(): void
4848

4949
$fields = $formFields->getItems()['fields'];
5050
$this->assertInstanceOf(FieldMetadata::class, $fields);
51-
$this->assertCount(27, $fields->getTypes());
51+
$this->assertCount(28, $fields->getTypes());
5252
$this->assertEquals('fields', $fields->getName());
5353
$this->assertEquals('block', $fields->getType());
5454
$this->assertEquals('attachment', $fields->getDefaultType());
@@ -67,6 +67,7 @@ public function testGetMetadataEnglish(): void
6767
'freeText',
6868
'function',
6969
'headline',
70+
'hidden',
7071
'lastName',
7172
'textarea',
7273
'phone',
@@ -106,7 +107,7 @@ public function testGetMetadataGerman(): void
106107

107108
$fields = $formFields->getItems()['fields'];
108109
$this->assertInstanceOf(FieldMetadata::class, $fields);
109-
$this->assertCount(27, $fields->getTypes());
110+
$this->assertCount(28, $fields->getTypes());
110111
$this->assertEquals('fields', $fields->getName());
111112
$this->assertEquals('block', $fields->getType());
112113
$this->assertEquals('attachment', $fields->getDefaultType());
@@ -126,6 +127,7 @@ public function testGetMetadataGerman(): void
126127
'company',
127128
'freeText',
128129
'function',
130+
'hidden',
129131
'country',
130132
'spacer',
131133
'textarea',
@@ -184,7 +186,7 @@ public function testGetMetadataAttachmentEnglish(): void
184186

185187
$fields = $formFields->getItems()['fields'];
186188
$this->assertInstanceOf(FieldMetadata::class, $fields);
187-
$this->assertCount(27, $fields->getTypes());
189+
$this->assertCount(28, $fields->getTypes());
188190

189191
$attachment = $fields->getTypes()['attachment'];
190192
$this->assertInstanceOf(FormMetadata::class, $attachment);
@@ -253,7 +255,7 @@ public function testGetMetadataAttachmentGerman(): void
253255

254256
$fields = $formFields->getItems()['fields'];
255257
$this->assertInstanceOf(FieldMetadata::class, $fields);
256-
$this->assertCount(27, $fields->getTypes());
258+
$this->assertCount(28, $fields->getTypes());
257259

258260
$attachment = $fields->getTypes()['attachment'];
259261
$this->assertInstanceOf(FormMetadata::class, $attachment);

0 commit comments

Comments
 (0)