symfony-sonata

Symfony2 Sonata Admin show attribute only as a readyonly text

扶醉桌前 提交于 2019-12-03 02:44:23
I have some immutable attributes on my entity to administrate with sonata-admin bundle. I want to show them in the edit-view of the entity, but don't want to provide any mechanism to change it (e.g. the value shall not be inside a input field) I couldn't find anything but this: $formMapper ->add('post', 'entity', array( 'label' => 'Some post', 'attr' => array( 'readonly' => true, 'disabled' => true ), 'class' => 'Acme\DemoBundle\Entity\Post' ) ) ; I tried it out with read_only , readonly , disabled etc. all the stuff. It looks ok, it's now inside a dropdown (since it is an entity) and I can

SonataAdminBundle form field query

笑着哭i 提交于 2019-12-03 00:40:44
In SonataAdminBundle in Admin class I cannot make an orderBy on ManyToMany field . For example Author and Book. Author can have many books, as well as Book can have many Autors. In link above it is written that I can use a query for a form field. So I could prepare a query that would select authors and irder them by name. How to manage this? How to get EntityManager there in order to create query and pass it through query option? protected function configureFormFields(FormMapper $formMapper) { $formMapper ->add('name','text') ->add('author', 'sonata_type_model', array('query' => ....), array(

How can I create a custom DataGrid filter in SonataAdmin

隐身守侯 提交于 2019-12-03 00:38:12
I have an entity Transaction with numerous status codes. I want the user to be able to see these status codes as strings in SonataAdmin. The user should also be able to filter on the basis of these status codes. Entity Transaction { const TRANSACTION_STATUS_WAITING = 1; const TRANSACTION_STATUS_PENDING = 2; const TRANSACTION_STATUS_CONFIRMED = 3; /** * Set status * * @param smallint $status */ public function setStatus($status) { $this->status = $status; } /** * Get status * * @return smallint */ public function getStatus() { return $this->status; } public function getStatusAsString() { switch

How to display the current picture above the upload field in SonataAdminBundle?

孤街醉人 提交于 2019-12-02 19:09:33
I am using SonataAdminBundle (with Doctrine2 ORM) and I have successfully added a file upload feature to my Picture model. I would like, on the Show and Edit pages, to display a simple <img src="{{ picture.url }} alt="{{ picture.title }} /> tag just above the relevant form field (provided that the Picture being edited is not new, of course), so that the user may see the current photo, and decide whether to change it or not. After hours of research, I've been unable to figure out how to do it. I suppose I need to override some template, but I'm a bit lost... Can somebody give me a hint? Thank

Sonata Admin Bundle - Form type: sonata_type_collection - custom template?

牧云@^-^@ 提交于 2019-12-02 18:53:46
Is it possible to override the template for the form type: "sonata_type_collection"? Ive tried along these lines: $formMapper->add('slides', 'sonata_type_collection', array(), array( 'edit' => 'inline', 'inline' => 'table', 'sortable' => 'priority', 'template' => 'MyBundle:Form:slides.admin.html.twig' )); but to no avail. I know I could override the entire template, but I only want to do it for this form, not all the places where I use this form type. Does anyone know if this is possible? Thanks I found a great bit of code in /vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Form

Symfony2 - override template bundle

核能气质少年 提交于 2019-12-01 23:29:19
问题 I want to override the default SonataAdmin Template. I create a standard_layout.html.twig in my Namespace/bundle/resources/views (same structur, same file name, same content) I copied all the content of the source template in my target template, i just edit some part of the target off course....and nothing thanks for your help Bye 回答1: You have the solution of bundle heritance http://symfony.com/doc/current/cookbook/bundles/inheritance.html which allows, not only override templates but

Symfony2 - override template bundle

北城以北 提交于 2019-12-01 20:32:37
I want to override the default SonataAdmin Template. I create a standard_layout.html.twig in my Namespace/bundle/resources/views (same structur, same file name, same content) I copied all the content of the source template in my target template, i just edit some part of the target off course....and nothing thanks for your help Bye You have the solution of bundle heritance http://symfony.com/doc/current/cookbook/bundles/inheritance.html which allows, not only override templates but methods too. Or you have http://symfony.com/doc/2.0/book/templating.html#overriding-bundle-templates which

setting default value in symfony2 sonata admin bundle

时光毁灭记忆、已成空白 提交于 2019-11-30 03:45:53
how can i set default value in sonata admin bundle the data option is missing in configureFormFields method protected function configureFormFields(FormMapper $formMapper) { $formMapper ->add('name', null, array('required' => true, 'data' => "my default value")) ; } how can use data attribute to set default value inside field ??? I presume you've probably already solved this by now, but as a reference to anyone else you can override the getNewInstance() method and set the default value on the object: public function getNewInstance() { $instance = parent::getNewInstance(); $instance->setName('my

Sonata Admin - Only allow show what logged in user has created

谁说胖子不能爱 提交于 2019-11-30 00:58:58
I've setup a sonata admin interface which allows users to create specific content, but how do I restrict users from editing content created by other users? For arguments sake, a user logs in and creates a blog. In the list view of blogs, only the blogs that user created should be displayed. Currently, everything is displayed to every user - I do have groups/roles setup to restrict access to admin areas, which works fine. The only way I can currently think of only show a specific logged in users content, is to override the templates? But, surely, this is an obvious and simple configuration

Sonata admin bundle order

一个人想着一个人 提交于 2019-11-29 05:54:52
How to change default entity order in SonataAdminBundle for list action? answer :) add this to your admin class protected $datagridValues = array( '_page' => 1, '_sort_order' => 'DESC', // sort direction '_sort_by' => 'id' // field name ); pilot You can add another sort order or set a default one via the constructor like this: public function __construct($code, $class, $baseControllerName) { parent::__construct($code, $class, $baseControllerName); if (!$this->hasRequest()) { $this->datagridValues = array( '_page' => 1, '_sort_order' => 'ASC', // sort direction '_sort_by' => 'artist_id' //