plugin/claco-form/Listener/Resource/ClacoFormListener.php
public function onLoad(LoadResourceEvent $event)
    {
        /** @var ClacoForm $clacoForm */
        $clacoForm = $event->getResource();
        $user = $this->tokenStorage->getToken()->getUser();
        $isAnon = 'anon.' === $user;
        $myEntries = $isAnon ? [] : $this->clacoFormManager->getUserEntries($clacoForm, $user);
        $canGeneratePdf = !$isAnon &&
            $this->platformConfigHandler->hasParameter('knp_pdf_binary_path') &&
            file_exists($this->platformConfigHandler->getParameter('knp_pdf_binary_path'));
        $cascadeLevelMax = $this->platformConfigHandler->hasParameter('claco_form_cascade_select_level_max') ?
            $this->platformConfigHandler->getParameter('claco_form_cascade_select_level_max') :
            2;
        $roles = [];
        $roleUser = $this->roleManager->getRoleByName('ROLE_USER');
        $roleAnonymous = $this->roleManager->getRoleByName('ROLE_ANONYMOUS');
        $workspaceRoles = $this->roleManager->getWorkspaceRoles($clacoForm->getResourceNode()->getWorkspace());
        $roles[] = $this->serializer->serialize($roleUser, [Options::SERIALIZE_MINIMAL]);
        $roles[] = $this->serializer->serialize($roleAnonymous, [Options::SERIALIZE_MINIMAL]);

        foreach ($workspaceRoles as $workspaceRole) {
            $roles[] = $this->serializer->serialize($workspaceRole, [Options::SERIALIZE_MINIMAL]);
        }
        $myRoles = $isAnon ? [$roleAnonymous->getName()] : $user->getRoles();

        $event->setData([
            'clacoForm' => $this->serializer->serialize($clacoForm),
            'canGeneratePdf' => $canGeneratePdf,
            'cascadeLevelMax' => $cascadeLevelMax,
            'myEntriesCount' => count($myEntries),
            'roles' => $roles,
            'myRoles' => $myRoles,
        ]);
        $event->stopPropagation();
    }
public function onLoad(LoadResourceEvent $event)
    {
        /** @var ClacoForm $clacoForm */
        $clacoForm = $event->getResource();
        $user = $this->tokenStorage->getToken()->getUser();
        $isAnon = 'anon.' === $user;
        $myEntries = $isAnon ? [] : $this->clacoFormManager->getUserEntries($clacoForm, $user);
        $canGeneratePdf = !$isAnon &&
            $this->platformConfigHandler->hasParameter('knp_pdf_binary_path') &&
            file_exists($this->platformConfigHandler->getParameter('knp_pdf_binary_path'));
        $cascadeLevelMax = $this->platformConfigHandler->hasParameter('claco_form_cascade_select_level_max') ?
            $this->platformConfigHandler->getParameter('claco_form_cascade_select_level_max') :
            2;
        $roles = [];
        $roleUser = $this->roleManager->getRoleByName('ROLE_USER');
        $roleAnonymous = $this->roleManager->getRoleByName('ROLE_ANONYMOUS');
        $workspaceRoles = $this->roleManager->getWorkspaceRoles($clacoForm->getResourceNode()->getWorkspace());
        $roles[] = $this->serializer->serialize($roleUser, [Options::SERIALIZE_MINIMAL]);
        $roles[] = $this->serializer->serialize($roleAnonymous, [Options::SERIALIZE_MINIMAL]);

        foreach ($workspaceRoles as $workspaceRole) {
            $roles[] = $this->serializer->serialize($workspaceRole, [Options::SERIALIZE_MINIMAL]);
        }
        $myRoles = $isAnon ? [$roleAnonymous->getName()] : $user->getRoles();

        $event->setData([
            'clacoForm' => $this->serializer->serialize($clacoForm),
            'canGeneratePdf' => $canGeneratePdf,
            'cascadeLevelMax' => $cascadeLevelMax,
            'myEntriesCount' => count($myEntries),
            'roles' => $roles,
            'myRoles' => $myRoles,
        ]);
        $event->stopPropagation();
    }
public function onLoad ( LoadResourceEvent $ event ) { /** @var ClacoForm $clacoForm */ $ clacoForm = $ event -> getResource ( ) ; $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; $ isAnon = 'anon.' === $ user ; $ myEntries = $ isAnon ? [ ] : $ this -> clacoFormManager -> getUserEntries ( $ clacoForm , $ user ) ; $ canGeneratePdf = ! $ isAnon && $ this -> platformConfigHandler -> hasParameter ( 'knp_pdf_binary_path' ) && file_exists ( $ this -> platformConfigHandler -> getParameter ( 'knp_pdf_binary_path' ) ) ; $ cascadeLevelMax = $ this -> platformConfigHandler -> hasParameter ( 'claco_form_cascade_select_level_max' ) ? $ this -> platformConfigHandler -> getParameter ( 'claco_form_cascade_select_level_max' ) : 2 ; $ roles = [ ] ; $ roleUser = $ this -> roleManager -> getRoleByName ( 'ROLE_USER' ) ; $ roleAnonymous = $ this -> roleManager -> getRoleByName ( 'ROLE_ANONYMOUS' ) ; $ workspaceRoles = $ this -> roleManager -> getWorkspaceRoles ( $ clacoForm -> getResourceNode ( ) -> getWorkspace ( ) ) ; $ roles [ ] = $ this -> serializer -> serialize ( $ roleUser , [ Options :: SERIALIZE_MINIMAL ] ) ; $ roles [ ] = $ this -> serializer -> serialize ( $ roleAnonymous , [ Options :: SERIALIZE_MINIMAL ] ) ; foreach ( $ workspaceRoles as $ workspaceRole ) { $ roles [ ] = $ this -> serializer -> serialize ( $ workspaceRole , [ Options :: SERIALIZE_MINIMAL ] ) ; } $ myRoles = $ isAnon ? [ $ roleAnonymous -> getName ( ) ] : $ user -> getRoles ( ) ; $ event -> setData ( [ 'clacoForm' => $ this -> serializer -> serialize ( $ clacoForm ) , 'canGeneratePdf' => $ canGeneratePdf , 'cascadeLevelMax' => $ cascadeLevelMax , 'myEntriesCount' => count ( $ myEntries ) , 'roles' => $ roles , 'myRoles' => $ myRoles , ] ) ; $ event -> stopPropagation ( ) ; }
Loads the ClacoForm resource.

@DI\Observe("resource.claroline_claco_form.load")

@param LoadResourceEvent $event
Loads the ClacoForm resource .