Creates a child resource.

@param Request $request
@return \Symfony\Component\HttpFoundation\Response
761743
public function newChildAction(Request $request)
    {
        $this->isGranted('CREATE');

        $context = $this->loadContext($request);

        $resourceName = $this->config->getResourceName();
        $resource = $context->getResource($resourceName);

        $child = $this->createNewFromParent($context, $resource);

        if (0 < strlen($referer = $request->headers->get('referer'))) {
            $cancelPath = $referer;
        } else {
            $cancelPath = $this->generateResourcePath($request);
        }

        $form = $this
            ->createForm($this->config->getFormType(), $child, [
                'action' => $this->generateUrl(
                    $this->config->getRoute('new_child'),
                    $context->getIdentifiers(true)
                ),
                'method' => 'POST',
                'attr' => [
                    'class' => 'form-horizontal form-with-tabs',
                ],
                'admin_mode' => true,
                '_redirect_enabled' => true,
            ])
            ->add('actions', 'form_actions', [
                'buttons' => [
                    'saveAndList' => [
                        'type' => 'submit', 'options' => [
                            'button_class' => 'primary',
                            'label' => 'ekyna_core.button.save_and_list',
                            'attr' => [
                                'icon' => 'list',
                            ],
                        ],
                    ],
                    'save' => [
                        'type' => 'submit', 'options' => [
                            'button_class' => 'primary',
                            'label' => 'ekyna_core.button.save',
                            'attr' => [
                                'icon' => 'ok',
                            ],
                        ],
                    ],
                    'cancel' => [
                        'type' => 'button', 'options' => [
                            'label' => 'ekyna_core.button.cancel',
                            'button_class' => 'default',
                            'as_link' => true,
                            'attr' => [
                                'class' => 'form-cancel-btn',
                                'icon' => 'remove',
                                'href' => $cancelPath,
                            ],
                        ],
                    ],
                ],
            ])
        ;

        $form->handleRequest($this->getRequest());
        if ($form->isValid()) {

            $this->getRepository()->persistAsLastChildOf($child, $resource);

            // TODO use ResourceManager
            $event = $this->getOperator()->create($child);

            /* if ($request->isXmlHttpRequest()) {
                if ($event->hasErrors()) {
                    $errorMessages = $event->getErrors();
                    $errors = [];
                    foreach ($errorMessages as $message) {
                        $errors[] = $message->getMessage();
                    }
                    return new JsonResponse(array('error' => implode(', ', $errors)));
                }

                return new JsonResponse(array(
                    'id' => $resource->getId(),
                    'name' => (string)$resource,
                ));
            }*/

            $event->toFlashes($this->getFlashBag());

            if (!$event->hasErrors()) {
                /** @noinspection PhpUndefinedMethodInspection */
                if ($form->get('actions')->get('saveAndList')->isClicked()) {
                    $redirectPath = $this->generateResourcePath($resource, 'list');
                } elseif (null === $redirectPath = $form->get('_redirect')->getData()) {
                    $redirectPath = $this->generateResourcePath($child);
                }
                return $this->redirect($redirectPath);
            }
        }

        return $this->render(
            $this->config->getTemplate('new_child.html'),
            $context->getTemplateVars([
                'child' => $child,
                'form' => $form->createView()
            ])
        );
    }
1000158
public function createAction(Request $request)
    {
        $entity = $this->get('oktolab_media')->createEpisode();
        $form = $this->createCreateForm($entity);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            $em->flush();

            $this->get('session')->getFlashBag()->add(
                'success',
                'oktolab_media.success_create_episode'
            );

            return $this->redirect(
                $this->generateUrl(
                    'oktolab_episode_show',
                    ['uniqID' => $entity->getUniqID()]
                )
            );
        } else {
            $this->get('session')->getFlashBag()->add(
                'error',
                'oktolab_media.error_create_episode'
            );
        }

        return [
            'entity' => $entity,
            'form'   => $form->createView(),
        ];
    }
814115
public function createAction(Request $request)
    {
        $entity = new Collection();
        $form = $this->createCreateForm($entity);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            $em->flush();

            return $this->redirect($this->generateUrl('admin_collection_show', array('id' => $entity->getId())));
        }

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
880787
public function create(Request $request)
    {
        $manager = $this->manager;

        $result = $manager->create($request->only($this->fillable));

        if (!$result->ok()) {
            return $this->response(['errors' => $result->getSimpleErrors()], Response::HTTP_BAD_REQUEST);
        }

        return $this->response($this->serialize($result->getResource(), $request), Response::HTTP_CREATED);
    }
968377
public function newAction(Request $request)
    {
        $provincium = new Provincia();
        $form = $this->createForm('Matudelatower\UbicacionBundle\Form\Type\ProvinciaType', $provincium);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($provincium);
            $em->flush();

            return $this->redirectToRoute('provincia_show', array('id' => $provincium->getId()));
        }

        return $this->render('UbicacionBundle:provincia:new.html.twig', array(
            'provincium' => $provincium,
            'form' => $form->createView(),
        ));
    }
1218225
public function createMainMenu(Request $request)
    {
        $menu = $this->factory->createItem('root');

        $repositoriesMenu = $this->repositoryMenu->getMenu();

        foreach ($repositoriesMenu as $repositoryActions) {
            $oneRepoMenu = $menu->addChild($repositoryActions->getName());

            /** @var RepositoryActionInterface $action */
            foreach ($repositoryActions as $action) {
                $oneRepoMenu->addChild($action->getName(), ['route' => $action->getRouteName()]);
            }
        }

        return $menu;
    }
650695
public function createAction(Request $request)
    {
        $this->denyAccessUnlessGranted('ROLE_ADMIN');

        $domain = new Domain();

        $form = $this->createForm(DomainType::class, $domain);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($domain);
            $em->flush();

            $this->addFlash('success', 'Domaim has been created successfully');

            return $this->redirectToRoute('opifer_cms_domain_edit', ['id' => $domain->getId()]);
        }

        return $this->render('OpiferCmsBundle:Backend/Domain:create.html.twig', [
            'domain' => $domain,
            'form' => $form->createView()
        ]);
    }
175216
public function createAction(Request $request): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('class', 'create'));
        $form = $this->formFactory->createContentTypeGroup(
            new ContentTypeGroupCreateData()
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (ContentTypeGroupCreateData $data) {
                $createStruct = $this->contentTypeService->newContentTypeGroupCreateStruct(
                    $data->getIdentifier()
                );
                $group = $this->contentTypeService->createContentTypeGroup($createStruct);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Content type group '%name%' created.") */
                        'content_type_group.create.success',
                        ['%name%' => $data->getIdentifier()],
                        'content_type'
                    )
                );

                return new RedirectResponse($this->generateUrl('ezplatform.content_type_group.view', [
                    'contentTypeGroupId' => $group->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->render('@ezdesign/admin/content_type_group/create.html.twig', [
            'form' => $form->createView(),
        ]);
    }
738598
public function createAction(Request $request)
    {
        $site = new Site();

        $originalDomains = new ArrayCollection();
        foreach ($site->getDomains() as $domain) {
            $originalDomains->add($domain);
        }

        $form = $this->createForm(SiteType::class, $site);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            // Add new domain
            foreach ($form->getData()->getDomains() as $domain) {
                $domain->setSite($site);
            }
            $em->persist($domain);

            $em->persist($site);
            $em->flush();

            return $this->redirectToRoute('opifer_cms_site_edit', ['id' => $site->getId()]);
        }

        return $this->render('OpiferCmsBundle:Backend/Site:create.html.twig', [
            'form' => $form->createView(),
        ]);
    }
816826
public function createAction(Request $request)
    {
        $templateRepository = $this->get('phlexible_media_template.template_manager');

        $type = $request->get('type');
        $key = $request->get('key');

        switch ($type) {
            case 'image':
                $template = new ImageTemplate();
                $template->setCache(false);
                break;
            case 'video':
                $template = new VideoTemplate();
                $template->setCache(true);
                break;
            case 'audio':
                $template = new AudioTemplate();
                $template->setCache(true);
                break;
            default:
                throw new InvalidArgumentException("Unknown template type $type");
        }

        $template->setKey($key);

        $templateRepository->updateTemplate($template);

        return new ResultResponse(true, 'New "'.$type.'" template "'.$key.'" created.');
    }
999527
public function treeAction(Request $request)
    {
        $siterootId = $request->get('siteroot_id');
        $tid = $request->get('node');
        $language = $request->get('language');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $elementService = $this->get('phlexible_element.element_service');
        $nodeSerializer = $this->get('phlexible_tree.node_serializer');

        // TODO: switch to master language of element
        $defaultLanguage = $this->container->getParameter('phlexible_cms.languages.default');

        $tree = $treeManager->getBySiteRootId($siterootId);
        $rootNode = $tree->getRoot();

        $data = [];
        if ($rootNode) {
            if ($tid === null || $tid < 1) {
                $data = [$nodeSerializer->serializeNode($rootNode, $language, $this->container->get('security.token_storage')->getToken())];
            } else {
                $node = $tree->get($tid);

                // check if children of this node should be shown
                $element = $elementService->findElement($node->getTypeId());
                $elementtype = $elementService->findElementtype($element);

                $nodes = $tree->getChildren($node);
                if (!empty($nodes) && !$elementtype->getHideChildren()) {
                    $data = $nodeSerializer->serializeNodes($nodes, $language, $this->container->get('security.token_storage')->getToken());
                }
            }
        }

        return new JsonResponse($data);
    }
874128
protected function doRequest(Request $request)
    {

        $this->client->send($request, $response = new Response());

        return $response;
    }
14473
public static function factory(Request $request)
    {
        /** @var Action[] $actions */
        $actions = self::getAllActions($request);

        foreach ($actions as $actionType) {
            if (empty($action)) {
                $action = $actionType;
                continue;
            }

            $posPrevious = self::getPriority($action);
            $posCurrent  = self::getPriority($actionType);

            if ($posCurrent > $posPrevious) {
                $action = $actionType;
            }
        }

        if (!empty($action)) {
            return $action;
        }

        return new ActionPageview($request);
    }
47693
public function createAction(Request $request)
    {
        $entity = new Product();
        $entity = $this->addProductItemFieldData($entity);
        $form = $this->createCreateForm($entity);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            /* persist product */
            $em->persist($entity);

            if (is_null($entity->getMediaGallery())) {
                /* create media gallery */
                $mediaGallery = new Gallery();
                $mediaGallery->setName($entity->getName());
                $mediaGallery->setEnabled(true);
                $em->persist($mediaGallery);

                /* set media gallery */
                $entity->setMediaGallery($mediaGallery);
            }

            $em->flush();

            $this->get('session')->getFlashBag()->add(
                'success', $this->get('translator')->trans('save_success')
            );

            return $this->redirect($this->generateUrl('admin_product_show', array('id' => $entity->getId())));
        } else {
            $this->get('session')->getFlashBag()->add(
                'warning', $this->get('translator')->trans('save_fail')
            );
        }

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
1021092
public function createAction(Request $request)
    {
        $title = $request->get('title');
        $type = $request->get('type');
        $uniqueId = $request->get('unique_id');

        if (!$uniqueId) {
            $uniqueId = preg_replace('/[^a-z0-9_]/', '_', strtolower($title));
        }

        $elementtypeService = $this->get('phlexible_elementtype.elementtype_service');
        $elementtypeService->createElementtype($type, $uniqueId, $title, null, null, [], $this->getUser()->getId());

        return new ResultResponse(true, 'Element Type created.');
    }
4268
public function newAction(Request $request)
    {
        $this->denyAccessUnlessGranted(ContributionActionInterface::CREATE, UserInterface::ENTITY_TYPE);

        $userClass = $this->container->getParameter('open_orchestra_user.document.user.class');
        /** @var UserInterface $user */
        $user = new $userClass();
        $user->setEmail($request->get('email'));
        $user->setLastName($request->get('lastName'));
        $user->setFirstName($request->get('firstName'));

        $form = $this->createForm('oo_registration_user', $user, array(
                'action' => $this->generateUrl('open_orchestra_user_admin_new'),
                'required_password' => true,
                'validation_groups' => array('Registration'),
            )
        );

        $form->handleRequest($request);

        if ($form->isValid()) {
            $documentManager = $this->get('object_manager');
            $documentManager->persist($user);
            $documentManager->flush();
            $message = $this->get('translator')->trans('open_orchestra_user_admin.new.success');

            $this->dispatchEvent(UserEvents::USER_CREATE, new UserEvent($user));
            $response = new Response(
                $message,
                Response::HTTP_CREATED,
                array('Content-type' => 'text/plain; charset=utf-8', 'userId' => $user->getId())
            );

            return $response;
        }

        return $this->renderAdminForm($form);
    }
696284
public function createAction(Request $request)
    {
        if ($this->get('session')->has('module')) {
            // get the last module from the session to fill some defaults for the new one
            $tmpModule = $this->get('session')->get('module');

            // setup a fresh module object
            $module = new Module();
            $module->setStyle($tmpModule->getStyle());
        }
        else {
            // setup a fresh module object
            $module = new Module();

            // fill it with some defaults
            $module->setStyle('less');
        }

        // create form
        $form = $this->createForm(new ModuleType(), $module);

        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);

            if ($form->isValid()) {
                // set default templates
                $module->addTemplate(strtolower($module->getName()));

                // save the module in the session
                $this->get('session')->set('module', $module);

                // create the module in the filesystem
                try {
                    $moduleManager = $this->get('terrific.composer.module.manager');
                    $moduleManager->createModule($module);

                    $this->get('session')->setFlash('notice', 'Module ' . ucfirst($module->getName()) . ' created successfully');
                }
                catch (\Exception $e) {
                    $logger = $this->get('logger');
                    $logger->err($e->getMessage());

                    $this->get('session')->setFlash('notice', 'Module could not be created: ' . $e->getMessage());
                }

                if ($request->get('addskin', false)) {
                    // redirect to the add skin form
                    return $this->redirect($this->generateUrl('composer_add_skin'));
                }
                else {
                    // redirect to the create module form
                    return $this->redirect($this->generateUrl('composer_create_module'));
                }
            }
        }

        return array('form' => $form->createView());
    }