An open API service indexing awesome lists of open source software.

https://github.com/ansien/formtojsonbundle

Convert Symfony forms to JSON
https://github.com/ansien/formtojsonbundle

converter forms json php symfony symfony-bundle symfony-forms transformer

Last synced: 2 months ago
JSON representation

Convert Symfony forms to JSON

Awesome Lists containing this project

README

        

# FormToJsonBundle

[comment]: <> (![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/ansien/FormToJsonBundle/Tests/master?label=Tests&logo=Tests))
[![Latest Version on Packagist](https://img.shields.io/packagist/v/ansien/form-to-json-bundle.svg)](https://packagist.org/packages/ansien/form-to-json-bundle)
[![Total Downloads](https://img.shields.io/packagist/dt/ansien/form-to-json-bundle.svg)](https://packagist.org/packages/ansien/form-to-json-bundle)
![GitHub](https://img.shields.io/github/license/ansien/FormToJsonBundle)

This bundle will allow you to transform Symfony forms into JSON.

## Installation
You can install the package via Composer:

```bash
composer require ansien/form-to-json-bundle
```

## Usage

Controller:
```php
createForm(ExampleType::class, $example);

return new JsonResponse($this->formTransformer->transform($form));
}
}
```

Example output:
```json
{
"schema": {
"id": "test",
"name": "test",
"type": "super_form",
"disabled": false,
"label": null,
"label_format": null,
"label_html": false,
"multipart": true,
"unique_block_prefix": "_test",
"row_attr": [],
"translation_domain": null,
"label_translation_parameters": [],
"attr_translation_parameters": [],
"valid": true,
"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": "test_text",
"name": "text",
"type": "text",
"disabled": false,
"label": null,
"label_format": null,
"label_html": false,
"multipart": false,
"unique_block_prefix": "_test_text",
"row_attr": [],
"translation_domain": null,
"label_translation_parameters": [],
"attr_translation_parameters": [],
"valid": true,
"required": true,
"size": null,
"label_attr": [],
"help": null,
"help_attr": [],
"help_html": false,
"help_translation_parameters": [],
"compound": false,
"method": "POST",
"action": "",
"submitted": false,
"attr": []
}
}
},
"values": {
"text": "Test 123"
},
"errors": {
"_global": [
"Test root error"
],
"text": [
"Test error"
]
}
}
```

## Extending the bundle
You can create your own form type transformer by making a new service that extends AbstractTypeTransformer and tagging it with `form_to_json_bundle.type_transformer`.

## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## Supporters
[![Stargazers repo roster for @ansien/FormToJsonBundle](https://reporoster.com/stars/ansien/FormToJsonBundle)](https://github.com/ansien/FormToJsonBundle/stargazers)

## Credits
- [Andries](https://github.com/ansien)
- [Limenius](https://github.com/Limenius)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.