I have an entity Post which has many Comments and I have included as follows in my PostAdmin.php
->tab('Comments')
->with('')
->add('comments', 'sonata_type_collection', array('by_reference' => false,'disabled' => false, 'label' => ' ', 'required' => false,
'type_options' => array(
'delete' => false,
'btn_add' => false
)
), array(
'edit' => 'inline',
))
->end()
->end();
I have already customised edit.html.twig to include javascripts that run some functions which are unrelated to this question.
I would like to override the comments block in edit.html.twig to include some ajax functionality for buttons that would then publish, delete or edit a single comment from all the listed comments under the article.
How would I go about this?
Related
I am using woocommerce plugin. Idea was to edit checkout page to create my own classes , placeholders etc for fields. With some googling I managed it all. Only thing that I can't change is country dropdown/select. For example having this code
$fields['shipping']['shipping_country'] = array(
'type' => 'select',
'label' => 'Country',
'placeholder' => '',
'maxlength' => false,
'required' => false,
'class' => array(),
'label_class' => array('col-md-6'),
'input_class' => array('col-md-6'),
'return' => false,
'options' => array( 'Germany' => 'Germany',
'Germany' => 'Germany'),
'custom_attributes' => array(),
'validate' => array(),
'default' => '',
);
I want to dynamically load all countries from woocommerce. I don't want to add country by country in array, dont think thats the right way also. So is there some object or whatever that will load in this 'options' array all available countries?
You aren't very specific - you haven't shared where this code exists in your system, or which countries you want, but the answer to your question is yes.
Check out these two functions:
WC()->countries->get_shipping_countries();
WC()->countries->get_allowed_countries();
NOTE:
You ALSO probably want to be using the woocommerce_form_field for this, since it does all the heavy lifting for you.
Sorry for my english.
I need to create a drop down list (select option) with values taken from an Entity.
I must also add options (I use select2 to do this).
When I send the form it doesn't work. How can I configure the field type to make it work?
I need the possibilities to adding multiple persons
My current code is
...
->add('person', 'entity', array(
'attr' => array(
'class' => 'tags'
),
'class' => 'AppBundle:Person',
'data_class' => null,
'label' => 'Persons',
'mapped' => false,
'multiple' => true,
'required' => false
));
Select2
$('select.tags').select2({
language: 'it',
tags: true,
tokenSeparators: [','],
width: '100%'
});
Error message
The offset "0" does not exist.
in advance, sorry for my poor english.
I have a problem with the "sonata_type_collection" form type.
I got two entity, the first, "proposition" has a one-to-many relationship with "Image". "Image" has a many-to-one relationship with "proposition". Everything seems to work well, the ImageAdmin is nested in PropositionAdmin.
But when i add a row in the PropositionAdmin, without persisting object, it clear the input="file" field. I read that its the correct behavior since Sonata reload the form when adding a row. So i was wondering if there was a way to avoid that behavior.
Thanks in advance.
Here is my code :
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('title')
->add('axe')
->add('username')
->add('password','repeated', array('type' => 'text','options' => array('translation_domain' => 'FOSUserBundle'),
'first_options' => array('label' => 'form.password'),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch'))
->add('imgs', 'sonata_type_collection', array(
'by_reference' => false
), array(
'edit' => 'inline',
'allow_delete' => true
))
;
}
I endend up by using a Symfony2 form.
I generated the formtype with Command here
Then, in the parent entity's bundle:
>add('imgs', 'collection', array(
'label' => 'Créations',
'by_reference' => false ,
'type' => new \propalBundle\Form\ImageType(),
'allow_delete' => true,
'allow_add' => true
), array(
'edit' => 'standard',
'inline' => 'table',
))
It can require some tweaks but seems to work.
When the proposition has relation oneToMany with image you should add multiple attribute in the configuration of imgs filed in PropositionAdmin class
->add('imgs', 'sonata_type_collection', array(
'by_reference' => false
'multiple' => true
), array(
'edit' => 'inline',
'allow_delete' => true
));
Suppose you have ArticleAdmin and CommentsAdmin. It is easy to add one-to-many editing in Sonata:
$formMapper->add('comments', 'sonata_type_collection',
array(
'by_reference' => false,
),
array(
'edit' => 'inline',
'inline' => 'table',
)
);
However, suppose I have more complicated CommentsAdmin form and it can has two visualizations depending on the kind of comment in it. I would like to display two sonata_type_collection fields in ArticleAdmin for grouping different types of comments into two different edit tables.
Adding another add('comments', ...) is of course incorrect, and adding add('comments2', ...) results in exception.
I will manage separating comments between two fields in admin, but how to create sonata_type_collection field on a virtual entity field Article::comments2? How to tell Sonata Admin what kind of collection should it be?
I'm not sure if this will help you but:
->add('categoryHasMedia', 'sonata_type_collection', array(
'cascade_validation' => true,
'label' => 'Logo\'s'
), array(
'edit' => 'inline',
'inline' => 'table',
'link_parameters' => array('context' => $context),
'admin_code' => 'appstrakt.project.admin.category_has_media',
))
By using admin_code you can tell which admin class you want to use for that sonata_type_collection if I'm not mistaken.
I have a problem with the EWZRecaptcha Bunlde (dev-master) and symfony 2.1.0.
The reCaptcha is displayed correctly and the image changes so i think the configuration is ok. But the reCaptcha is not validated and after submitting, $form->getErrorsAsString() says: This form should not contain extra fields.
Well, i think the extra fields are recaptcha_challenge_field and recaptcha_response_field that are sent from reCaptcha but i don think that i missed something in the docu so what can be wrong with them?
For validation i use the code from the docu: (i also tried the alternative, that was mentioned there)
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints as Recaptcha;
//...
/**
* #Recaptcha\True
*/
public $recaptcha;
//...
in config:
framework:
validation: { enable_annotations: true }
i added the field like this:
$builder->add('recaptcha', 'ewz_recaptcha', array(
'property_path' => false,
'attr' => array(
'options' => array(
'theme' => 'clean'
)
)
));
Maybe i forgot something essential, that was not mentioned in the docu?
Possibly try adding a 'constraints' option to the builder. My recaptcha builder add looks like this:
$builder->add('recaptcha', 'ewz_recaptcha', array(
'attr' => array(
'options' => array(
'theme' => 'red'
)
),
'label' => "Verification",
'property_path' => false,
'constraints' => array(
new True()
),
'help' => "Enter the words in the box for verification purposes."
));
So add a 'use' statement for the constraint:
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\True;
and then add the constraint option:
'constraints' => array(
new True()
),
finally found the solution!
to get rid of the extra fields i added those two fields in my form class:
$builder->add('recaptcha_challenge_field', 'hidden', array('property_path' => false));
$builder->add('recaptcha_response_field', 'hidden', array('property_path' => false));
the validation then works with:
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\True;
...
'constraints' => array(
new True()
)
the annotation doesn`t work for me:
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints AS Recaptcha;
...
/**
* #Recaptcha\True
*/
public $recaptcha;