@DI\Observe("crud_pre_create_object_claroline_forumbundle_entity_subject")

@param CreateEvent $event

@return ResourceNode
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;
    }
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)
        );
    }
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);
        }
    }
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;
    }
1165201
public function onNodePresave(NodeEvent $event)
    {
        $node = $event->getNode();

        // When coming from the node form, node form has already been submitted
        // case in which, if relevant, a group identifier has already been set
        // and this code won't be execute. In the other hand, if the prepare
        // hook has not been invoked, this will run and set things right.
        // There is still a use case where the node comes from the node form but
        // there is no contextual group, case in which this code will wrongly
        // run, but hopefuly since it is just setting defaults, it won't change
        // the normal behavior.
        if (empty($node->group_id)) {
            $groupId = $this->findMostRelevantGroupId();

            if ($groupId) {
                $node->group_id = $groupId;
            }

            $node->is_ghost = $this->findMostRelevantGhostValue($node);
        }
    }
62208
protected function applyEventCreated(
        EventCreated $eventCreated,
        DomainMessage $domainMessage
    ) {
        $eventId = $eventCreated->getEventId();

        $location = $eventCreated->getLocation();

        $this->addNewItemToIndex(
            $domainMessage,
            $eventId,
            EntityType::EVENT(),
            $eventCreated->getTitle(),
            $location->getAddress()->getPostalCode(),
            $location->getAddress()->getLocality(),
            $location->getAddress()->getCountry()->getCode()
        );
    }
1268283
public function preCreate(CreateEvent $event)
    {
        /** @var Role $role */
        $role = $event->getObject();

        if (!$role->getWorkspace()) {
            $role->setName(strtoupper('role_'.$role->getTranslationKey()));
        }
    }
1200182
public function create(SaleCreateEvent $event)
    {
        $sale = new SaleModel();

        $sale
            ->setLocale($event->getLocale())
            ->setTitle($event->getTitle())
            ->setSaleLabel($event->getSaleLabel())
            ->save()
        ;

        $event->setSale($sale);
    }
419771
public function onOpen(OpenResourceEvent $event)
    {
        $subRequest = $this->request->duplicate([], null, [
            '_controller' => 'ClarolineResultBundle:Result:result',
            'id' => $event->getResource()->getId(),
        ]);
        $event->setResponse($this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST));
        $event->stopPropagation();
    }
990364
public function onVisitNode(VisitNodeEvent $event)
    {
        $node = $event->getNode();
        if (!$node instanceof AbstractComparisonOperatorNode) {
            return $event;
        }

        $fieldName = $this->getDocumentFieldName($node->getField(), $event->getContext());
        if ($fieldName === false) {
            return $event;
        }

        $copy = clone $node;
        $copy->setField(strtr($fieldName, ['.0.' => '.']));
        $event->setNode($copy);
        return $event;
    }
583451
public function onVisitNode(VisitNodeEvent $event)
    {
        $node = $event->getNode();
        if ($node instanceof AbstractScalarOperatorNode &&
            $this->isExtrefField($node->getField(), $event->getContext())) {
            $event->setNode($this->processScalarNode($node));
        } elseif ($node instanceof AbstractArrayOperatorNode &&
            $this->isExtrefField($node->getField(), $event->getContext())) {
            $event->setNode($this->processArrayNode($node));
        }

        return $event;
    }
606686
public function createProxyEvent(Event $event)
    {
        if ($event instanceof GetResponseForControllerResultEvent) {
            $silexEvent = new PostDispatchEvent($event);

        } elseif ($event instanceof GetResponseEvent) {
            $silexEvent = new RequestEvent($event);

        } elseif ($event instanceof FilterControllerEvent) {
            $silexEvent = new PreDispatchEvent($event);

        } elseif ($event instanceof FilterResponseEvent) {
            $silexEvent = new ResponseEvent($event);

        } elseif ($event instanceof SfPostResponseEvent) {
            $silexEvent = new PostResponseEvent($event);

        } elseif ($event instanceof FinishRequestEvent) {
            $silexEvent = new PostRequestEvent($event);

        } elseif ($event instanceof KernelEvent) {
            $silexEvent = new SilexKernelEvent($event);

        } elseif ($event instanceof Event) {
            $silexEvent = new SilexEvent($event);

        } else {
            $silexEvent = null; // unknown event
        }

        return $silexEvent;
    }
504458
public function preCreate(CreateEvent $event)
    {
        $badge = $event->getObject();

        if ($badge->getWorkspace()) {
            $badge->setEnabled($this->parametersSerializer->serialize()['badges']['enable_default']);
        }
    }
601413
public function preCreate(CreateEvent $event)
    {
        $workspace = $this->manager->createWorkspace($event->getObject());
        $options = $event->getOptions();

        $user = $this->tokenStorage->getToken() ?
            $this->tokenStorage->getToken()->getUser() :
            $this->userManager->getDefaultClarolineAdmin();
        $model = $workspace->getWorkspaceModel() ? $workspace->getWorkspaceModel() : $this->manager->getDefaultModel();
        $workspace->setWorkspaceModel($model);

        if ($user instanceof User) {
            $workspace->setCreator($user);

            $organization = $user->getMainOrganization() ?
                $user->getMainOrganization() :
                $this->organizationManager->getDefault();
            $workspace->addOrganization($organization);
        }

        //this is for workspace creation: TODO remove that because it's very confusing
        //make a search on LIGHT_COPY you'll find what will probably need a change
        if (in_array(Options::LIGHT_COPY, $options)) {
            $this->om->flush();

            return $workspace;
        }

        //is this part ever fired anymore ? I don't know

        $workspace = $this->manager->copy($model, $workspace, false);

        $this->om->flush();

        return $workspace;
    }
12557
public function onSerialize(DecorateResourceNodeEvent $event)
    {
        $options = $event->getOptions();

        if (!in_array(Options::SKIP_RESOURCE_NOTIFICATION, $options)) {
            $node = $event->getResourceNode();
            $user = $this->tokenStorage->getToken()->getUser();
            $followResource = $user !== 'anon.' ?
                $this->notificationManager->getFollowerResource(
                    $user->getId(),
                    $node->getId(),
                    $node->getClass()
                ) :
                false;

            $event->add('notifications', ['enabled' => !empty($followResource)]);
        }
    }
945407
public function addTypeOnPostSerialize(ObjectEvent $event)
    {
        $article = $event->getObject();
        $visitor = $event->getVisitor();
        $context = $event->getContext();

        if (!($article instanceof ArticleDocument)) {
            return;
        }

        $structure = $this->structureManager->getStructure($article->getStructureType(), 'article');
        $visitor->addData('articleType', $context->accept($this->getType($structure->getStructure())));
    }
944759
public function processCreateDraft(FormActionEvent $event)
    {
        /** @var $createContentDraft \EzSystems\RepositoryForms\Data\Content\CreateContentDraftData */
        $createContentDraft = $event->getData();

        $contentInfo = $this->contentService->loadContentInfo($createContentDraft->contentId);
        $versionInfo = $this->contentService->loadVersionInfo($contentInfo, $createContentDraft->fromVersionNo);
        $contentDraft = $this->contentService->createContentDraft($contentInfo, $versionInfo);
        $referrerLocation = $event->getOption('referrerLocation');

        $event->setPayload('content', $contentDraft);
        $event->setPayload('is_new', $contentDraft->contentInfo->isDraft());

        $contentEditUrl = $this->router->generate('ez_content_draft_edit', [
            'contentId' => $contentDraft->id,
            'versionNo' => $contentDraft->getVersionInfo()->versionNo,
            'language' => $contentDraft->contentInfo->mainLanguageCode,
            'locationId' => null !== $referrerLocation ? $referrerLocation->id : null,
        ]);
        $event->setResponse(new RedirectResponse($contentEditUrl));
    }