<commit_before>Defining admin class
====================

The admin class contains all the information required to generate the CRUD
interface. Let's create the Post Admin class.

PostAdmin
---------

By convention, Admin files are located in an Admin namespace.

First, you need to create an Admin/PostAdmin.php file

.. code-block:: php

    <?php
    // src/Tutorial/BlogBundle/Admin/PostAdmin.php
    namespace Tutorial\BlogBundle\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 Knp\Menu\ItemInterface as MenuItemInterface;

    use Tutorial\BlogBundle\Entity\Comment;

    class PostAdmin extends Admin
    {
        /**
         * @param \Sonata\AdminBundle\Show\ShowMapper $showMapper
         *
         * @return void
         */
        protected function configureShowField(ShowMapper $showMapper)
        {
            $showMapper
                ->add('enabled')
                ->add('title')
                ->add('abstract')
                ->add('content')
                ->add('tags')
            ;
        }

        /**
         * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
         *
         * @return void
         */
        protected function configureFormFields(FormMapper $formMapper)
        {
            $formMapper
                ->with('General')
                    ->add('enabled', null, array('required' => false))
                    ->add('title')
                    ->add('abstract')
                    ->add('content')
                ->end()
                ->with('Tags')
                    ->add('tags', 'sonata_type_model', array('expanded' => true, 'multiple' => true))
                ->end()
                ->with('Comments')
                    ->add('comments', 'sonata_type_model', array('multiple' => true))
                ->end()
                ->with('System Information', array('collapsed' => true))
                    ->add('created_at')
                ->end()
            ;
        }

        /**
         * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
         *
         * @return void
         */
        protected function configureListFields(ListMapper $listMapper)
        {
            $listMapper
                ->addIdentifier('title')
                ->add('enabled')
                ->add('abstract')
                ->add('content')
                ->add('tags')
                ->add('_action', 'actions', array(
                    'actions' => array(
                        'view' => array(),
                        'edit' => array(),
                        'delete' => array(),
                    )
                ))<commit_msg>Update deprecated view action<commit_after>Defining admin class
====================

The admin class contains all the information required to generate the CRUD
interface. Let's create the Post Admin class.

PostAdmin
---------

By convention, Admin files are located in an Admin namespace.

First, you need to create an Admin/PostAdmin.php file

.. code-block:: php

    <?php
    // src/Tutorial/BlogBundle/Admin/PostAdmin.php
    namespace Tutorial\BlogBundle\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 Knp\Menu\ItemInterface as MenuItemInterface;

    use Tutorial\BlogBundle\Entity\Comment;

    class PostAdmin extends Admin
    {
        /**
         * @param \Sonata\AdminBundle\Show\ShowMapper $showMapper
         *
         * @return void
         */
        protected function configureShowField(ShowMapper $showMapper)
        {
            $showMapper
                ->add('enabled')
                ->add('title')
                ->add('abstract')
                ->add('content')
                ->add('tags')
            ;
        }

        /**
         * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
         *
         * @return void
         */
        protected function configureFormFields(FormMapper $formMapper)
        {
            $formMapper
                ->with('General')
                    ->add('enabled', null, array('required' => false))
                    ->add('title')
                    ->add('abstract')
                    ->add('content')
                ->end()
                ->with('Tags')
                    ->add('tags', 'sonata_type_model', array('expanded' => true, 'multiple' => true))
                ->end()
                ->with('Comments')
                    ->add('comments', 'sonata_type_model', array('multiple' => true))
                ->end()
                ->with('System Information', array('collapsed' => true))
                    ->add('created_at')
                ->end()
            ;
        }

        /**
         * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
         *
         * @return void
         */
        protected function configureListFields(ListMapper $listMapper)
        {
            $listMapper
                ->addIdentifier('title')
                ->add('enabled')
                ->add('abstract')
                ->add('content')
                ->add('tags')
                ->add('_action', 'actions', array(
                    'actions' => array(
                        'show' => array(),
                        'edit' => array(),
                        'delete' => array(),
                    )
                ))
{'fraction_non_alphanumeric': 0.13000702740688685, 'fraction_numerical': 0.0, 'mean_word_length': 1.445446735395189, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5541760', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1379, 'n_words': 297}