@Observe("create_form_activity")

@param CreateFormResourceEvent $event
192669
public function onCreateForm(CreateFormResourceEvent $event)
    {
        $form = $this->formFactory->create(new ActivityType(), new Activity());
        $content = $this->templating->render(
            'ClarolineCoreBundle:Resource:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => 'activity'
            )
        );
        $event->setResponseContent($content);
        $event->stopPropagation();
    }
598279
public function onPreSubmitData(FormEvent $event)
    {
        $data = $event->getData();
        if (!array_key_exists('site_root', $data) || false === (bool)$data['site_root']) {
            $location = $this->locationService->loadLocation($data['location']);
            if (1 >= $location->depth) {
                return;
            }
            $parentLocation = $this->locationService->loadLocation($location->parentLocationId);
            $urlAlias = $this->urlAliasService->reverseLookup($parentLocation);
            $data['path'] = $urlAlias->path . '/' . $data['path'];
            $event->setData($data);
        }
    }
398175
public function postSubmit(FormEvent $event)
    {
        $image = $event->getData();

        if ($image && $image->hasFile()) {
            $image->setPath(null);
        }
    }
1289697
public function onPreSetData(FormEvent $event)
    {
        $form = $event->getForm();
        if ($this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
            $roles = [
                'User' => 'ROLE_USER',
                'Admin' => 'ROLE_ADMIN',
                'Super admin' => 'ROLE_SUPER_ADMIN',
            ];
            $form
                ->add(
                    'roles',
                    ChoiceType::class,
                    [
                        'label' => 'Roles',
                        'required' => true,
                        'expanded' => true,
                        'multiple' => true,
                        'choices' => $roles,
                    ]
                );
        }
    }
714591
public function onFileChange(ResourceActionEvent $event)
    {
        $parameters = $event->getData();
        $node = $event->getResourceNode();

        $resource = $this->resourceManager->getResourceFromNode($node);

        if ($resource) {
            $resource->setHashName($parameters['file']['hashName']);
            $this->om->persist($resource);
            $this->om->flush();
        }

        $event->setResponse(new JsonResponse($this->serializer->serialize($node)));
    }
994054
public function addPublishMessage(FormActionEvent $event)
    {
        if (!$this->isAdminSiteAccess($this->requestStack->getCurrentRequest())) {
            return;
        }
        $this->notificationHandler->success(
            $this->translator->trans(
                /** @Desc("Content published.") */
                'content.published.success',
                [],
                'content_edit'
            )
        );
    }
1347801
public function onPostBind(FormEvent $event)
    {
        $form = $event->getForm();

        $request = $this->container->get('request');
        if (!$request->request->has(Autocomplete::KEY_PATH)) {
            return;
        }

        $name = $request->request->get(Autocomplete::KEY_PATH);
        $parts = $this->parseNameIntoParts($name, $form->getRoot()->getName());

        $field = $form->getRoot();
        foreach ($parts as $part) {
            if (!$field->has($part)) {
                return;
            }
            $field = $field->get($part);
        }

        if ($field !== $form) {
            return;
        }

        $searchFields = $form->getConfig()->getAttribute('search-fields');
        $template = $this->options['template'];
        $extraParams = $this->options['extra_params'];

        $results = $this->resultsFetcher->getPaginatedResults($request, $form->getConfig()->getAttribute('query-builder'), $searchFields);
        // $results still holds the total amount through (count)
        $ttl = count($results);
        $responseData = array();
        $options = array('search-fields' => $searchFields, 'extra_params' => $extraParams);
        foreach ($results as $result) {
            $identifier = $this->options['identifier_propertypath'] ? $this->propertyAccessor->getValue($result, $this->options['identifier_propertypath']) : $result->getId();
            $responseData[] = $this->responseFormatter->formatResultLineForAutocompleteResponse($template, $result, $options, $identifier);
        }
        throw new UnexpectedResponseException(new AutocompleteResponse($responseData, $ttl));
    }
828788
public function onLog(LogCreateEvent $event)
    {
        $log = $event->getLog();
        $dateLog = $log->getDateLog();
        $action = $log->getAction();
        $resourceNode = $log->getResourceNode();
        $user =  $log->getDoer();

        if (!is_null($user)) {
            $activityRules = is_null($resourceNode) ?
                $this->activityManager
                    ->getActivityRuleByActionWithNoResource($action) :
                $this->activityManager
                    ->getActivityRuleByActionAndResource($action, $resourceNode);

            if (count($activityRules) > 0) {
                foreach ($activityRules as $activityRule) {
                    $activityParams = $activityRule->getActivityParameters();
                    $accessFrom = $activityRule->getActiveFrom();
                    $accessUntil = $activityRule->getActiveUntil();

                    if ((is_null($accessFrom) || $dateLog >= $accessFrom)
                        && (is_null($accessUntil) || $dateLog <= $accessUntil)) {
                        $nbRules = is_null($activityParams->getRules()) ?
                            0 :
                            count($activityParams->getRules());

                        if ($nbRules > 0) {
                            $rules = $activityParams->getRules();
                            $ruleType = 'result';

                            foreach ($rules as $rule) {
                                if (is_null($rule->getResult())) {
                                    $ruleType = 'occurrence';
                                    break;
                                }
                            }

                            $rulesLogs = $this->ruleValidator->validate($activityParams, $user);

                            if (isset($rulesLogs['validRules'])
                                && $rulesLogs['validRules'] >= $nbRules) {
                                $activityStatus = $ruleType === 'occurrence' ?
                                    AbstractEvaluation::STATUS_COMPLETED :
                                    AbstractEvaluation::STATUS_PASSED;
                            } else {
                                $activityStatus = $ruleType === 'occurrence' ?
                                    AbstractEvaluation::STATUS_INCOMPLETE :
                                    AbstractEvaluation::STATUS_FAILED;
                            }

                            $this->activityManager->manageEvaluation(
                                $user,
                                $activityParams,
                                $log,
                                $rulesLogs,
                                $activityStatus
                            );
                        }
                    }
                }
            }
        }
    }
1052709
public function onFileChange(ResourceActionEvent $event)
    {
        $files = $event->getFiles();
        $node = $event->getResourceNode();

        $file = isset($files['file']) ? $files['file'] : null;

        if ($file) {
            $publicFile = $this->fileUtils->createFile($file, null, ResourceNode::class, $node->getUuid());
            $resource = $this->resourceManager->getResourceFromNode($node);

            if ($resource && $publicFile) {
                $this->om->persist($publicFile);
                $resource->setHashName($publicFile->getUrl());
                $resource->setMimeType($publicFile->getMimeType());
                $resource->setSize($publicFile->getSize());
                $this->om->persist($resource);
                $this->om->flush();
            }
        }
        $event->setResponse(new JsonResponse($this->serializer->serialize($node)));
    }
976070
public function postCreate(CreateEvent $event)
    {
        /** @var Role $role */
        $role = $event->getObject();

        if ($role->getWorkspace()) {
            $sql = "
              INSERT INTO claro_resource_rights (role_id, mask, resourceNode_id)
              SELECT {$role->getId()}, 1, resource.id FROM claro_resource_node resource
              WHERE resource.workspace_id = {$role->getWorkspace()->getId()}
            ";

            $stmt = $this->conn->prepare($sql);
            $stmt->execute();
        }
    }
869184
public function submit(FormEvent $event)
    {
        $image = $event->getData();

        if ($image && $image->isNew() && !$image->hasFile()) {
            $event->setData(null);
        }
    }
4105
public function preSubmitData(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();

        if (null === $data || '' === $data) {
            $data = array();
        }

        foreach ($form as $name => $child) {
            if (!isset($data[$name])) {
                $form->remove($name);
            }
        }
    }
1177424
public function createResourceTimelineEntry(EntityPublishedEvent $event): void
    {
        // Only act on resource objects.
        $resource = $event->getObject();
        if (!$resource instanceof Resource) {
            return;
        }

        // Get the author for the resource.
        $author = $this->user_provider->loadUserByUsername($resource->getAuthor());

        // Create components for this action.
        $resource_component = $this->action_manager->findOrCreateComponent($resource);
        $author_component = $this->action_manager->findOrCreateComponent($author);

        // Add timeline entries for each group.
        foreach ($resource->getGroups() as $group) {
            // Create the group component.
            $group_component = $this->action_manager->findOrCreateComponent($group);

            // Create the action and link it.
            $action = $this->action_manager->create($author_component, 'created_resource', [
                'directComplement' => $resource_component,
                'indirectComplement' => $group_component,
            ]);

            // Update the action.
            $this->action_manager->updateAction($action);
        }
    }
1212624
public function about(ResourceActionEvent $event)
    {
        $event->setResponse(
            new JsonResponse($this->serializer->serialize($event->getResourceNode()))
        );
        $event->stopPropagation();
    }
252886
public function onDocimology(CustomActionResourceEvent $event)
    {
        /** @var Exercise $exercise */
        $exercise = $event->getResource();

        $content = $this->templating->render(
            'UJMExoBundle:exercise:docimology.html.twig', [
                '_resource' => $exercise,
                'exercise' => $this->exerciseManager->serialize($exercise, [Transfer::MINIMAL]),
                'statistics' => $this->docimologyManager->getStatistics($exercise, 100),
            ]
        );

        $event->setResponse(new Response($content));
        $event->stopPropagation();
    }
1279651
public function onPreSubmit(FormEvent $event)
    {
        $data = $event->getData();

        if ($data['file'] instanceof UploadedFile) {
            $event->getForm()->remove('remove');
        }

        if (empty($data['file']) && (!isset($data['remove']) || !$data['remove'])) {
            $event->setData($event->getForm()->getViewData());
        }
    }
1086781
public function postSubmit(FormEvent $event)
    {
        $collection = $event->getData();
        
        if ($collection instanceof PersistentCollection){           
            foreach ($collection->getDeleteDiff() as $entity){   
                if ($entity instanceof MultiFileInterface){
                    $this->om->remove($entity);
                } 
            }
        }
    }