I get the message:
Unable to found a valid admin for the class: Aman\VarshneyBundle\Entity\ArticleTable, get too many admin registered: sonata.admin.appsreview,sonata.admin.review,sonata.admin.article
I am not able to figure out this issue.
you have to specify "admin_code" option in your field definition
in your admin class while building your form
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('user', 'entity', array(), array(
'admin_code' => 'your.user.admin.service'
));
}
It only happens when you have multiple admin classes for the same entity.
I will put code with the use for the 'configureListFields' method, if it's usefull for someone.
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('filename', null, array('admin_code' => 'your.file.admin.service', 'label' => 'File Name'))
->add('parent', 'sonata_type_list', array('admin_code' => 'your.file.admin.service', 'label' => 'Parent File'))
->add('_action', 'actions', array(
'label' => 'Actions',
'actions' => array(
'download' => array(
'template' => 'FileAdminBundle:File:list__action_download.html.twig'
)
)
));
}
As we see, if we have multiple fields, we must put the 'admin_code' in all of them, excepts the actions (if we have it).
Hope it helps.
Related
When I submit the form. The value chosen from the dropdown list is successfully saved in the database.
The issue is when form is refresh in the edit mode, the value chosen for the brand is not retained.
Here is my configureFormFields:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('image', 'text')
->add('brand', EntityType::class, array(
'class' => Brand::class,
'choice_label' => 'slug',
))
->add('Page', ChoiceType::class, array(
'choices' => array(
'Homepage' => 'Homepage',
'HomeProduit' => 'Home Produit',
'HomeRubrique' => 'Home Rubrique',
'PageContent' => 'Page Content'
)))
;
}
I solved the issue.
The problem was that there was no relationship between the 2 tables (relationship added and everything works fine). Hope that can help someone some day.
I am using SonataAdminBundle for user administration. I would like to change roles on users. Currently my code in configureFormFields method is like this but roles are never updated and I don't know why.
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('roles', 'choice', array(
'choices' => array(
'ROLE_ADMIN' => 'ADMIN',
'ROLE_USER' => 'API USER',
),
'expanded' => false,
'multiple' => true,
'required' => false
))
->add('email')
->add('plainPassword', 'text', array('label' => 'Password', 'required' => false))
->end()
;
}
FOSUserBundle supports having multiple ROLES per user which is fine thing indeed. In my experience however, a common use case is a single role per user.
An easy way to manage this is to add the following method to your model/entity object to obtain a single role:
public function getRole() {
$role = $this->roles[0];
return $role;
}
Note: $role = $this->roles[0] will return the first ROLE in the database roles field. It may be that you need to choose the correct role with your own logic. Or, it may also be that you need to get the default role. If you use $this->getRoles() instead of $this->roles you have have the database roles plus the default role in the returned array.
Next you need to add a matching setter to allow you to save the single role per user. This implementation will work.
public function setRole($role) {
$this->setRoles(array($role));
}
Finally you will want to add a role field in your user form:
$builder->add('role', 'choice', array(
'choices' => array(
'ROLE_USER' => 'User',
'ROLE_ADMIN' => 'Admin',
'ROLE_SUPER_ADMIN' => 'Super Admin'
),
'multiple' => false
));
An important thing to note:
$builder->add('role'... : 'role' NOT 'roles'
If you will create labels exactly the same, as role - code will works just great. Something like
->add('roles', 'choice', array(
'choices' => array(
'ROLE_ADMIN' => 'ROLE_ADMIN',
'ROLE_USER' => 'ROLE_USER',
),
'expanded' => false,
'multiple' => true,
'required' => false
))
vendors version, which was tested with code above
doctrine/doctrine-bundle 1.8.1
friendsofsymfony/user-bundle 2.1.2
doctrine/orm 2.6.1
sonata-project/admin-bundle 3.33.0
sonata-project/doctrine-orm-admin-bundle 3.4.2
symfony/symfony 3.4.6
I'd like to add ckeditor to content field in block admin.
Here's what i did till now:
added raw_content and content_formatter properties to my block
modified buildEditForm in TextBlockService to this:
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
$formMapper->add('settings', 'sonata_type_immutable_array', array(
'keys' => array(
array('content', 'sonata_formatter_type', array(
'event_dispatcher' => $formMapper->getformBuilder()->getEventDispatcher(),
'format_field' => ['content_formatter'],
'source_field' => ['raw_content'],
'source_field_options' => array(
'attr' => array('class' => 'span10', 'rows' => 10)
),
'listener' => true,
'target_field' => ['content']
)),
)
));
}
It works just fine, allowing me to choose 'richhtml' from editors list but when i try to save the block it throws an error:
Expected argument of type "string or Symfony\Component\PropertyAccess\PropertyPathInterface", "NULL" given
How can i fix that?
here's how it should be to work:
$formMapper->add('settings', 'ckeditor', array());
I'm using Symfony 2.3 and newest SonataAdminBundle. It's possible to create editable fields in list view with SonataAdminBundle? What is the best practice?
Try this:
$listMapper
->addIdentifier('title')
->addIdentifier('artist')
->add('createDate')
->add('changeDate')
->add('missing', null, array('editable' => true))
->add('_action', 'actions', array(
'actions' => array(
'view' => array(),
'edit' => array(),
'delete' => array()
)
))
;
Notice the array('editable' => true). For booleans this works, I'm not sure for other fields.
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;