limenius / liformbundle Goto Github PK
View Code? Open in Web Editor NEWSymfony Bundle to render Symfony Forms to JSON Schema
License: MIT License
Symfony Bundle to render Symfony Forms to JSON Schema
License: MIT License
Hello
Symfony 3.4 is telling me that the method setDefaultTransformers() is not defined.
I checked Limenius\Liform\Resolver and could not find that method.
This is how my controller looks like:
`use Limenius\Liform\Resolver;
use Limenius\Liform\Liform;
class AdController extends Controller
{
/**
* @Route("/nouvelle-annonce-voiture-occasion", name="new_ad_page")
*/
public function showAction(Request $request)
{
$resolver = new Resolver();
$resolver->setDefaultTransformers();
$liform = new Liform($resolver);
$ad = new Ad();
//$form = $this->createForm(AdType::class, $ad);
$form = $this->createForm(AdType::class, $ad);
$schema = json_encode($liform->transform($form));
\Doctrine\Common\Util\Debug::dump($schema);`
Also, you may notice that I removed the csrf_protection => false option from createForm
as it would give me the error below. Instead I placed that option on the Type class, as follows:
public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => Ad::class, 'csrf_protection' => false, )); }
This is the error: (if I leave the csrf_protection where you instruct in docs)
The option "csrf_protection" does not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "compound", "constraints", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "liform", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "upload_max_size_message", "validation_groups".
Thanks
$builder
->add('date', DateTimeType::class, [
'widget' => 'single_text',
])
;
result => Could not find a transformer for any of these types (datetime, form)
Actualy a bypass by using a simple text input and appy a transformer on it :
->addModelTransformer(new CallbackTransformer(
function ($datetimeObj) {
if ($datetimeObj === null) {
return '';
}
return $datetimeObj->format('Y-m-d H:i:s');
},
function ($datetimeString) {
return \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datetimeString, new \DateTimeZone('UTC'));
}
))
Got this error when I tried to generate a schema with liform :
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\UndefinedMethodException: "Attempted to call an undefined method named "getBlockPrefix" of class "Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeDataCollectorProxy"." at /home/admin/Documents/displayce/code/vendor/limenius/liform/src/Limenius/Liform/FormUtil.php line 39
Here my two code lines :
$editForm = $this->createForm(new EditType(), $entity, array( 'method' => 'PUT', 'csrf_protection' => false, ));
$schema = json_encode($this->get('liform')->transform($editForm));
I saw a bug related to that and it seems to be fixed with 2.8 version but of course my project is using 2.7 : https://github.com/symfony/symfony/issues/15760
Hi,
I am a newer using Liform connect with angular-schema-form.
Also, maybe this is reported already, but I am receiving from json form which has a DataType field a key widget="date"
Anyway to pass this a render a datepicker (which I am doing) ?
Thanks in advance.
Hi,
I want to integrate your bundle into Symfony4 project.
But when I load my application I have this issue :
I already added this line in my bundles.php file for loading your bundle in my kernel app symfony
Limenius\LiformBundle\LimeniusLiformBundle::class => ['dev' => true, 'test' => true],
perhaps Symfony version dependancy issue ?
Can we get a new release? The latest one is missing f96cd65 latest Symfony compatibility fix.
Thanks.
The bundle is working properly, but it returns widget instead of format.
"address": {
"type": "string",
"title": "Email address",
"widget": "email",
"propertyOrder": 2
},
Hello @nacmartin ,
By default, you specify StringTransformer
as the default transformer for TimeType
in transformers.xml.
With this default settings, it's just impossible to override the TimeType
with another Transformer, for example if we want to use a ChoiceType (select input) with the 'choice' widget.
It's possible to remove this default settings?
Thanks in advance
Fetching the service via $this->get, as described in the README, has been removed in Symfony 6, as all services are private by default and the container and get() helper methods aren't available.
Instead, the documentation should reflect getting the service by injecting it in the contructor or the controller method, e..g
__construct(private Liform $liform)
Ideally, though, this would work with LiformInterface (the abstract instead of the concrete).
Thanks for this great usefull bundle, i just got a problem, you call translator "As It" without check for any translation domain who can be specified in symfony form builder, and look like you dont use translator at all for placeholder, as i'm going to have a base project who have to be able to maintain multi-language functionality i think you just need a little change to make translator work like a charm without put all in a messages.{lang}.yml
namespace Limenius\Liform\Transformer;
abstract class AbstractTransformer {
///...
protected function addLabel($form, $schema)
{
if ($label = $form->getConfig()->getOption('label')) {
$schema['title'] = $this->translator->trans($label); // <----- should be ' .... '->trans($label, [], $TranslationDomainSpecifiedFromSymfonyFormBuildler )
} else {
$schema['title'] = $this->translator->trans($form->getName());
}
return $schema;
}
//....
}
Edit : this is related to https://github.com/Limenius/Liform i'll make a PR to solve this issue
Change the type from: "library" to "symfony-bundle"
https://github.com/answear/LiformBundle is the latest version of this bundle, and works with Symfony 6.
However, since it's a fork it does not allow for adding issues.
It seems like answear should become the maintainer of this bundle, since it's the most up to date.
Environment: PHP 7.4 and Symfony 5.0.6 with Flex.
When running composer require limenius/liform-bundle ^0.16.0
, the following error occurs:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- limenius/liform-bundle v0.16.0 requires limenius/liform ^0.16.0 -> satisfiable by limenius/liform[v0.16.0].
- Installation request for limenius/liform-bundle ^0.16.0 -> satisfiable by limenius/liform-bundle[v0.16.0].
- Conclusion: remove symfony/cache-contracts v2.0.1
- Conclusion: don't install symfony/cache-contracts v2.0.1
- limenius/liform v0.16.0 requires symfony/contracts ^2.1 -> satisfiable by symfony/contracts[v2.1.0, v2.1.1, v2.1.2, v2.1.3].
- don't install symfony/contracts v2.1.0|don't install symfony/cache-contracts v2.0.1
- don't install symfony/contracts v2.1.1|don't install symfony/cache-contracts v2.0.1
- don't install symfony/contracts v2.1.2|don't install symfony/cache-contracts v2.0.1
- don't install symfony/contracts v2.1.3|don't install symfony/cache-contracts v2.0.1
- Installation request for symfony/cache-contracts (locked at v2.0.1) -> satisfiable by symfony/cache-contracts[v2.0.1].
Additional research (probably not so helpful) yielded this output:
$ composer why symfony/cache-contracts
symfony/cache v5.0.6 requires symfony/cache-contracts (^1.1.7|^2)
$ composer require symfony/contracts ^2.1.0
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Conclusion: don't install symfony/contracts v2.1.3
- Conclusion: don't install symfony/contracts v2.1.2
- Conclusion: don't install symfony/contracts v2.1.1
- don't install symfony/http-client-contracts v2.0.1|don't install symfony/contracts v2.1.0
- don't install symfony/contracts v2.1.0|remove symfony/http-client-contracts v2.0.1
- don't install symfony/contracts v2.1.0|don't install symfony/http-client-contracts v2.0.1
- Installation request for symfony/contracts ^2.1.0 -> satisfiable by symfony/contracts[v2.1.0,
v2.1.1, v2.1.2, v2.1.3].
- Installation request for symfony/http-client-contracts (locked at v2.0.1) -> satisfiable by symfony/http-client-contracts[v2.0.1].
I suppose this might be a version incompatibility with symfony/cache 5.0.6, but I'll be thankful for any help!
As you indicate in the documentation, the bundle must be able to be used with the script json-editor.
But in this script, "enum_titles" should be in an "options" array to be applied.
It's a choice or an error?
Thanks for your work.
Hi,
In a FormType, if we have 'label' => false
, it's normalized by the form name instead of null
(or a blank string if we want to follow the RFC).
In your code:
protected function addLabel(FormInterface $form, array $schema)
{
$translationDomain = $form->getConfig()->getOption('translation_domain');
if ($label = $form->getConfig()->getOption('label')) {
$schema['title'] = $this->translator->trans($label, [], $translationDomain);
} else {
$schema['title'] = $this->translator->trans($form->getName(), [], $translationDomain);
}
return $schema;
}
should be changed by:
protected function addLabel(FormInterface $form, array $schema)
{
$translationDomain = $form->getConfig()->getOption('translation_domain');
if ($label = $form->getConfig()->getOption('label')) {
$schema['title'] = $this->translator->trans($label, [], $translationDomain);
} elseif (false === $form->getConfig()->getOption('label')) {
$schema['title'] = '';
} else {
$schema['title'] = $this->translator->trans($form->getName(), [], $translationDomain);
}
return $schema;
}
Hello,
I have a server_side rendering who work's fine, and I try to send specific status code (404, 503...) on certains routes, but I always get 200 and I don't know how to do that.
Could you help me ?
I'm uncertain whether the issue I'm experiencing is because my current version of Symfony 4.3.4 is unsupported by this bundle, or due to some specific implementation issue in our installation, or whether actually the bundle does not support all the different types included by Symfony.
use Limenius\Liform\Resolver;
use Limenius\Liform\Liform;
use Limenius\Liform\Liform\Transformer;
...
public function edit(Activity $activity, Liform $liform, Request $request)
{
// $builder->add('startDate', DateType::class, [
$form = $this->createForm(ActivityFormType::class, $activity, []);
$schema = $liform->transform($form);
...
}
The above pattern works as expected for TextType, and ChoiceType, but falls over for DateType with the error
"Could not find a transformer for any of these types (date, form) "
The documenation does not make it clear whether I should expect this functionality to exist. It suggests I will need to add custom work to include custom extension, however seems to imply that it should work out the box with a standard Symfony install.
I notice that DateType and EntityType do not seem to be in the list of available transformers here.
https://github.com/Limenius/LiformBundle/blob/master/Resources/config/transformers.xml
Am I correct then in my understanding that DateType which is a standard Symfony type is not supported?
https://symfony.com/doc/current/reference/forms/types/date.html
Edit
Also from here http://nacho-martin.com/serializing-symfony-forms-to-json-schema.html
This overview seems to imply dates are supported
->add('dueTo', Type\DateTimeType::class, [
Using the DateTimeType we get a similar error Could not find a transformer for any of these types (datetime)
Docs says:
This bundle registers a normalizer to serialize forms with errors into an array.
$serializer = $this->get('serializer');
$initialValues = $serializer->normalize($form);
but there is no "serializer" service registered. I see in services.yml
that there is InitialValuesNormalizer
<service id="liform.serializer.initial_values_normalizer" class="Limenius\Liform\Serializer\Normalizer\InitialValuesNormalizer" public="false">
<tag name="serializer.normalizer" priority="-10" />
</service>
but it is public="false"
so I can't access it.
I have eneded with this:
$normalizer = new \Limenius\Liform\Serializer\Normalizer\InitialValuesNormalizer();
$initialValues = $normalizer->normalize($form);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.