Showing posts with label SonataAdminBundle. Show all posts
Showing posts with label SonataAdminBundle. Show all posts

Monday, June 11, 2012

Sonata AdminBundle: How to create a custom field

I wanted to create a custom field that is not in the database for the listFields so I searched the web how do it. Here is how I have done it:


class Entity 
{
    ...
    //custom getter
    public function getFullName()
    {
        return $this->getFirstName() . ' ' . $this->getLastName();
    }
}


In your EntityAdmin:

 protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
           ->add('fullName', 'doctrine_orm_string')
            ->add('_action', 'actions', array(
                'actions' => array(
                    'view' => array(),
                    'edit' => array(),
                    'delete' => array(),
                )
            ))
        ;
    }

Sunday, June 10, 2012

Sonata Admin Bundle error:configureShowFields

If you get this two errors:
[2/2] FileLoaderLoadException: Cannot import resource "C:\wamp\www\project\app/config\." from "C:\wamp\www\project\app/config\routing.yml".  -+

[1/2] ErrorException: Runtime Notice: Declaration of Company\NameBundle\Admin\EntityAdmin::configureShowFields() should be compatible with that of Sonata\AdminBundle\Admin\Admin::configureShowFields() in C:\wamp\www\havefun\src\Company\NameBundle\Admin\EntityAdmin.php line 84  -

Check if you included the ShowMapper class like this:
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;

protected function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
            ->add('name')
            ->add('email')
        ;
    }

Saturday, June 9, 2012

SonataAdminBundle weird breadcrumbs

If you installed SonataAdminBundle and your breadcrumbs look like this 0/1/ then the solution to this problem is to reinstall the KnpMenuBundle, but the 1.1.0 version, you can find it on git . Add this to your deps file:
[MenuBundle]
git=https://github.com/KnpLabs/KnpMenuBundle.git
target=/bundles/Knp/Bundle/MenuBundle
version=v1.1.0

[KnpMenu]
git=https://github.com/KnpLabs/KnpMenu.git
target=/knp/menu
version=v1.1.1
  
But before running the command  php bin/vendors install --reinstall  make sure you comment the
'Knp\Menu'   => __DIR__.'/../vendor/knp/menu/src',
    'Knp\Bundle' => __DIR__.'/../vendor/bundles',

in the app/autoload.php file

and comment  the
new Knp\Bundle\MenuBundle\KnpMenuBundle(),

line in the app/AppKernel.php file

Also you might have to comment the:
   lines of code in app/config
      sonata_admin:
    title:      HungryCoders
    title_logo: bundles/sonataadmin/logo_title.png
    templates:
        # default global templates
        layout:  SonataAdminBundle::standard_layout.html.twig
        ajax:    SonataAdminBundle::ajax_layout.html.twig

        # default actions templates, should extend a global templates
        list:    SonataAdminBundle:CRUD:list.html.twig
        show:    SonataAdminBundle:CRUD:show.html.twig
        edit:    SonataAdminBundle:CRUD:edit.html.twig
    dashboard:
        blocks:
            # display a dashboard block
            - { position: left, type: sonata.admin.block.admin_list }

...


services:           
    sonata.admin.product:
        class: Demo\TestBundle\Admin\ProductAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: demo, label: Products }
        arguments: [null, Demo\TestBundle\Entity\Product, DemoTestBundle:ProductAdmin]

Now you can run the command to install the vendors, and UnComment the code in app/autoload.php, app/AppKernel.php and app/config/config.yml. Now your breadcrumb should look good.

Monday, May 21, 2012

Installing Sonata Bundle Error

If you get the next error when using Sonata Admin Bundle you should use the Sonata Admin Bundle 2.0 branch.

Fatal error: Declaration of Sonata\AdminBundle\Form\Extension\Field\Type\FormTypeFieldExtension::getDefaultOptions() must be compatible with that of Symfony\Component\Form\FormTypeExtensionInterface::getDefaultOptions() in /var/www/pulpower.spotymedia.com/vendor/bundles/Sonata/AdminBundle/Form/Extension/Field/Type/FormTypeFieldExtension.php on line 186

 Clear the deps file and copy the next code

[SonataAdminBundle]
    git=git://github.com/sonata-project/SonataAdminBundle.git
    target=/bundles/Sonata/AdminBundle
    version=origin/2.0

run the command php bin/vendors install -reinstall

Now everything should work.

https://github.com/sonata-project/SonataAdminBundle/issues/679

Sunday, May 20, 2012

Installing SonataAdminBundle Error

If you get the next error when installing SonataAlbumBundle:
The child node "default_contexts" at path "sonata_block" must be configured.

Then you should include this code in your app/config/config.yml file
 # app/config/config.yml
sonata_block:
    default_contexts: [cms]
    blocks:
        sonata.admin.block.admin_list:
            contexts:   [admin]

        #sonata.admin_doctrine_orm.block.audit:
        #    contexts:   [admin]

        sonata.block.service.text:
        sonata.block.service.action:
        sonata.block.service.rss:

        # Some specific block from the SonataMediaBundle
        #sonata.media.block.media:
        #sonata.media.block.gallery:
        #sonata.media.block.feature_media: