symfony-sonata

setting default value in symfony2 sonata admin bundle

倖福魔咒の 提交于 2019-11-29 00:54:01
问题 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 ??? 回答1: 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

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

懵懂的女人 提交于 2019-11-29 00:40:11
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\GeneratedValue(strategy="IDENTITY") */ private $id; /** * Relation * * @ORM\OneToMany(targetEntity=

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

三世轮回 提交于 2019-11-28 21:42:01
问题 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

Sonata Admin Bundle: DatePicker range

三世轮回 提交于 2019-11-28 06:51:48
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'))) ; } pulzarraider UPDATED 2016-02-02 If you are using 3.* Symfony the following twig configuration must be used: # app/config/config.yml twig: # ... form_themes: - 'SonataCoreBundle

Doctrine inserting in postPersist event

和自甴很熟 提交于 2019-11-28 04:01:04
I want add new Feed item on entity persist and update. I write this event listener (postUpdate is same): public function postPersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); $em = $args->getEntityManager(); if ($entity instanceof FeedItemInterface) { $feed = new FeedEntity(); $feed->setTitle($entity->getFeedTitle()); $feed->setEntity($entity->getFeedEntityId()); $feed->setType($entity->getFeedType()); if($entity->isFeedTranslatable()) { $feed->getEnTranslation()->setTitle($entity->getFeedTitle('en')); } $em->persist($feed); $em->flush(); } } But I got Integrity constraint

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-

Annotations in extended Sonata user class not being read

点点圈 提交于 2019-11-27 18:33:11
问题 I extended the user bundle from the Sonata project with Sonata EasyExtends bundle. It is placed under src/Application/Sonata/UserBundle by default Now I want to customize the extended class and add some fields. I notice though that annotations are not being processed, I need to define the mappings in src/Application/Sonata/UserBundle/Resources/config/doctrine/User.orm.xml Is there any way to make use of the annotations instead of the XML file? I think it will solve a lot of my problems with

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

Doctrine inserting in postPersist event

南笙酒味 提交于 2019-11-27 05:15:28
问题 I want add new Feed item on entity persist and update. I write this event listener (postUpdate is same): public function postPersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); $em = $args->getEntityManager(); if ($entity instanceof FeedItemInterface) { $feed = new FeedEntity(); $feed->setTitle($entity->getFeedTitle()); $feed->setEntity($entity->getFeedEntityId()); $feed->setType($entity->getFeedType()); if($entity->isFeedTranslatable()) { $feed->getEnTranslation()->setTitle(

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