Pre create event handler.

@param ResourceEventInterface $event
542002
public function onPreCreate(ResourceEventInterface $event)
    {
        $page = $this->getPageFromEvent($event);

        // Generate random route name.
        if (null === $page->getRoute()) {
            $class = get_class($page);
            /** @noinspection SqlDialectInspection */
            $query = $this->em->createQuery("SELECT p.id FROM {$class} p WHERE p.route = :route");
            $query->setMaxResults(1);

            do {
                $route = sprintf('cms_page_%s', uniqid());
                $result = $query
                    ->setParameter('route', $route)
                    ->getOneOrNullResult(Query::HYDRATE_SCALAR);
            } while (null !== $result);

            $page->setRoute($route);
        }
    }
310229
public function onLabelEdit(ResourceEvent $event)
    {
        $labelIdList    = $event->getResourceIdList();
        $labels         = $this->labelManager->loadLabels($labelIdList);
        $channelsToAdd  = [];
        $channelsToDel  = [];

        foreach ($labels as $label) {
            if (!$this->labelManager->isRootLabel($label)) {
                $channelsToAdd[] = 'label:' . $label->tid;
            } else {
                $channelsToDel[] = 'label:' . $label->tid;
            }
        }

        if (!empty($channelsToAdd)) {
            $this->notifService->getBackend()->createChannels($channelsToAdd, true);
        }
        if (!empty($channelsToDel)) {
            $this->notifService->getBackend()->deleteChannels($channelsToDel, true);
        }
    }
548176
public function load(LoadResourceEvent $event)
    {
        $event->setData([
            'text' => $this->serializer->serialize($event->getResource()),
        ]);

        $event->stopPropagation();
    }
741979
public function restore(ResourceActionEvent $event)
    {
        $this->manager->restore($event->getResourceNode());

        $event->setResponse(
            new JsonResponse($this->serializer->serialize($event->getResourceNode()))
        );
    }
414300
public function onRequestBeforeSend(Event $event)
    {
        $request = $event['request'];
        $timestamp = $this->getTimestamp($event);

        $url = $request->getUrl(true);
        $url->getQuery()->add('ts', $timestamp);

        $body = '';
        $path = sprintf('%s?%s', $url->getPath(), (string) $url->getQuery());

        if ($request instanceof EntityEnclosingRequest) {
            $body = $request->getBody();
        }

        $signature = $this->signer->getSignature($request->getMethod(), $path, $body);

        $request->setUrl($url);
        $request->setHeader('Content-Type', 'application/json');
        $request->setHeader('X-Leetchi-Signature', $signature);
    }
357749
public function beforePrepare(Event $event)
	{
		$command = $event['command'];

		if ($command->getName() !== 'createEntity') return;
		if (!$command['_id']) return;

		$operation = $command->getOperation();
		$operation->setHttpMethod('PUT');
	}
1012985
public function createResourceEvent(ResourceInterface $resource, $throwException = true)
    {
        if ($config = $this->registry->findConfiguration($resource, $throwException)) {
            $class = $config->getEventClass();

            /** @var \Ekyna\Component\Resource\Event\ResourceEventInterface $event */
            $event = new $class;
            $event->setResource($resource);

            return $event;
        }

        return null;
    }
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();
        }
    }
922430
public function beforeRender(Event $event)
    {
        parent::beforeRender($event);

        $this->set('detect', $this->detect);
    }
83676
public function onDelete(DeleteResourceEvent $event)
    {
        $ds = DIRECTORY_SEPARATOR;

        /** @var File $resource */
        $resource = $event->getResource();
        $workspace = $resource->getResourceNode()->getWorkspace();
        $hashName = $resource->getHashName();

        $archiveFile = $this->filesDir.$ds.'webresource'.$ds.$workspace->getUuid().$ds.$hashName;
        $webResourcesPath = $this->uploadDir.$ds.'webresource'.$ds.$workspace->getUuid().$ds.$hashName;

        if (file_exists($archiveFile)) {
            $event->setFiles([$archiveFile]);
        }
        if (file_exists($webResourcesPath)) {
            try {
                $this->deleteFiles($webResourcesPath);
            } catch (\Exception $e) {
            }
        }
        $this->om->remove($resource);
        $event->stopPropagation();
    }
564525
protected function handle(Event $event): void
    {
        $method = 'apply'.ClassName::short($event);

        if (!method_exists($this, $method)) {
            return;
        }

        $this->$method($event);
    }
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
        ));
    }
479954
public function beforePrepare(Event $event)
	{
		$command = $event['command'];
		$operation = $command->getOperation();

		if ($command->getName() !== 'updateEntity' && $command->offsetExists('_id') === true) return;

		$operation->addParam(new Parameter(array(
			'name' => 'body_id',
			'location' => 'json',
			'type' => 'string',
			'default' => $command->offsetGet('_id'),
			'static' => true,
			'sentAs' => '_id'
		)));
	}
502728
public function beforeRender($event)
    {
        $this->Controller->set('authUser', $this->Controller->authUser);

        // beforeRender-event
        $_event = new Event('Component.Manager.beforeRender', $this, [
        ]);
        $this->Controller->eventManager()->dispatch($_event);

        if ($this->isPrefix()) {
            $this->_runCallback("beforeRender", $event);

            // beforeRender-event with Prefix
            $this->_runEvent("beforeRender");
        }
    }
954338
private function getMenuFromEvent(ResourceEventInterface $event)
    {
        $resource = $event->getResource();

        if (!$resource instanceof MenuInterface) {
            throw new InvalidArgumentException("Expected instance of MenuInterface");
        }

        return $resource;
    }
1152066
public static function onBeforeSave(Event $event)
    {
        $layout = $event->getTarget();
        if (!is_a($layout, 'BackBee\Site\Layout')) {
            return;
        }

        $dispatcher = $event->getDispatcher();
        if (null !== $dispatcher->getApplication()) {
            if (is_a($event->getEventArgs(), 'Doctrine\ORM\Event\PreUpdateEventArgs')) {
                if (!$event->getEventArgs()->hasChangedField('_data')) {
                    return;
                }
            }

            // Update the layout thumbnail - Beware of generate thumbnail before any other operation
            $thumb = $dispatcher->getApplication()->getEntityManager()
                    ->getRepository('BackBee\Site\Layout')
                    ->generateThumbnail($layout, $dispatcher->getApplication());

            // Update the layout file
            try {
                $dispatcher->getApplication()->getRenderer()->updateLayout($layout);
            } catch (\BackBee\Renderer\Exception\RendererException $e) {
                $dispatcher->getApplication()->warning($e->getMessage());
            }

            if (is_a($event->getEventArgs(), 'Doctrine\ORM\Event\PreUpdateEventArgs')) {
                if ($event->getEventArgs()->hasChangedField('_picpath')) {
                    $event->getEventArgs()->setNewValue('_picpath', $thumb);
                }
            }
        }
    }
586192
public function determineEventBinding(Event $event)
    {
        switch ($event->getCode()) {
            case Event::RESOURCE_DELETED:
                return 'delete';
                break;
            case Event::RESOURCE_CREATED:
                return 'create';
                break;
            case Event::RESOURCE_MODIFIED:
                return 'modify';
            break;
        }
    }