Skip to content

Commit

Permalink
1.0.4 - Add type
Browse files Browse the repository at this point in the history
  • Loading branch information
andries committed Mar 15, 2021
1 parent 079168b commit 97efc61
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 15 deletions.
64 changes: 50 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,71 @@ class ExampleController extends AbstractController
Example output:
```json
{
"id": "example",
"name": "example",
"label": "Example form",
"unique_block_prefix": "_example",
"value": null,
"id": "create_example_command",
"name": "create_example_command",
"type": "form",
"disabled": false,
"label": null,
"label_format": null,
"label_html": false,
"multipart": false,
"unique_block_prefix": "_create_example_command",
"row_attr": [],
"translation_domain": null,
"label_translation_parameters": [],
"attr_translation_parameters": [],
"valid": true,
"value": {
"name": null,
"exampleValue": null,
"exampleCountry": null,
"exampleDate": null
},
"required": true,
"size": null,
"label_attr": [],
"help": null,
"help_attr": [],
"help_html": false,
"help_translation_parameters": [],
"compound": true,
"method": "POST",
"action": "",
"submitted": false,
"attr": [],
"children": {
"text": {
"id": "example_text",
"name": "text",
"name": {
"id": "create_example_command_name",
"name": "name",
"type": "text",
"disabled": false,
"label": null,
"unique_block_prefix": "_example_text",
"value": "Hello!",
"label_format": null,
"label_html": false,
"multipart": false,
"unique_block_prefix": "_create_example_command_name",
"row_attr": [],
"translation_domain": null,
"label_translation_parameters": [],
"attr_translation_parameters": [],
"valid": true,
"value": "",
"required": true,
"size": null,
"label_attr": [],
"help": null,
"help_attr": [],
"help_html": false,
"help_translation_parameters": [],
"compound": false,
"method": "POST",
"action": "",
"attr": {
"class": "test-class"
},
"submitted": false,
"attr": [],
"errors": []
}
}
},
"errors": []
}
```

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"bundle",
"form"
],
"version": "1.0.3",
"version": "1.0.4",
"type": "symfony-bundle",
"require": {
"php": ">=8.0",
Expand Down
4 changes: 4 additions & 0 deletions src/Transformer/BuiltIn/AbstractTypeTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ abstract public static function getBlockPrefix(): string;

protected function hydrateBasicOptions(FormView $formView, array $schema): array
{
$blockPrefixes = $formView->vars['block_prefixes'];
$type = $blockPrefixes[count($blockPrefixes) - 2];

$schema['id'] = $formView->vars['id'] ?? null;
$schema['name'] = $formView->vars['name'] ?? null;
$schema['type'] = $type;
$schema['disabled'] = $formView->vars['disabled'] ?? null;
$schema['label'] = $formView->vars['label'] ?? null;
$schema['label_format'] = $formView->vars['label_format'] ?? null;
Expand Down
35 changes: 35 additions & 0 deletions tests/TransformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class TransformTest extends FormToJsonBundleTestCase
{
"id": "test",
"name": "test",
"type": "super_form",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -78,6 +79,7 @@ class TransformTest extends FormToJsonBundleTestCase
"text": {
"id": "test_text",
"name": "text",
"type": "text",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -107,6 +109,7 @@ class TransformTest extends FormToJsonBundleTestCase
"textarea": {
"id": "test_textarea",
"name": "textarea",
"type": "textarea",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -136,6 +139,7 @@ class TransformTest extends FormToJsonBundleTestCase
"email": {
"id": "test_email",
"name": "email",
"type": "email",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -165,6 +169,7 @@ class TransformTest extends FormToJsonBundleTestCase
"integer": {
"id": "test_integer",
"name": "integer",
"type": "integer",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -198,6 +203,7 @@ class TransformTest extends FormToJsonBundleTestCase
"money": {
"id": "test_money",
"name": "money",
"type": "money",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -235,6 +241,7 @@ class TransformTest extends FormToJsonBundleTestCase
"number": {
"id": "test_number",
"name": "number",
"type": "number",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -271,6 +278,7 @@ class TransformTest extends FormToJsonBundleTestCase
"password": {
"id": "test_password",
"name": "password",
"type": "password",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -303,6 +311,7 @@ class TransformTest extends FormToJsonBundleTestCase
"percent": {
"id": "test_percent",
"name": "percent",
"type": "percent",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -339,6 +348,7 @@ class TransformTest extends FormToJsonBundleTestCase
"search": {
"id": "test_search",
"name": "search",
"type": "search",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -368,6 +378,7 @@ class TransformTest extends FormToJsonBundleTestCase
"url": {
"id": "test_url",
"name": "url",
"type": "url",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -402,6 +413,7 @@ class TransformTest extends FormToJsonBundleTestCase
"range": {
"id": "test_range",
"name": "range",
"type": "range",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -431,6 +443,7 @@ class TransformTest extends FormToJsonBundleTestCase
"tel": {
"id": "test_tel",
"name": "tel",
"type": "tel",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -460,6 +473,7 @@ class TransformTest extends FormToJsonBundleTestCase
"color": {
"id": "test_color",
"name": "color",
"type": "color",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -492,6 +506,7 @@ class TransformTest extends FormToJsonBundleTestCase
"choice": {
"id": "test_choice",
"name": "choice",
"type": "choice",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -535,6 +550,7 @@ class TransformTest extends FormToJsonBundleTestCase
"country": {
"id": "test_country",
"name": "country",
"type": "country",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -579,6 +595,7 @@ class TransformTest extends FormToJsonBundleTestCase
"language": {
"id": "test_language",
"name": "language",
"type": "language",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -624,6 +641,7 @@ class TransformTest extends FormToJsonBundleTestCase
"locale": {
"id": "test_locale",
"name": "locale",
"type": "locale",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -668,6 +686,7 @@ class TransformTest extends FormToJsonBundleTestCase
"timezone": {
"id": "test_timezone",
"name": "timezone",
"type": "timezone",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -713,6 +732,7 @@ class TransformTest extends FormToJsonBundleTestCase
"currency": {
"id": "test_currency",
"name": "currency",
"type": "currency",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -757,6 +777,7 @@ class TransformTest extends FormToJsonBundleTestCase
"date": {
"id": "test_date",
"name": "date",
"type": "date",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -864,6 +885,7 @@ class TransformTest extends FormToJsonBundleTestCase
"dateInterval": {
"id": "test_dateInterval",
"name": "dateInterval",
"type": "dateinterval",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -1288,6 +1310,7 @@ class TransformTest extends FormToJsonBundleTestCase
"dateTime": {
"id": "test_dateTime",
"name": "dateTime",
"type": "datetime",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -1351,6 +1374,7 @@ class TransformTest extends FormToJsonBundleTestCase
"time": {
"id": "test_time",
"name": "time",
"type": "time",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -1554,6 +1578,7 @@ class TransformTest extends FormToJsonBundleTestCase
"birthday": {
"id": "test_birthday",
"name": "birthday",
"type": "birthday",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -1771,6 +1796,7 @@ class TransformTest extends FormToJsonBundleTestCase
"week": {
"id": "test_week",
"name": "week",
"type": "week",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -1891,6 +1917,7 @@ class TransformTest extends FormToJsonBundleTestCase
"checkbox": {
"id": "test_checkbox",
"name": "checkbox",
"type": "checkbox",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -1926,6 +1953,7 @@ class TransformTest extends FormToJsonBundleTestCase
"file": {
"id": "test_file",
"name": "file",
"type": "file",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -1958,6 +1986,7 @@ class TransformTest extends FormToJsonBundleTestCase
"radio": {
"id": "test_radio",
"name": "radio",
"type": "radio",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -1993,6 +2022,7 @@ class TransformTest extends FormToJsonBundleTestCase
"collection": {
"id": "test_collection",
"name": "collection",
"type": "collection",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -2033,6 +2063,7 @@ class TransformTest extends FormToJsonBundleTestCase
"repeated": {
"id": "test_repeated",
"name": "repeated",
"type": "repeated",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -2072,6 +2103,7 @@ class TransformTest extends FormToJsonBundleTestCase
"hidden": {
"id": "test_hidden",
"name": "hidden",
"type": "hidden",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -2101,6 +2133,7 @@ class TransformTest extends FormToJsonBundleTestCase
"button": {
"id": "test_button",
"name": "button",
"type": "button",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -2130,6 +2163,7 @@ class TransformTest extends FormToJsonBundleTestCase
"reset": {
"id": "test_reset",
"name": "reset",
"type": "reset",
"disabled": false,
"label": null,
"label_format": null,
Expand Down Expand Up @@ -2159,6 +2193,7 @@ class TransformTest extends FormToJsonBundleTestCase
"submit": {
"id": "test_submit",
"name": "submit",
"type": "submit",
"disabled": false,
"label": null,
"label_format": null,
Expand Down

0 comments on commit 97efc61

Please sign in to comment.