Symfony Form: translation of attr - symfony

I'm trying to translate help messages that I created on my form using attr array but I can't translate it. Does anybody know how to do it?
This is an example:
->add('facebook_sharing_title', null,
array(
'label' => "establishment.edit.facebooksharingtitle",
'required' => false,
'attr' => array('help' => '70 caractères max. conseillé')
)
)
As you can see, the translation o the label is ok. However, if I do the same for help it doesn't work. I can't find anything about it in the symfony site. I know how to do it on twig but I would like to do it on the form type.

Related

Capitalize filter in symfony2 Constraint Messages

I'm new to symfony. I searched a lot especially in the symfony documentation:
http://symfony.com/doc/current/book/translation.html#translating-constraint-messages
But I found nothing about it.
I know how to use capitalize twig filter in a twig template.
http://twig.sensiolabs.org/doc/filters/capitalize.html
{{ 'my first car'|capitalize }}
But is it possible to capitalize a translation in these three scenarios:
In entities annotations Constraints Messages (this example does not work, translation is not translated if I add |capitalize)
class Author
{
/**
* #Assert\NotBlank(message = "author.name.not_blank|capitalize")
*/
public $name;
}
In a form builder (this example does not work, translation is not translated if I add |capitalize)
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'invalid_message' => 'user.password_confirm_mismatch|capitalize',
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
'required' => false
)
In a controller with the translator service. In this case it is not very important because I can use the php ucfirst function. But maybe there is another method more in line with symfony best practices.
//Not capitalized, any way to add twig capitalize filter in this code?
$tranlsation_test_1 = $this->get('translator')->trans('info.profile_updated_successfully',array(),null,$new_user_app_language_code);
//Capitalized but with the php ucfirst function
$tranlsation_test_2 = ucfirst($this->get('translator')->trans('info.profile_updated_successfully',array(),null,$new_user_app_language_code));
Many tanks for your advices.

Symfony2 Sonata Admin IvoryCKEditor wrong render for some reason

I am trying to implement IvoryCKEditor Bundle to my SonataAdmin entities and I am witnessing some very strange errors/bugs/mistakes... I dont even know..
So when I want to render a simple textarea field and add some longtext to it I simply do something like this:
/**
* #param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
// ->add('id', 'hidden')
->add('name')
->add('contentEn', 'ckeditor', array(
'attr' => array('cols' => '8', 'rows' => '8')))
->add('contentEs', 'ckeditor', array(
'attr' => array('cols' => '8', 'rows' => '8')))
->add('status')
;
}
This works like a charm.. However if I have mapped entities and I want to show its fields I use sonata collection:
->add('translations', 'sonata_type_collection',
array(
'required' => false,
'label' => false,
),
array(
'edit' => 'inline',
'inline' => 'standard',
)
)
And in the mapped entities admin I do this again:
$formMapper
->with('Item Info')
//->add('id')
->add('product_name')
->add('description_for_lbi', 'ckeditor')
->add('short_description', 'ckeditor')
->add('long_description', 'ckeditor')
->add('conditions', 'ckeditor')
->add('language', null, array('required' => true))
->end()
;
Now here is the problem. Its seems the ckeditor form the collection is rendering in a completely different way.
The first example renders an iframe and makes the ckeditor look "clean".
In the collection ckeditor is rendering in a completely different way, no iframes.. And for the editor to show up I have to click on the field first.. And the field has no borders... I really dont know how to explain this.
So I guess my question is, why the ckeditor is rendering completely different when I am using it in a collection. Am I doing something wrong?
If you guys dont understand what I mean I can post some screens...
UPDATE
I thing the problem is here:
'edit' => 'inline',
'inline' => 'standard',
this makes the editor look bad. However if I remove these lines I get error:
Error: Maximum function nesting level of '100' reached, aborting!
This error is when I am trying to edit an object
You are completely right with your edit. inline editing in ckeditor breaks if you have 2 or more instances of the ckeditor config.
My suggestion is to drop inline editing.
For the second part, the error comes from xdebug, which cannot follow your object nesting level because it exceeds this limit.
In order to fix this (which is recommended, as limit = 100 is way too low for symfony2), please see this
article.

A2LiX Translation Form labels options

I'm using KnpLabs/DoctrineBehaviors/Translatable and A2LiX Translation Form to translate my entities in a Symfony application. It works very well. However, when the form is rendered there is a "translations" title that I would like to delete and a "EN [Default]" text on a tab that I would like to change.
In the examples of the doc, there's a "medias" example so I imagine that we can change this text. Moreover, the tabs don't have this [Default] text. So I imagine that's possible to change them.
And this is mine:
Does anybody know how to do it? If we take a look on the form type options we don't see anything concerning the "Translations" label. For the "Default", I can't see where I should search for it.
Default template file is located at vendor/a2lix/translation-form-bundle/A2lix/TranslationFormBundle/Resources/views/default.html.twig. If you want you can specify your own template and set it in config.yml file, like this:
a2lix_translation_form:
....
templating: "#SLCore/includes/translation.html.twig"
More information can be found here.
For the "translations" title, I was able to override it adding a label to the form type just like a normal field. However, it is not possible to use a blank value. I had to use ' ' in order to override the text.
->add('translations', 'a2lix_translations', array(
'label' => ' ', --> this overrides the translations title
'fields' => array(
'name' => array(
'field_type' => 'text',
'label' => 'blabla'
),
'description' => array(
'field_type' => 'textarea',
'label' => 'bleble',
)
)
))
For the "Default" label, I still have no solution.

symfony2 FromBuilder multiple checkboxes from entity instead of using "choice"

How can I get multiple Cehckboxes instead a choice field in Symfony? Actually, I'm using:
->add('usergroups', 'entity', array('class' => 'PrUserBundle:Group','property' => 'name','required' => true))
This will output a select-Field..
In this case, it would be better to output checkboxes as it is easier to handle for the user.
http://symfony.com/doc/current/reference/forms/types/checkbox.html at, there is nothing helpful about multiple select....
Do I have to build an array and place it by myself?
Use the expanded option for choice and entity fields.
->add('usergroups', 'entity', array('class' => 'PrUserBundle:Group','property' => 'name','required' => true, 'expanded' => true,))

ManyToMany nullable not allowed

I have a scenario like this:
tracks ManyToMany instruments
I create the form in this way:
$builder
->add('instruments', 'entity_hidden', array(
'attr' => array('class' => 'one_req'),
'label' => 'form.instrument',
'translation_domain' => 'label',
'required' => false,
'class' => 'Acme\DemoBundle\Entity\Instrument'
))
"hidden_entity" is given by a custom transformer that you can find here: gist
although I believe that is not the problem.
The problem is that the user may not even choose any instrument (such asamong other specified with "required" => false).
When I go to save my returns this error:
Neither the property 'instruments' nor one of the methods 'setInstruments()',
'__set()' or '__call()' exist and have public access in
class 'Acme\DemoBundle\Entity\SoundtrackVersion'.
I do not understand why ..
Where am I doing wrong?
It sounds very obvious, but error can not lie. Check that Acme\DemoBundle\Entity\SoundtrackVersion entity has property instruments and methods setInstruments() and getInstruments().

Resources