@DI\Observe("crud_pre_create_object_claroline_forumbundle_entity_message")

@param CreateEvent $event

@return ResourceNode
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;
    }
60603
public function onPreUpdate(ResourceEventInterface $event)
    {
        $page = $this->getPageFromEvent($event);

        // Don't disable if static
        if (!$page->isEnabled() && $page->isStatic()) {
            $page->setEnabled(true);
        }

        // Don't enable if at least one ancestor is disabled.
        if ($page->isEnabled()) {
            $parentPage = $page;
            while (null !== $parentPage = $parentPage->getParent()) {
                if (!$parentPage->isEnabled()) {
                    $page->setEnabled(false);
                    $event->addMessage(new ResourceMessage(
                        'ekyna_cms.page.alert.parent_disabled',
                        ResourceMessage::TYPE_WARNING
                    ));
                    break;
                }
            }
        }

        // Bubble disable
        if ($this->disablePageChildren($page)) {
            $event->addMessage(new ResourceMessage(
                'ekyna_cms.page.alert.children_disabled',
                ResourceMessage::TYPE_WARNING
            ));
        }
        if ($this->disablePageRelativeMenus($page)) {
            $event->addMessage(new ResourceMessage(
                'ekyna_cms.page.alert.menus_disabled',
                ResourceMessage::TYPE_WARNING
            ));
            $this->tm->addTags(call_user_func($this->menuClass . '::getEntityTagPrefix'));
        }
    }
1055916
public function preCreate(CreateEvent $event)
    {
        $announcement = $event->getObject();
        $options = $event->getOptions();
        $announcement->setAggregate($options['announcement_aggregate']);

        if (!in_array(Options::NO_LOG, $options)) {
            $this->eventDispatcher->dispatch(
                'log',
                'Claroline\\AnnouncementBundle\\Event\\Log\\LogAnnouncementCreateEvent',
                [$announcement->getAggregate(), $announcement]
            );
        }
    }
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())));
    }
394999
public function onNodeNewLabels(ResourceEvent $event)
    {
        $event->ignoreDefaultChan();
        foreach ($event->getArgument('new_labels') as $labelId) {
            $event->addResourceChanId('label', $labelId);
        }
    }
1176763
public function open(OpenResourceEvent $event)
    {
        $resource = $event->getResource();
        $workspace = $resource->getResourceNode()->getWorkspace();

        $options = [];
        if (!$this->checkPermission('EDIT', $resource->getResourceNode())) {
            // filter returned posts
            $options[] = AnnouncementAggregateSerializer::VISIBLE_POSTS_ONLY;
        }

        $content = $this->templating->render(
            'ClarolineAnnouncementBundle:announcement:open.html.twig', [
                '_resource' => $resource,
                'announcement' => $this->serializer->serialize($resource, $options),
                'roles' => array_map(function (Role $role) {
                    return $this->serializer->serialize($role, [Options::SERIALIZE_MINIMAL]);
                }, $workspace->getRoles()->toArray()),
            ]
        );

        $event->setResponse(new Response($content));
        $event->stopPropagation();
    }
1200182
public function create(SaleCreateEvent $event)
    {
        $sale = new SaleModel();

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

        $event->setSale($sale);
    }
984074
public function onCreate(CreateResourceEvent $event)
    {
        $form = $this->formFactory->create(new ActivityType(), new Activity());
        $form->handleRequest($this->request);

        if ($form->isValid()) {
            $published = $form->get('published')->getData();
            $event->setPublished($published);
            $activity = $form->getData();
            $activity->setName($activity->getTitle());
            $activityParameters = new ActivityParameters();
            $activityParameters->setActivity($activity);
            $activity->setParameters($activityParameters);
            $event->setResources(array($activity));
            $event->stopPropagation();

            return;
        }

        $content = $this->templating->render(
            'ClarolineCoreBundle:Resource:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => 'activity'
            )
        );

        $event->setErrorFormContent($content);
        $event->stopPropagation();
    }
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));
    }
969598
public function postCreate(CreateEvent $event)
    {
        $organization = $event->getObject();
        $key = $this->cryptoManager->generatePair();
        $key->setOrganization($organization);
        $this->om->persist($key);
        $this->om->flush();
    }
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;
    }
1000118
public function onCreateForm(CreateFormResourceEvent $event)
    {
        $formFactory = $this->container->get('claroline.form.factory');
        $form = $formFactory->create(FormFactory::TYPE_RESOURCE_TEXT, array('text_'.rand(0, 1000000000)));
        $response = $this->container->get('templating')->render(
            'ClarolineCoreBundle:Text:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => 'text'
            )
        );
        $event->setResponseContent($response);
        $event->stopPropagation();
    }
818493
protected function persistResource(ResourceEvent $event)
    {
        $resource = $event->getResource();

        // TODO Validation ?

        try {
            $this->manager->persist($resource);
            $this->manager->flush();
        } catch(DBALException $e) {
            if ($this->debug) {
                throw $e;
            }
            $event->addMessage(new ResourceMessage(
                'ekyna_admin.resource.message.persist.failure',
                ResourceMessage::TYPE_ERROR
            ));
            return $event;
        }

        return $event->addMessage(new ResourceMessage(
            'ekyna_admin.resource.message.persist.success',
            ResourceMessage::TYPE_SUCCESS
        ));
    }
467590
public function onRequest(RequestEvent $event)
    {
        if (!$this->wsaEnabled) {
            return;
        }

        $request = $event->getRequest();
        $envelope = $request->documentElement;
        $soapNS = $envelope->namespaceURI;

        $xpath = new \DOMXPath($event->getRequest());
        $xpath->registerNamespace('soap', $soapNS);
        $xpath->registerNamespace('wsa', self::NS_WSA);

        // Add WSA namespace to envelope
        $envelope->setAttributeNS(self::NS_XMLNS, 'xmlns:wsa', self::NS_WSA);

        // Find or create header
        $headers = $xpath->query('//soap:Envelope/soap:Header');
        $header = $headers->item(0);

        if (!$header) {
            $header = $request->createElementNS($soapNS, $envelope->prefix . ':Header');
            $envelope->insertBefore($header, $envelope->firstChild);
        }

        // Add MessageID
        $header->appendChild($request->createElementNS(self::NS_WSA, 'wsa:MessageID', 'uuid:' . Uuid::uuid4()));

        // Add Action
        $header->appendChild($request->createElementNS(self::NS_WSA, 'wsa:Action', $event->getAction()));

        // Add To
        $header->appendChild($request->createElementNS(self::NS_WSA, 'wsa:To', $event->getLocation()));

        // Add From
        if (false !== $this->getFrom()) {
            // use anonymous when set to true, given address otherwise
            $fromAddress = $this->getFrom() === true ? self::ANONYMOUS : $this->getFrom();
            $from = $request->createElementNS(self::NS_WSA, 'wsa:From');
            $from->appendChild($request->createElementNS(self::NS_WSA, 'wsa:Address', $fromAddress));
            $header->appendChild($from);
        }

        // Add ReplyTo
        if (!$event->isOneWay()) {
            $address = $this->address ?: self::ANONYMOUS;

            $replyTo = $request->createElementNS(self::NS_WSA, 'wsa:ReplyTo');
            $replyTo->appendChild($request->createElementNS(self::NS_WSA, 'wsa:Address', $address));

            $header->appendChild($replyTo);
        }
    }
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;
    }
703230
public function createEntity(NodeCreateEvent $event)
    {
        $className = $this->registry
            ->getRepository($this->lookupEntityName($event->getType()))
            ->getClassName();

        $event->setEntity(new $className());
    }
308997
public function create(MarketingEvent &$marketingEvent)
    {
        $data = $marketingEvent->exportData();
        $endpoint = '/admin/marketing_events.json';
        $response = $this->request(
            $endpoint, 'POST', array(
            'marketing_event' => $data
            )
        );
        $marketingEvent->setData($response['marketing_event']);
    }