Displays a form to create a new BusinessTemplate entity.

@param string $id The id of the businessEntity

@throws \Exception

@Route("/{id}/new", name="victoire_business_template_new")
@Method("GET")

@return JsonResponse The entity and the form
172660
public function newAction($id)
    {
        //get the business entity
        $businessEntity = $this->getBusinessEntity($id);

        /** @var BusinessTemplate $view */
        $view = $this->get('victoire_business_page.BusinessTemplate_chain')->getBusinessTemplate($id);
        $view->setBusinessEntityId($businessEntity->getId());

        $form = $this->createCreateForm($view);

        $parameters = [
            'entity' => $view,
            'form'   => $form->createView(),
        ];

        return new JsonResponse([
            'html' => $this->container->get('templating')->render(
                'VictoireBusinessPageBundle:BusinessTemplate:new.html.twig',
                $parameters
            ),
            'success' => true,
        ]);
    }
386603
public function createAction()
    {
        // Load form
        $entityClass = $this->getModuleNamespace() . '\Entity\\' . $this->getEntityName();
        $entity      = new $entityClass();
        $form        = $this->getForm('Create' . $this->getEntityName());
        $form->bind($entity);

        // Implement Post/Redirect/Get pattern
        $prg = $this->prg();
        if ($prg instanceof Response) {
            return $prg;
        } else if (false !== $prg) {

            // Set form data
            $form->setData($prg);

            // Create account
            $result = $this->getService()->create();
            if ($result) {
                return $this->redirect()->toRoute($this->indexRoute);
            }
        }

        // Set up view model
        $viewModel = new ViewModel(array(
            'entityName' => $this->getEntityName(),
            'form'       => $form,
        ));
        $viewModel->setTemplate('infinity-base/crud/create');

        return $viewModel;
    }
870186
public function createEditForm($id) {
        $entity = $this->read_handler->get($id);
        return $form = $this->doCreate($this->getDefaultTypeClass(), $entity);
    }
1093642
public function show($id)
    {
        $template = $this->client->get(sprintf('templates/%d.json', $id));

        return new Template($this->response($template));
    }
87042
public function getByID($id)
    {
        $site = $this->entityManager->getRepository('Concrete\Core\Entity\Site\Site')
            ->find($id);
        $factory = new Factory($this->config);
        if (is_object($site)) {
            return $factory->createEntity($site);
        }
    }
510106
public function newInstance($id)
    {
        if (!isset($this->registered[$id])){
            throw new ComponentNotFoundException($id);
        }
        // create new object via factory
        $factory = $this->factories[$id] ?? null;
        if (!$factory || !is_callable($factory) || !method_exists($factory, '__invoke')){
            throw new FactoryNotFoundException($id);
        }
        // get current slot
        $slot = $this->slots[$id] ?? new Slot($id);
        // callback factory to get new instance
        $newInstance = $this->callbackFactory($id, $slot, $factory);
        return $newInstance;
    }
230198
public function show($id)
    {
        $message = $this->client->get(
            sprintf('buckets/%d/messages/%d.json', $this->bucket, $id)
        );

        return new Message($this->response($message));
    }
422317
public function advertListJsonAction($id)
    {
        $em = $this->getDoctrine()->getManager();

        $advert = $em->getRepository('EcommerceBundle:Advert')->find($id);
        /** @var \Kitchenit\AdminBundle\Services\DataTables\JsonList $jsonList */
        $jsonList = $this->get('json_list');
        $jsonList->setRepository($em->getRepository('EcommerceBundle:Transaction'));
        $jsonList->setAdvertId($advert->getId());
        $response = $jsonList->get();

        return new JsonResponse($response);
    }
283307
public function editAction($id = null)
    {
        $request = $this->getRequest();
        // the key used to lookup the template
        $templateKey = 'edit';

        $id = $request->get($this->admin->getIdParameter());
        $existingObject = $this->admin->getObject($id);

        if (!$existingObject) {
            throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
        }

        $this->checkParentChildAssociation($request, $existingObject);

        $this->admin->checkAccess('edit', $existingObject);

        $preResponse = $this->preEdit($request, $existingObject);
        if (null !== $preResponse) {
            return $preResponse;
        }

        $this->admin->setSubject($existingObject);
        $objectId = $this->admin->getNormalizedIdentifier($existingObject);

        $form = $this->admin->getForm();

        if (!\is_array($fields = $form->all()) || 0 === \count($fields)) {
            throw new \RuntimeException(
                'No editable field defined. Did you forget to implement the "configureFormFields" method?'
            );
        }

        $form->setData($existingObject);
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $isFormValid = $form->isValid();

            // persist if the form was valid and if in preview mode the preview was approved
            if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
                $submittedObject = $form->getData();
                $this->admin->setSubject($submittedObject);

                try {
                    $existingObject = $this->admin->update($submittedObject);

                    if ($this->isXmlHttpRequest()) {
                        return $this->renderJson([
                            'result' => 'ok',
                            'objectId' => $objectId,
                            'objectName' => $this->escapeHtml($this->admin->toString($existingObject)),
                        ], 200, []);
                    }

                    $this->addFlash(
                        'sonata_flash_success',
                        $this->trans(
                            'flash_edit_success',
                            ['%name%' => $this->escapeHtml($this->admin->toString($existingObject))],
                            'SonataAdminBundle'
                        )
                    );

                    // redirect to edit mode
                    return $this->redirectTo($existingObject);
                } catch (ModelManagerException $e) {
                    $this->handleModelManagerException($e);

                    $isFormValid = false;
                } catch (LockException $e) {
                    $this->addFlash('sonata_flash_error', $this->trans('flash_lock_error', [
                        '%name%' => $this->escapeHtml($this->admin->toString($existingObject)),
                        '%link_start%' => '<a href="'.$this->admin->generateObjectUrl('edit', $existingObject).'">',
                        '%link_end%' => '</a>',
                    ], 'SonataAdminBundle'));
                }
            }

            // show an error message if the form failed validation
            if (!$isFormValid) {
                if (!$this->isXmlHttpRequest()) {
                    $this->addFlash(
                        'sonata_flash_error',
                        $this->trans(
                            'flash_edit_error',
                            ['%name%' => $this->escapeHtml($this->admin->toString($existingObject))],
                            'SonataAdminBundle'
                        )
                    );
                }
            } elseif ($this->isPreviewRequested()) {
                // enable the preview template if the form was valid and preview was requested
                $templateKey = 'preview';
                $this->admin->getShow();
            }
        }

        $formView = $form->createView();
        // set the theme for the current Admin Form
        $this->setFormTheme($formView, $this->admin->getFormTheme());

        // NEXT_MAJOR: Remove this line and use commented line below it instead
        $template = $this->admin->getTemplate($templateKey);
        // $template = $this->templateRegistry->getTemplate($templateKey);

        return $this->renderWithExtraParams($template, [
            'action' => 'edit',
            'form' => $formView,
            'object' => $existingObject,
            'objectId' => $objectId,
        ], null);
    }
1285454
public function actionCreate($id)
    {
        $model = new Item();
        $model->pid = $id;
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            Yii::$app->session->setFlash('success', Yii::t('modules/page', 'Success'));
            return $this->redirect(['update', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
789507
public function show($id)
    {
        $apiRequest = RequestFactory::create();

        $resource = new GetResource(
            $this->serializer,
            $apiRequest->getFields(),
            $apiRequest->getIncludedRelationships()
        );

        $find = $this->findResourceCallable($id);

        return $this->addHeaders($resource->get($id, get_class($this->getDataModel()), $find));
    }
1055557
public function preview($id)
    {
        $campagne = $this->campagne->find($id);
        $data     = $this->mailjet->getHtml($campagne->api_campagne_id);

        return response($data);
    }
540764
public function show($id)
    {
        $questionnaire = $this->client->get(
            sprintf('buckets/%d/questionnaires/%d.json', $this->bucket, $id)
        );

        return new Questionnaire($this->response($questionnaire));
    }
802979
public function show($id)
    {
        $project = $this->client->get(sprintf('projects/%d.json', $id));

        return new Project($this->response($project));
    }
298194
public function generateEntityCodeAction($id = null)
    {
        $request = $this->getRequest();

        $id = $request->get($this->admin->getIdParameter());
        if ($id) {
            $subject = $this->admin->getObject($id);
            if (!$subject) {
                $error = sprintf('unable to find the object with id : %s', $id);

                return new JsonResponse(['error' => $error]);
            }
            try {
                $this->admin->checkAccess('edit', $subject); // TODO: is it necessary ? (we are not editing the entity)
            } catch (Exception $exc) {
                $error = $exc->getMessage();

                return new JsonResponse(['error' => $error]);
            }
        } else {
            $subject = $this->admin->getNewInstance();
        }

        $this->admin->setSubject($subject);

        $form = $this->admin->getForm();
        $form->setData($subject);
        $form->submit($request->request->get($form->getName()));
        $entity = $form->getData();

        $field = $request->query->get('field', 'code');
        $registry = $this->get('blast_core.code_generators');
        $generator = $registry::getCodeGenerator(get_class($entity), $field);
        try {
            $code = $generator::generate($entity);

            return new JsonResponse(['code' => $code]);
        } catch (\Exception $exc) {
            $error = $this->get('translator')->trans($exc->getMessage());

            return new JsonResponse(['error' => $error, 'generator' => get_class($generator)]);
        }
    }
1064303
public function show($id)
    {
        $todolist = $this->client->get(
            sprintf('buckets/%d/todolists/%d.json', $this->bucket, $id)
        );

        return new TodoList($this->response($todolist));
    }
1132373
public function putAction(Request $request, $id)
    {
        $locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));

        try {
            $attribute = $this->getManager()->save(
                $request->request->all(),
                $locale,
                $this->getUser()->getId(),
                $id
            );
            $view = $this->view($attribute, 200);
        } catch (AttributeDependencyNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 400);
        } catch (AttributeNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 404);
        } catch (MissingAttributeException $exc) {
            $exception = new MissingArgumentException(self::$entityName, $exc->getAttribute());
            $view = $this->view($exception->toArray(), 400);
        }

        return $this->handleView($view);
    }