@DI\Observe("crud_pre_create_object_claroline_corebundle_entity_resource_resourcenode")

@param CreateEvent $event

@return ResourceNode
779703
public function preCreate(CreateEvent $event)
    {
        /** @var ResourceNode $resourceNode */
        $resourceNode = $event->getObject();

        // set the creator of the resource
        $user = $this->tokenStorage->getToken()->getUser();
        if ($user instanceof User) {
            $resourceNode->setCreator($user);
        }

        return $resourceNode;
    }
438428
public function onNodeResourceEventAlterChannels(Event $event)
    {
        if (!$this->groupManager || !$event instanceof ResourceEvent) {
            return;
        }

        $done = [];

        // Fetch site groups, and yes we don't really have a choice here
        $nodes = $this->entityManager->getStorage('node')->loadMultiple($event->getResourceIdList());
        foreach ($nodes as $node) {
            if ($node->group_id) {
                $groupId = (int)$node->group_id;
                $done[$groupId] = $groupId;
            }
        }

        foreach ($done as $groupId) {
            $event->addArbitraryChanId('admin:content:' . $groupId);
        }
    }
1235145
protected function performAdditionalCreateAction($createEvent)
    {
        return $this->generateRedirectFromRoute(
            "admin.configuration.taxes.update",
            $this->getViewArguments(),
            $this->getRouteArguments($createEvent->getTax()->getId())
        );
    }
950845
public function preCreate(CreateEvent $event)
    {
        $organization = $event->getObject();
        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof User) {
            $organization->addAdministrator($user);
        }
    }
358940
public function onCreateForm(CreateFormResourceEvent $event)
    {
        $form = $this->container->get('form.factory')->create(new FileType(true), new File());
        $content = $this->container->get('templating')->render(
            'ClarolineCoreBundle:Resource:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => 'file'
            )
        );
        $event->setResponseContent($content);
        $event->stopPropagation();
    }
7458
public function preCreate(CreateEvent $event)
    {
        $message = $event->getObject();
        $forum = $this->getSubject($message)->getForum();

        //create user if not here
        $user = $this->om->getRepository(User::class)->findOneBy([
          'user' => $message->getCreator(),
          'forum' => $forum,
        ]);

        if (!$user) {
            $user = new User();
            $user->setForum($forum);
            $user->setUser($message->getCreator());
        }
        if (!$this->checkPermission('EDIT', $forum->getResourceNode())) {
            if (Forum::VALIDATE_PRIOR_ALL === $forum->getValidationMode()) {
                $message->setModerated(Forum::VALIDATE_PRIOR_ALL);
            }

            if (Forum::VALIDATE_PRIOR_ONCE === $forum->getValidationMode()) {
                $message->setModerated($user->getAccess() ? Forum::VALIDATE_NONE : Forum::VALIDATE_PRIOR_ONCE);
            }
        } else {
            $message->setModerated(Forum::VALIDATE_NONE);
        }

        return $message;
    }
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)));
    }
1033470
public function move(ResourceActionEvent $event)
    {
        $resourceNode = $event->getResourceNode();
        $data = $event->getData();
        $parent = isset($data['destination']['autoId']) && isset($data['destination']['meta']['type']) && 'directory' === $data['destination']['meta']['type'] ?
            $this->manager->getById($data['destination']['autoId']) :
            null;

        if (!empty($parent)) {
            $movedResource = $this->manager->move($resourceNode, $parent);
            $event->setResponse(
                new JsonResponse($this->serializer->serialize($movedResource), 200)
            );
        } else {
            $event->setResponse(
                new JsonResponse(null, 500)
            );
        }
    }
1224675
public function onNodePrepare(NodeEvent $event)
    {
        $node = $event->getNode();

        if (!empty($node->group_id)) {
            return; // Someone took care of this for us
        }

        $node->group_id = $this->findMostRelevantGroupId();
        $node->is_ghost = (int)$this->findMostRelevantGhostValue($node);
    }
672549
public function create(Resource\ResourceData $resourceData)
    {
        return $this->crudRepositoryAdapter->createResource($this->resourceType, $resourceData);
    }
291203
public static function addEventEntry(AbstractEvent $event)
    {
        return new self(
            null !== $event->aggregateRoot ? $event->aggregateRoot->getId() : null,
            null !== $event->aggregateRoot ? get_class($event->aggregateRoot) : null,
            $event->author,
            get_class($event),
            $event->date,
            serialize($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();
    }
707986
public function onOpen(OpenResourceEvent $event)
    {
        $directory = $event->getResource();

        $content = $this->templating->render(
            'ClarolineCoreBundle:directory:index.html.twig', [
                'directory' => $directory,
                '_resource' => $directory,
            ]
        );

        $response = new Response($content);
        $event->setResponse($response);

        $event->stopPropagation();
    }
1355502
protected function performAdditionalCreateAction($createEvent)
    {
        return $this->generateRedirectFromRoute(
            "admin.configuration.profiles.update",
            $this->getViewArguments(),
            $this->getRouteArguments($createEvent->getProfile()->getId())
        );
    }
118895
public function onAdd(ResourceActionEvent $event)
    {
        $data = $event->getData();
        $parent = $event->getResourceNode();

        $add = $this->actionManager->get($parent, 'add');

        // checks if the current user can add
        $collection = new ResourceCollection([$parent], ['type' => $data['resourceNode']['meta']['type']]);
        if (!$this->actionManager->hasPermission($add, $collection)) {
            throw new ResourceAccessException($collection->getErrorsForDisplay(), $collection->getResources());
        }

        $options = $event->getOptions();
        $options[] = Options::IGNORE_CRUD_POST_EVENT;

        // create the resource node

        /** @var ResourceNode $resourceNode */
        $resourceNode = $this->crud->create(ResourceNode::class, $data['resourceNode'], $options);
        $resourceNode->setParent($parent);
        $resourceNode->setWorkspace($parent->getWorkspace());

        // initialize custom resource Entity
        $resourceClass = $resourceNode->getResourceType()->getClass();

        /** @var AbstractResource $resource */
        $resource = $this->crud->create($resourceClass, !empty($data['resource']) ? $data['resource'] : [], $options);
        $resource->setResourceNode($resourceNode);

        // maybe do it in the serializer (if it can be done without intermediate flush)
        if (!empty($data['resourceNode']['rights'])) {
            foreach ($data['resourceNode']['rights'] as $rights) {
                /** @var Role $role */
                $role = $this->om->getRepository('ClarolineCoreBundle:Role')->findOneBy(['name' => $rights['name']]);
                $this->rightsManager->editPerms($rights['permissions'], $role, $resourceNode);
            }
        } else {
            // todo : initialize default rights
        }

        $this->crud->dispatch('create', 'post', [$resource, $options]);
        $this->om->persist($resource);
        $this->om->persist($resourceNode);

        // todo : dispatch creation event

        $this->om->flush();

        // todo : dispatch get/load action instead
        $event->setResponse(new JsonResponse(
            [
                'resourceNode' => $this->serializer->serialize($resourceNode),
                'resource' => $this->serializer->serialize($resource),
            ],
            201
        ));
    }
1344164
public function load(LoadResourceEvent $event)
    {
        $resourceNode = $event->getResourceNode();

        // propagate event to resource type
        $subEvent = $this->lifecycleManager->load($resourceNode);

        $event->setData(array_merge([
            // we need the full workspace object for some rendering config
            // (we only have access to the minimal version of the WS in the node)
            'workspace' => $resourceNode->getWorkspace() ? $this->serializer->serialize($resourceNode->getWorkspace()) : null,
            'resourceNode' => $this->serializer->serialize($resourceNode),
            'managed' => $this->manager->isManager($resourceNode),
            'userEvaluation' => null, // todo flag evaluated resource types and auto load Evaluation if any
        ], $subEvent->getData()));
    }
504187
public function preCreate(CreateEvent $event)
    {
        $subject = $event->getObject();
        $forum = $subject->getForum();

        //create user if not here
        $user = $this->om->getRepository('ClarolineForumBundle:Validation\User')->findOneBy([
          'user' => $subject->getCreator(),
          'forum' => $forum,
        ]);

        if (!$user) {
            $user = new User();
            $user->setForum($forum);
            $user->setUser($subject->getCreator());
        }

        $messages = $subject->getMessages();
        $first = $messages && isset($messages[0]) ? $messages[0] : null;

        if (!$this->checkPermission('EDIT', $forum->getResourceNode())) {
            if (Forum::VALIDATE_PRIOR_ALL === $forum->getValidationMode()) {
                $subject->setModerated(Forum::VALIDATE_PRIOR_ALL);
                if ($first) {
                    $first->setModerated(Forum::VALIDATE_PRIOR_ALL);
                }
            }

            if (Forum::VALIDATE_PRIOR_ONCE === $forum->getValidationMode()) {
                $subject->setModerated($user->getAccess() ? Forum::VALIDATE_NONE : Forum::VALIDATE_PRIOR_ONCE);
                if ($first) {
                    $first->setModerated(Forum::VALIDATE_PRIOR_ALL);
                }
            }
        } else {
            $subject->setModerated(Forum::VALIDATE_NONE);
            if ($first) {
                $first->setModerated(Forum::VALIDATE_PRIOR_ALL);
            }
        }

        if ($first) {
            $this->om->persist($first);
        }

        return $subject;
    }