Closed DILL44 closed 11 years ago
I add a custom field in post:
in /vendor/bundles/Sonata/NewsBundle/Resources/config/doctrine/Post.orm.xml.skeleton I add my custom field
<?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <!-- This file has been generated by the EasyExtends bundle ( http://sonata-project.org/easy-extends ) References : xsd : https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd xml mapping : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/xml-mapping/en association mapping : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/association-mapping/en --> <entity name="Application\Sonata\NewsBundle\Entity\Post" table="news__post" repository-class="Application\Sonata\NewsBundle\Entity\PostRepository"> <id name="id" type="integer" column="id"> <generator strategy="AUTO"/> </id> <one-to-one field="podcast" target-entity="RadioSolution\PodcastBundle\Entity\Podcast" inversed-by="Application\Sonata\NewsBundle\Entity\Post"> <join-column name="podcast_id" referenced-column-name="id" /> </one-to-one> </entity> </doctrine-mapping>
I create a custom admin class
<?php namespace Application\Sonata\NewsBundle\Admin; use Sonata\AdminBundle\Admin\Admin; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Show\ShowMapper; use Sonata\FormatterBundle\Formatter\Pool as FormatterPool; use Sonata\NewsBundle\Admin\PostAdmin as BaseAdmin; use Knp\Menu\ItemInterface as MenuItemInterface; use Application\Sonata\NewsBundle\Entity\Comment; class PostAdmin extends BaseAdmin { /** * {@inheritdoc} */ protected function configureFormFields(FormMapper $formMapper) { $formMapper ->with('General') ->add('enabled', null, array('required' => false)) ->add('author', 'sonata_type_model', array(), array('edit' => 'list')) ->add('category', 'sonata_type_model', array(), array('edit' => 'list')) ->add('title') ->add('abstract') ->add('contentFormatter', 'sonata_formatter_type_selector', array( 'source' => 'rawContent', 'target' => 'content' )) ->add('rawContent','textarea', array('attr' => array('class' => 'tinymce', 'tinymce'=>'{"theme":"medium"}'))) ->end() ->with('podcast') ->add('podcast','sonata_type_model', array('required' => false)) ->end() ->with('Tags') ->add('tags', 'sonata_type_model', array('expanded' => true)) ->end() ->with('Options') ->add('publicationDateStart') ->add('commentsCloseAt') ->add('commentsEnabled', null, array('required' => false)) ->add('commentsDefaultStatus', 'choice', array('choices' => Comment::getStatusList(), 'expanded' => true)) ->end() ; } }
I declare my service:
services: sonata.news.admin.post: class: Application\Sonata\NewsBundle\Admin\PostAdmin tags: - { name: sonata.admin,manager_type: orm, group:"sonata_blog", label:"posts", label_catalogue:"%sonata.news.admin.post.translation_domain%", label_translator_strategy:"sonata.admin.label.strategy.underscore"} arguments: [null,Application\Sonata\NewsBundle\Entity\Post, SonataAdminBundle:CRUD]
but I get an error when I edit a post
An exception has been thrown during the rendering of a template ("unable to find the routesonata.news.admin.post|sonata.news.admin.comment.list") in SonataAdminBundle::standard_layout.html.twig at line 18.
sonata.news.admin.post|sonata.news.admin.comment.list
you can see my project https://github.com/DILL44/euradio/tree/master
I overwrite
protected function configureSideMenu(MenuItemInterface $menu, $action, Admin $childAdmin = null) {}
in Application\Sonata\NewsBundle\Admin\PostAdmin.php and it's work!!!
I add a custom field in post:
in /vendor/bundles/Sonata/NewsBundle/Resources/config/doctrine/Post.orm.xml.skeleton I add my custom field
I create a custom admin class
I declare my service:
but I get an error when I edit a post
An exception has been thrown during the rendering of a template ("unable to find the route
sonata.news.admin.post|sonata.news.admin.comment.list
") in SonataAdminBundle::standard_layout.html.twig at line 18.you can see my project https://github.com/DILL44/euradio/tree/master