sonata-admin

Getting instance of container in custom sonata block

感情迁移 提交于 2019-11-28 05:54:57
问题 I am creating a custom block for dashboard and where I want to display information persisted into the DB. How do I get an instance of the container or doctrine entity manager in the block service? Tried googling alot but nothing substantial has come out so far 回答1: When you create a new block in sonata, you have to declare it like a service, so you can inject doctrine.orm.entity_manager . I can show you an example of a block where I injected the entity manager: //My\Bundle\Block

SonataAdminBundle : display non crud (statistics)

偶尔善良 提交于 2019-11-28 03:20:55
I'm using sonata admin bundle to generate my backend, I'm so happy with it that I would like to use my backend to display statistics as well. I guess I can do that by tweaking bundle's views, "standard_layout.html.twig" maybe. Problem is, I can't find examples or even people speaking about it, so I'm wondering, is that possible ? Aren't people speaking about it because it's too simple ? Did you do it ? I really would like to have a single backend, so pls enlighten me ! Thank you, copndz Yes, it`s possible. It can be done with Sonata Block or using your own controller. If you use your

How to print translatable data in sonata admin with DoctrineBehaviors from kpnlabs

为君一笑 提交于 2019-11-28 00:32:53
I'm just looking the good way to use DoctrineBehaviors by knplabs. I have allready render a form in sonata admin bundle with the help of this bundle : https://github.com/a2lix/TranslationFormBundle Now, i want to have my translated field in the admin list. At this time, it's work with this method: /** * @ORM\Entity * @ORM\Table(name="sport") */ class Sport { ... public function getNom(){ return $this->translate()->getNom(); } } It's work but, i have to remap all the translated field in the original entity. I'm pretty sure i'm missing something, particularly with the magic of the proxy

Sonata admin bundle order

不问归期 提交于 2019-11-27 23:26:27
问题 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 ); 回答1: 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-

Correct way to use FormEvents to customise fields in SonataAdmin

≯℡__Kan透↙ 提交于 2019-11-27 18:50:24
问题 I have a Sonata Admin class with some form fields in it, but I'd like to use the FormEvents::PRE_SET_DATA event to dynamically add another form field based on the bound data. However, I'm running into several problems: 1) The only way I can find to add the form field to the correct 'formGroup' in the admin is by adding the new field twice (once via the formMapper and once via the form itself)... this seems very wrong and I cannot control where in the formGroup it appears. 2) The added element

Add custom button to edit page of sonata admin bundle

 ̄綄美尐妖づ 提交于 2019-11-27 16:30:00
问题 As you know, sonata admin bundle comes with three buttons in edit page which are "Add new, update and delete". I can remove delete button with this: protected function configureRoutes(RouteCollection $collection) { $collection ->remove('delete') ; } But I want to also add "Send message to User" button in edit of UserAdmin. How can I do this? I can't find any documentation about that in sonata docs. 回答1: You should hint the parameter if the file is in other namespace, and the add() method

Symfony2 1:M / 1:1 Relationship and Sonata Admin Form

夙愿已清 提交于 2019-11-27 15:24:07
问题 I've hitting my head against the wall for countless hours now and I hope SO can be of help! I have Retailer, Branch and RetailerBranches entities which work just fine, retailers can have many branches and a branch can only have one retailer. The hard part happens when trying to make Sonata Admin (SonataAdminBundle) play nice with that relationship. In their simplest form, they look like this: Retailer entity /** * @ORM\Column(name="ID", type="integer", nullable=false) * @ORM\Id * @ORM

How to add custom link or button to SonataAdminBundle Dashboard in Symfony2

╄→尐↘猪︶ㄣ 提交于 2019-11-27 10:49:01
I am new with symfony2 and SonataAdminBundle. I have added 3 entities to the SonataAdminBundle Dashboard and they appear successfully. The Entities appear with the default links - "Add new" and "List" buttons. I want to be able to do the following I want to add a third link to one of the entities on the dashboard. I want to be able to add a link to the buttons located above the grid in the default list page. I want to be able to add/customize links appearing under the form on Edit or Create new page I have not been able to find a way to do any of the above, been searching for hours, any help

Sonata Admin Bundle: DatePicker range

本小妞迷上赌 提交于 2019-11-27 01:33:21
问题 How would I create a doctrine_orm_datetime_range filter in the Sonata Admin Bundle which uses the jQuery UI datepicker? I tried the following, but it doesn't work: protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $datagridMapper ->add('datumUitgevoerd', 'doctrine_orm_datetime', array('widget' => 'single_text'), null, array('required' => false, 'attr' => array('class' => 'datepicker'))) ; } 回答1: UPDATED 2016-02-02 If you are using 3.* Symfony the following twig

How to use Ajax within Sonata Admin forms?

懵懂的女人 提交于 2019-11-26 23:53:20
I have a Merchant entity with the following fields and associations:- /** * @ORM\ManyToMany(targetEntity="Category", inversedBy="merchants") */ public $categories; /** * @ORM\ManyToMany(targetEntity="Tag", inversedBy="merchants") */ public $tags; /** * @ORM\ManyToOne(targetEntity="Category", inversedBy="merchants") */ protected $primaryCategory; /** * @ORM\ManyToOne(targetEntity="Tag", inversedBy="merchants") */ protected $primaryTag; The Tags and Categories also have a ManyToMany mapping. So we have Tag_Category, Merchant_Tag, Merchant_Category mapping tables. Now I want to perform some ajax