Creates content draft based in data submitted by the user and injects ContentUpdateData to the event.

This step is required to achieve compatibility with other FormProcessors.

@param FormActionEvent $event
14120
public function createContentDraft(FormActionEvent $event): void
    {
        /** @var ContentTranslationData $data */
        $data = $event->getData();

        if (!$data instanceof ContentTranslationData) {
            return;
        }

        $contentDraft = $this->contentService->createContentDraft($data->content->contentInfo);
        $fields = array_filter($data->fieldsData, function (FieldData $fieldData) use ($contentDraft, $data) {
            $mainLanguageCode = $contentDraft->getVersionInfo()->getContentInfo()->mainLanguageCode;

            return $mainLanguageCode === $data->initialLanguageCode
                || ($mainLanguageCode !== $data->initialLanguageCode && $fieldData->fieldDefinition->isTranslatable);
        });
        $contentUpdateData = new ContentUpdateData([
            'initialLanguageCode' => $data->initialLanguageCode,
            'contentDraft' => $contentDraft,
            'fieldsData' => $fields,
        ]);

        $event->setData($contentUpdateData);
    }
1047139
protected function getCreationEvent($formData)
    {
        $contentCreateEvent = new ContentCreateEvent();

        $contentCreateEvent
            ->setLocale($formData['locale'])
            ->setDefaultFolder($formData['default_folder'])
            ->setTitle($formData['title'])
            ->setVisible($formData['visible'])
        ;

        return $contentCreateEvent;
    }
137392
public function onPreSetData(FormEvent $event)
    {
        $form = $event->getForm();
        $item = $event->getData();

        foreach ($this->fields as $field) {
            list ($name, $type, $options) = $field;
            if (null !== $item) {
                $options = array_replace($options, $this->itemHelper->getFormOptions($item, $name));
            }
            $form->add($name, $type, $options);
        }
    }
217334
public function onCreateForm(CreateFormResourceEvent $event)
    {
        $form = $this->formFactory->create(new DirectoryType, new Directory());
        $response = $this->templating->render(
            'ClarolineCoreBundle:Resource:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => 'directory'
            )
        );
        $event->setResponseContent($response);
        $event->stopPropagation();
    }
832258
public static function onFlushContent(Event $event)
    {
        $content = $event->getTarget();
        if (!($content instanceof AbstractClassContent)) {
            return;
        }

        $page = $content->getMainNode();
        if (null === $page) {
            return;
        }

        $newEvent = new Event($page, $content);
        $newEvent->setDispatcher($event->getDispatcher());
        self::onFlushPage($newEvent);
    }
1367638
public function onApiCreate(CreateResourceEvent $event)
    {
        $request = $this->container->get('request');
        $form = new FileType(true);
        $form->enableApi();
        $form = $this->container->get('form.factory')->create($form, new File());
        $form->submit($this->container->get('request'));


        if ($form->isValid()) {
            $this->handleFileCreation($form, $event);
        }

        $event->setErrorFormContent($form);
        $event->stopPropagation();
    }
727173
public function onPreSetData(FormEvent $event) {
        $item = $event->getData();
        $form = $event->getForm();


        // Meeting is defined -> keep it as hidden field
        if ($item && null != $item->getMeeting()) {
            $form->add('meeting', 'entity_hidden', ["class" => 'Interne\SeanceBundle\Entity\Meeting']);
        }
        // Meeting is not defined -> generate a select
        else {
            $form->add('meeting', 'entity', [
                'class' => 'InterneSeanceBundle:Meeting',
                'choice_label' => 'name',
                'placeholder' => 'Réserve de points...',
                'empty_value' => null,
                'expanded' => true,
                ]);
        }
    }
308005
public static function onUpdate(Event $event)
    {
        $content = $event->getTarget();
        if (!($content instanceof AbstractClassContent)) {
            throw new BBException(
                'Enable to update object',
                BBException::INVALID_ARGUMENT,
                new \InvalidArgumentException(sprintf(
                    'Only BackBee\ClassContent\AbstractClassContent can be commit, `%s` received',
                    get_class($content)
                ))
            );
        }

        $dispatcher = $event->getDispatcher();
        if (null === $application = $dispatcher->getApplication()) {
            throw new BBException(
                'Enable to update object',
                BBException::MISSING_APPLICATION,
                new \RuntimeException('BackBee application has to be initialized')
            );
        }

        if (null === $token = $application->getBBUserToken()) {
            throw new SecurityException('Enable to update : unauthorized user', SecurityException::UNAUTHORIZED_USER);
        }

        $em = $dispatcher->getApplication()->getEntityManager();
        if (null === $revision = $content->getDraft()) {
            if (null === $revision = $em->getRepository('BackBee\ClassContent\Revision')->getDraft($content, $token)) {
                throw new ClassContentException('Enable to get draft', ClassContentException::REVISION_MISSING);
            }
            $content->setDraft($revision);
        }

        $content->releaseDraft();
        if (0 == $revision->getRevision() || $revision->getRevision() == $content->getRevision) {
            throw new ClassContentException('Content is up to date', ClassContentException::REVISION_UPTODATE);
        }

        $lastCommitted = $em->getRepository('BackBee\ClassContent\Revision')->findBy([
            '_content'  => $content,
            '_revision' => $content->getRevision(),
            '_state'    => Revision::STATE_COMMITTED,
        ]);
        if (null === $lastCommitted) {
            throw new ClassContentException(
                'Enable to get last committed revision',
                ClassContentException::REVISION_MISSING
            );
        }

        $content->updateDraft($lastCommitted);
    }
509461
public function postSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        if (!$form->isValid()) {
            return;
        }

        $entity = $event->getData();
        $formHash = $this->getFormHash($form);
        $entityConfiguration = $this->getTranslatableEntityConfiguration($entity);

        if (is_null($entityConfiguration)) {
            return null;
        }

        $this->translationsBackup[$formHash] = [];

        $entityData = [
            'object' => $entity,
            'idGetter' => $entityConfiguration['idGetter'],
            'alias' => $entityConfiguration['alias'],
            'fields' => [],
        ];

        $entityFields = $entityConfiguration['fields'];

        foreach ($entityFields as $fieldName => $fieldConfiguration) {
            if (!isset($this->submittedDataPlain[$formHash][$fieldName])) {
                continue;
            }

            $field = $this->submittedDataPlain[$formHash][$fieldName];

            foreach ($this->locales as $locale) {
                $entityData['fields'][$fieldName][$locale] = $field[$locale . '_' . $fieldName];
            }

            if ($this->masterLocale && isset($field[$this->masterLocale . '_' . $fieldName])) {
                $masterLocaleData = $field[$this->masterLocale . '_' . $fieldName];
                $setter = $fieldConfiguration['setter'];
                $entity->$setter($masterLocaleData);
            }
        }

        $this->translationsBackup[$formHash][] = $entityData;
    }
1318188
public function processRedirectAfterPublish(FormActionEvent $event): void
    {
        if ($event->getForm()['redirectUrlAfterPublish']->getData()) {
            return;
        }

        $this->resolveSystemUrlRedirect($event);
    }
1060310
public function saveFile(FileCreateOrUpdateEvent $event)
    {
        $model = $event->getModel();
        $model->setFile(sprintf("tmp/%s", $event->getUploadedFile()->getFilename()));
        $con = Propel::getWriteConnection(ProductImageTableMap::DATABASE_NAME);
        $con->beginTransaction();

        try {
            $nbModifiedLines = $model->save($con);
            $event->setModel($model);

            if (!$nbModifiedLines) {
                throw new FileException(
                    sprintf(
                        'File "%s" (type %s) with parent id %s failed to be saved',
                        $event->getParentName(),
                        \get_class($model),
                        $event->getParentId()
                    )
                );
            }

            $newUploadedFile = $this->fileManager->copyUploadedFile($event->getModel(), $event->getUploadedFile());

            $event->setUploadedFile($newUploadedFile);
            $con->commit();
        } catch (\Exception $e) {
            $con->rollBack();

            throw $e;
        }
    }
498037
public function preSetData(FormEvent $event)
    {
        $entity = $event->getData();
    
        if ($entity instanceof FileInterface && null !== $entity->getId()){
            try {
                $this->fileManager->copyFileToTemporaryDirectory($entity);
            } catch (\Gaufrette\Exception\FileNotFound $e) {
                $event->setData(null);
            }
        }
    }
537983
public function onPreSetData(FormEvent $event)
    {
        $contentLanguages = [];
        $form = $event->getForm();

        /** @var TranslationAddData $data */
        $data = $event->getData();
        $contentType = $data->getContentType();

        if (null !== $contentType) {
            $contentLanguages = array_keys($contentType->getNames());
        }

        $this->addLanguageFields($form, $contentLanguages);
    }
694086
public function createForm(FormEvent $event): void
    {
        $admin = $event->getAdmin();
        $action = $admin->getAction();
        $configuration = $action->getConfiguration();

        if (!$configuration->get('use_form')) {
            return;
        }
        $entity = null;

        if (LAGAdminBundle::LOAD_STRATEGY_UNIQUE === $configuration->get('load_strategy')) {
            if (!$admin->getEntities()->isEmpty()) {
                $entity = $admin->getEntities()->first();
            }
        }

        if ('create' === $action->getName() || 'edit' === $action->getName()) {
            $form = $this->adminFormFactory->createEntityForm($admin, $event->getRequest(), $entity);
            $event->addForm($form, 'entity');
        }

        if ('delete' === $action->getName()) {
            $form = $this->adminFormFactory->createDeleteForm($action, $event->getRequest(), $entity);
            $event->addForm($form, 'delete');
        }
    }
535493
public function handleForm(FormEvent $event): void
    {
        $admin = $event->getAdmin();
        $action = $admin->getAction();

        if ('delete' === $action->getName()) {
            if (!$admin->hasForm('delete')) {
                return;
            }
            $form = $admin->getForm('delete');
            $this->handleDeleteForm($event->getRequest(), $form, $admin);
        }
    }
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'
            )
        );
    }
467700
public function handleAction(ActionEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        $this->checkLanguage($event->getEnvironment(), 'create' === $event->getAction()->getName());
    }