Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Symfony 4 ] Sonata Blocks

    2 juillet 2020 à 11:26:05

    Bonjour,

    J'essaye de faire marcher le bundle Sonata avec les blocks. Donc pour commencer je voulais tester avec un block existant. Dans mon profileController je fais

        public function showAction()
        {
            $user = $this->getUser();
    
            if (!is_object($user) || (!$user instanceof FOSUserInterface && !$user instanceof LDapUserInterface)) {
                throw $this->createAccessDeniedException('This user does not have access to this section.');
            }
    
            return $this->render('bundles/ApplicationSonataUserBundle/Profile/show.html.twig', array(
                'user' => $user,
                'blocks' => $this->getParameter('sonata.admin.block.admin_list'),
            ));
        }
    

    Mais j'ai l'erreur:

    The parameter "sonata.admin.block.admin_list" must be defined.

    Ce que je ne comprends pas. Voici mes configs:

    sonata_user.yaml

    sonata_user:
      security_acl: true
      manager_type: orm # can be orm or mongodb
    
      class:
        user: App\Entity\User
        group: App\Entity\Group
      impersonating:
        route: sonata_admin_dashboard
        parameters:  { path: / }
    
      profile:
        default_avatar: 'bundles/sonatauser/default_avatar.png' # Default avatar displayed if the user doesn't have one
    

    sonata_block.yaml

    sonata_block:
      blocks:
        sonata.admin.block.admin_list:
        sonata.admin.block.search_result:
    

    sonata_admin.yaml

    sonata_admin:
        title: Intranet XXX
    
        security:
            # the default value
            #handler: sonata.admin.security.handler.role
    
            # use this service if you want ACL
            handler: sonata.admin.security.handler.acl
    
            information:
                GUEST:    [VIEW, LIST]
                STAFF:    [EDIT, LIST, CREATE]
                EDITOR:   [OPERATOR, EXPORT]
                ADMIN:    [MASTER]
            # permissions not related to an object instance and also to be available when objects do not exist
            # the DELETE admin permission means the user is allowed to batch delete objects
            admin_permissions: [CREATE, LIST, DELETE, UNDELETE, EXPORT, OPERATOR, MASTER]
    
            # permission related to the objects
            object_permissions: [VIEW, EDIT, DELETE, UNDELETE, OPERATOR, MASTER, OWNER]
    
        dashboard:
            blocks:
                # display a dashboard block
                - { position: left, type: algam.intranet.service.user_last_posts, settings: { } }
                - { position: right, type: algam.intranet.service.user_last_comments, settings: { } }
                - { position: left, type: sonata.block.service.text, settings: { content: "<h2>Bonjour</h2>"} }
                - { position: left, type: sonata.order.block.recent_orders, settings: { title: Recent Orders, number: 5, mode: public }}
                - { position: right, type: sonata.timeline.block.timeline, settings: { max_per_page: 15 }}
                - { position: right, type: sonata.news.block.recent_posts, settings: { title: Recent Posts, number: 5, mode: public }}
                - { position: right, type: sonata.news.block.recent_comments, settings: { title: Recent Comments, number: 5, mode: public }}
    
    


    Et enfin dans block.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
        <services>
            <service id="sonata.admin.block.admin_list" class="Sonata\AdminBundle\Block\AdminListBlockService" public="true">
                <tag name="sonata.block"/>
                <argument type="service" id="twig"/>
                <!-- NEXT_MAJOR: Remove "null" argument -->
                <argument>null</argument>
                <argument type="service" id="sonata.admin.pool"/>
                <argument type="service" id="sonata.admin.global_template_registry"/>
            </service>
       </services>
    </container>
    

    Pour moi mon block est bien défini mais pourtant ça ne marche pas. Quelqu'un a une idée? C'est très compliqué de trouver des tutos sur Internet et je galère depuis 2 jours :/ Merci

    PS: Sinon j'ai essayé le sonata_block_render de cette façon

    {{ sonata_block_render({ 'type': 'sonata.admin.block.admin_list' }) }}

    Mais rien ne s'affiche, pas d'erreur par contre.


    EDIT: J'ai essayé de faire un use de la classe correspondant au service et je le met en paramètre de ma fonction showAction:

    use Sonata\AdminBundle\Block\AdminListBlockService;
    
    public function showAction(AdminListBlockService $admin){}
    
    
    

    Et j'ai cette erreur

    Cannot autowire argument $admin of "App\Controller\ProfileFOSUser1Controller::showAction()": it references class "Sonata\AdminBundle\Block\AdminListBlockService" but no such service exists. You should maybe alias this class to the existing "sonata.admin.block.admin_list" service.

    -
    Edité par Akame14 2 juillet 2020 à 14:44:19

    • Partager sur Facebook
    • Partager sur Twitter

    [Symfony 4 ] Sonata Blocks

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown