{"id":16003008,"url":"https://github.com/limenius/liformbundle","last_synced_at":"2025-05-15T08:11:35.261Z","repository":{"id":8976765,"uuid":"60427553","full_name":"Limenius/LiformBundle","owner":"Limenius","description":"Symfony Bundle to render Symfony Forms to JSON Schema","archived":false,"fork":false,"pushed_at":"2025-03-27T10:07:23.000Z","size":99,"stargazers_count":140,"open_issues_count":8,"forks_count":44,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-10T04:44:06.280Z","etag":null,"topics":["forms","json-schema","reactjs","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Limenius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-04T19:48:54.000Z","updated_at":"2025-05-08T12:04:56.000Z","dependencies_parsed_at":"2022-09-16T10:50:40.660Z","dependency_job_id":"48b64f9b-bcc9-4a33-b401-80a9441e134a","html_url":"https://github.com/Limenius/LiformBundle","commit_stats":{"total_commits":78,"total_committers":8,"mean_commits":9.75,"dds":0.1282051282051282,"last_synced_commit":"a17409d915b75b2c905800152d551e11420ca84f"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limenius%2FLiformBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limenius%2FLiformBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limenius%2FLiformBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Limenius%2FLiformBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Limenius","download_url":"https://codeload.github.com/Limenius/LiformBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254301613,"owners_count":22047905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["forms","json-schema","reactjs","symfony","symfony-bundle"],"created_at":"2024-10-08T10:05:41.979Z","updated_at":"2025-05-15T08:11:30.910Z","avatar_url":"https://github.com/Limenius.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"LiformBundle\n============\n\nBundle that integrates [Liform](https://github.com/Limenius/Liform) into Symfony. Liform is a library to serialize Symfony Forms into [JSON schema](http://json-schema.org/).\nFor use with [liform-react](https://github.com/Limenius/liform-react) or [json-editor](https://github.com/jdorn/json-editor), or any other form generator based on json-schema.\n\nIt is very annoying to maintain Symfony forms that match forms in a client technology, such as JavaScript. It is also annoying to maintain a documentation of such forms. And it's error prone, too.\n\nLiformBundle generates a JSON schema representation, that serves as documentation and can be used to validate your data and, if you want, to generate forms using a generator.\n\n## Installation\n\nFirst and foremost, note that you have a complete example with React, Webpack and Symfony Standard Edition at [Limenius/symfony-react-sandbox](https://github.com/Limenius/symfony-react-sandbox) ready for you, which includes an example implementation of this bundle.\n\nFeel free to clone it, run it, experiment, and copy the pieces you need to your project. Because this bundle focuses mainly on the frontend side of things, you are expected to have a compatible frontend setup.\n\n### Step 1: Download the Bundle\n\nOpen a console, navigate to your project directory and execute the\nfollowing command to download the latest stable version of this bundle:\n\n    $ composer require limenius/liform-bundle\n\nThis command requires you to have Composer installed globally, as explained\nin the *installation chapter* of the Composer documentation.\n\n### Step 2: Enable the Bundle\n\nThen, enable the bundle by adding the following line in the `app/AppKernel.php`\nfile of your project:\n\n```php\n// app/AppKernel.php\n\n// ...\nclass AppKernel extends Kernel\n{\n    public function registerBundles()\n    {\n        $bundles = array(\n            // ...\n\n            new Limenius\\LiformBundle\\LimeniusLiformBundle(),\n        );\n\n        // ...\n    }\n\n    // ...\n}\n```\n\n## Usage\n\nSerializing a form into JSON Schema:\n\n```php\n        $form = $this-\u003ecreateForm(CarType::class, $car, ['csrf_protection' =\u003e false]);\n        $schema = json_encode($this-\u003eget('liform')-\u003etransform($form));\n```\n\nAnd `$schema` will contain a JSON Schema representation such as:\n\n```js\n{  \n   \"title\":null,\n   \"properties\":{  \n      \"name\":{  \n         \"type\":\"string\",\n         \"title\":\"Name\",\n         \"propertyOrder\":1\n      },\n      \"color\":{  \n         \"type\":\"string\",\n         \"title\":\"Color\",\n         \"attr\":{  \n            \"placeholder\":\"444444\"\n         },\n         \"default\":\"444444\",\n         \"description\":\"3 hexadecimal digits\",\n         \"propertyOrder\":2\n      },\n      \"drivers\":{  \n         \"type\":\"array\",\n         \"title\":\"hola\",\n         \"items\":{  \n            \"title\":\"Drivers\",\n            \"properties\":{  \n               \"firstName\":{  \n                  \"type\":\"string\",\n                  \"propertyOrder\":1\n               },\n               \"familyName\":{  \n                  \"type\":\"string\",\n                  \"propertyOrder\":2\n               }\n            },\n            \"required\":[  \n               \"firstName\",\n               \"familyName\"\n            ],\n            \"type\":\"object\"\n         },\n         \"propertyOrder\":3\n      }\n   },\n   \"required\":[  \n      \"name\",\n      \"drivers\"\n   ]\n}\n```\n\n## Information extracted to JSON-schema\n\nThe goal of Liform is to extract as much data as possible from the form in order to have a complete representation with validation and UI hints in the schema. The options currently supported are.\n\nCheck out [the Liform documentation](https://github.com/Limenius/Liform/blob/master/README.md#information-extracted-to-json-schema) for more details.\n\n## Using your own transformers\n\nLiform works by recursively inspecting the form, finding (resolving) the right transformer for every child and using that transformer to build the corresponding slice of the json-schema. So, if you want to modify the way a particular form type is transformed, you can add a transformer and configure it to to be applied for all children with a particular `block_prefix`.  \nTo achieve this, you should create a new service definition and add the `liform.transformer` tag. You need to specify for which form-types your transformer will be applied by setting the `form_type` property of the tag to the corresponding `block_prefix`.\n\nIn the following example we are reusing the StringTransformer class. By specifying the `widget` property of the tag we can scope the transformer to only work for types with that particular widget.  \n\n```yaml\nservices:\n    app.liform.file_type.transformer:\n        class: \"%liform.transformer.string.class%\"\n        parent: Limenius\\Liform\\Transformer\\AbstractTransformer\n        tags:\n            - { name: liform.transformer, form_type: file, widget: file_widget }\n```\n\nYou can of course use your very own Transformer class, just make sure to implement the required `Limenius\\Liform\\Transformer\\TransformerInterface` when you do.\n\n## Extending the default behaviour\n\nIn addition to adding your own transformers for customizing the serialization of a specific form-type Liform allows you to add extensions to customize the default behaviour of all types.  \nIn the following example we use an Extension to add a `submit_url` property to the schema representing the form's `action` parameter.\n\n```php\n\u003c?php\n\nuse Limenius\\Liform\\Transformer\\ExtensionInterface;\nuse Symfony\\Component\\Form\\FormInterface;\n\nclass FormDataExtension implements ExtensionInterface\n{\n    /**\n     * @param FormInterface $form\n     * @param array         $schema\n     *\n     * @return array\n     */\n    public function apply(FormInterface $form, array $schema)\n    {\n        if (!$form-\u003eisRoot()) {\n            return $schema;\n        }\n\n        if (!$form-\u003egetConfig()-\u003ehasOption('action')) {\n            return $schema;\n        }\n\n        $schema['submit_url'] = $form-\u003egetConfig()-\u003egetOption('action');\n\n        return $schema;\n    }\n}\n```\n\nMake sure your Extension class implements the required `Limenius\\Liform\\Transformer\\ExtensionInterface`. To register your extension; create a new service definition and add the `liform.extension` tag to it.\n\n```yaml\nservices:\n    app.liform.form_data.extension:\n        class: MyProject\\Application\\Liform\\FormDataExtension\n        tags:\n            - { name: liform.extension }\n```\n\n## Serializing initial values\n\nThis bundle registers a normalizer to serialize a `FormView` class into an array of initial values that match your json-schema. The following example shows you how to use this feature in a controller action:\n\n```php\n$serializer = $this-\u003eget('serializer');\n$initialValues = $serializer-\u003enormalize($form);\n```\n\n## Serializing errors\n\n\nThis bundle registers a normalizer to serialize forms with errors into an array. This part was shamelessly taken from [FOSRestBundle](https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Serializer/Normalizer/FormErrorNormalizer.php). Copy the following statements to use this feature:\n\n```php\n$serializer = $this-\u003eget('serializer');\n$errors = $serializer-\u003enormalize($form);\n```\n\nThe format of the array containing the normalized form errors is compatible with the [liform-react](https://github.com/Limenius/liform-react) package. \n\n## License\n\nThis bundle was released under the MIT license. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.\n\n    LICENSE.md\n\n## Acknowledgements\n\nThe technique for transforming forms using resolvers and reducers is inspired on [Symfony Console Form](https://github.com/matthiasnoback/symfony-console-form)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimenius%2Fliformbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flimenius%2Fliformbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimenius%2Fliformbundle/lists"}