Displays a form to create a new SurveyCategory entity.

@Route("/new", name="surveycategory_new")
@Method("GET")
@Template()
546435
public function newAction()
    {
        $entity = new SurveyCategory();
        $form   = $this->createCreateForm($entity);

        return array(
            '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(),
        );
    }
121581
public function newAction(Request $request, $widget = false)
    {
        $this->checkIfUserHasPermission(Permission::CREATE_DELETE);

        list($parentEntity, $association) = $this->getParentEntityDefinition($request);

        $this->getEventDispatcher()->dispatch(
            Events::PRE_CRUD_CONTROLLER_ACTION,
            new CrudControllerActionEvent($this->meta, __FUNCTION__)
        );

        $isXmlHttpRequest = $request->isXmlHttpRequest();

        if ($isXmlHttpRequest) {
            $widget = true;
        }

        $entityClass = $this->entityClass;
        $entity = new $entityClass();

        if ($this->meta->hasParent()) {
            $this->getPropertyAccessor()->setValue($entity, $association, $parentEntity);
        }
        if ($this->getTranslationJoiner()->isTranslatable($entityClass)) {
            $this->getTranslationsInitializer()->initializeTranslations($entity, $this->getParameter('darvin_admin.locales'));
        }

        $this->getNewActionFilterFormHandler()->handleForm($entity, $request);

        $form = $this->getAdminFormFactory()->createEntityForm(
            $this->meta,
            $entity,
            'new',
            $this->getAdminRouter()->generate($entity, $entityClass, AdminRouter::TYPE_NEW),
            $widget ? [AdminFormFactory::SUBMIT_INDEX] : $this->getEntityFormSubmitButtons()
        )->handleRequest($request);

        if (!$form->isSubmitted()) {
            return new Response($this->renderNewTemplate($widget, $form, $parentEntity));
        }

        $success = $form->isValid();

        if ($success) {
            $em = $this->getEntityManager();
            $em->persist($entity);
            $em->flush();

            $this->getEventDispatcher()->dispatch(CrudEvents::CREATED, new CreatedEvent($this->getUser(), $entity));

            $html = '';
            $message = $this->meta->getBaseTranslationPrefix().'action.new.success';
        } else {
            $html = $this->renderNewTemplate($widget, $form, $parentEntity);
            $message = FlashNotifierInterface::MESSAGE_FORM_ERROR;
        }
        if ($isXmlHttpRequest) {
            return new AjaxResponse($html, $success, $message, [], $success ? '' : null);
        }

        $this->getFlashNotifier()->done($success, $message);

        return $success
            ? $this->successRedirect($form, $entity)
            : new Response($this->renderNewTemplate($widget, $form, $parentEntity));
    }
812722
public function newAction()
    {
        $entity = new ProductOrderItem();
        $form   = $this->createCreateForm($entity);

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
        );
    }
390009
public function newAction()
    {
        $entity = new Feature();

        if ($this->getRequest()->query->has('category')) {
            $em = $this->getDoctrine()->getManager();

            $category = $em->getRepository('EcommerceBundle:Category')->
                find($this->getRequest()->query->get('category'));

            $entity->setCategory($category);
        }

        $form   = $this->createForm(new FeatureType(), $entity);

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
        );
    }
293562
protected function crudCreate(Request $request = null)
    {
        try{
            
            $entity = $this->getEntity();
            $form = $this->createAndBindForm($request, $this->getEntityType() , $entity);
            $page = static::NEW_VIEW;
            
            if ($form->isValid()) {
                $this->saveEntity($entity);                
                if($request->get('_loop_create')){
                    $form = $this->createForm($this->getEntityType(), $this->getEntity());
                }else{
                    $page = static::SHOW_VIEW;
                    $form = $this->createDeleteForm($entity->getId());
                }
                $form = $form->createView();
                return $this->render($page, $this->commonsResponseVars(compact('entity','form')));
            }
            $form = $form->createView();
            return $this->success($page, $this->commonsResponseVars(compact('entity','form')));
            
        }catch(\Exception $e){
          return $this->failure($e);
        }
    }
4407
public function update_category($updateid, $newparent, $newname, $newinfo, $newinfoformat = FORMAT_HTML,
            $idnumber = null, $redirect = true) {
        global $CFG, $DB;
        if (empty($newname)) {
            print_error('categorynamecantbeblank', 'question');
        }

        // Get the record we are updating.
        $oldcat = $DB->get_record('question_categories', array('id' => $updateid));
        $lastcategoryinthiscontext = question_is_only_child_of_top_category_in_context($updateid);

        if (!empty($newparent) && !$lastcategoryinthiscontext) {
            list($parentid, $tocontextid) = explode(',', $newparent);
        } else {
            $parentid = $oldcat->parent;
            $tocontextid = $oldcat->contextid;
        }

        // Check permissions.
        $fromcontext = context::instance_by_id($oldcat->contextid);
        require_capability('moodle/question:managecategory', $fromcontext);

        // If moving to another context, check permissions some more, and confirm contextid,stamp uniqueness.
        $newstamprequired = false;
        if ($oldcat->contextid != $tocontextid) {
            $tocontext = context::instance_by_id($tocontextid);
            require_capability('moodle/question:managecategory', $tocontext);

            // Confirm stamp uniqueness in the new context. If the stamp already exists, generate a new one.
            if ($DB->record_exists('question_categories', array('contextid' => $tocontextid, 'stamp' => $oldcat->stamp))) {
                $newstamprequired = true;
            }
        }

        if ((string) $idnumber === '') {
            $idnumber = null;
        } else if (!empty($tocontextid)) {
            // While this check already exists in the form validation, this is a backstop preventing unnecessary errors.
            if ($DB->record_exists('question_categories',
                    ['idnumber' => $idnumber, 'contextid' => $tocontextid])) {
                $idnumber = null;
            }
        }

        // Update the category record.
        $cat = new stdClass();
        $cat->id = $updateid;
        $cat->name = $newname;
        $cat->info = $newinfo;
        $cat->infoformat = $newinfoformat;
        $cat->parent = $parentid;
        $cat->contextid = $tocontextid;
        if ($idnumber) {
            $cat->idnumber = $idnumber;
        }
        if ($newstamprequired) {
            $cat->stamp = make_unique_id_code();
        }
        $DB->update_record('question_categories', $cat);

        // Log the update of this category.
        $event = \core\event\question_category_updated::create_from_question_category_instance($cat);
        $event->trigger();

        // If the category name has changed, rename any random questions in that category.
        if ($oldcat->name != $cat->name) {
            $where = "qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = ?";

            $randomqtype = question_bank::get_qtype('random');
            $randomqname = $randomqtype->question_name($cat, false);
            $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));

            $randomqname = $randomqtype->question_name($cat, true);
            $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
        }

        if ($oldcat->contextid != $tocontextid) {
            // Moving to a new context. Must move files belonging to questions.
            question_move_category_to_context($cat->id, $oldcat->contextid, $tocontextid);
        }

        // Cat param depends on the context id, so update it.
        $this->pageurl->param('cat', $updateid . ',' . $tocontextid);
        if ($redirect) {
            redirect($this->pageurl); // Always redirect after successful action.
        }
    }
1235994
public function newAction()
    {
        $entity = new Tax();
        $form   = $this->createForm(new TaxType(), $entity);

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
        );
    }
1069656
public function createAction()
	{
		$this->isPostRequest();

		$page = new GroupPage();

		$localeId = $this->getCurrentLocale()->getId();

		$localization = Localization::factory($page, $localeId);
		/* @var $localization \Supra\Package\Cms\Entity\GroupLocalization */

		$title = trim($this->getRequestParameter('title', ''));

		if (empty($title)) {
			throw new CmsException(null, 'Group title cannot be empty.');
		}

		$localization->setTitle($title);

		$parentLocalizationId = $this->getRequestParameter('parent_id');

		if (empty($parentLocalizationId)) {
			throw new \UnexpectedValueException(
					'Parent ID is empty while it is not allowed Group to be root.'
			);
		}

		$parentLocalization = $this->getEntityManager()
					->find(Localization::CN(), $parentLocalizationId);

		if ($parentLocalization === null) {
			throw new CmsException(null, sprintf(
					'Specified parent page [%s] not found.',
					$parentLocalizationId
			));
		}

		$entityManager = $this->getEntityManager();

		$entityManager->transactional(function (EntityManager $entityManager) use ($page, $localization, $parentLocalization) {

			$this->lockNestedSet($page);

			$entityManager->persist($page);
			$entityManager->persist($localization);

			if ($parentLocalization) {
				$page->moveAsLastChildOf($parentLocalization->getMaster());
			}

			$this->unlockNestedSet($page);
		});

		return new SupraJsonResponse($this->loadNodeMainData($localization));
	}
385235
public function newAction()
    {
        $entity = new Category();
        $form   = $this->createForm(new CategoryType(), $entity);

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
        );
    }
321972
public function newAction()
    {
        $scope = new Scope();
        $form   = $this->createCreateForm($scope);

        return $this->render('ChillMainBundle:Scope:new.html.twig', array(
            'entity' => $scope,
            'form'   => $form->createView(),
        ));
    }
158187
public function createAction()
	{
		$this->isPostRequest();

		$type = $this->getRequestParameter('type');

		$page = null;

		switch ($type) {
			case Entity::APPLICATION_DISCR:
				$page = new ApplicationPage(
						$this->getRequestParameter('application_id')
				);
				break;
			case Entity::PAGE_DISCR:
				$page = new Page();
				break;
			default:
				throw new \InvalidArgumentException(sprintf('Unknown page type [%s]', $type));
		}

		$localeId = $this->getCurrentLocale()->getId();

		$localization = Localization::factory($page, $localeId);
		/* @var $localization PageLocalization */

		if (! $localization instanceof PageLocalization) {
			throw new \UnexpectedValueException(sprintf(
					'Expecting created localization to be instance of PageLocalization, [%s] received.',
					get_class($localization)
			));
		}

		$templateId = $this->getRequestParameter('template');
		
		$template = $this->getEntityManager()
				->find(Template::CN(), $templateId);
		/* @var $template Template */

		if ($template === null) {
			throw new CmsException(null, 'Template not specified or found.');
		}

		$templateLocalization = $template->getLocalization($localeId);

		if ($templateLocalization === null) {
			throw new \InvalidArgumentException(
					"Specified template has no localization for [{$localeId}] locale."
			);
		}

		$localization->setTemplate($template);

		// copy values from template
		$localization->setIncludedInSearch($templateLocalization->isIncludedInSearch());
		$localization->setVisibleInMenu($templateLocalization->isVisibleInMenu());
		$localization->setVisibleInSitemap($templateLocalization->isVisibleInSitemap());

		$title = trim($this->getRequestParameter('title', ''));

		if (empty($title)) {
			throw new CmsException(null, 'Page title cannot be empty.');
		}
		
		$localization->setTitle($title);

		$parentLocalization = $pathPart
				= null;

		$parentLocalizationId = $this->getRequestParameter('parent_id');
		
		if (! empty($parentLocalizationId)) {

			$parentLocalization = $this->getEntityManager()
					->find(Localization::CN(), $parentLocalizationId);

			if ($parentLocalization === null) {
				throw new CmsException(null, sprintf(
						'Specified parent page [%s] not found.',
						$parentLocalizationId
				));
			}

			$pathPart = trim($this->getRequestParameter('path'));

			// path part cannot be empty for non-root pages.
			if (empty($pathPart)) {
				throw new CmsException(null, 'Page path can not be empty.');
			}
		}

		if ($parentLocalization && $pathPart) {
			$localization->setPathPart($pathPart);
		} else {
			$rootPath = $localization->getPathEntity();
			$rootPath->setPath('');
			$localization->setPathPart('');
		}

		$entityManager = $this->getEntityManager();

		$entityManager->transactional(function (EntityManager $entityManager) use ($page, $localization, $parentLocalization) {

			$this->lockNestedSet($page);

			$entityManager->persist($page);
			$entityManager->persist($localization);

			if ($parentLocalization) {
				$page->moveAsLastChildOf($parentLocalization->getMaster());
			}

			$this->unlockNestedSet($page);
		});

		return new SupraJsonResponse($this->loadNodeMainData($localization));
	}
1050815
public function newAction(Request $request)
    {
        $slider = new Slider();
        $form = $this->createForm('CoreExtraBundle\Form\SliderType', $slider,  array('uploadDir'=> 'uploads/images/slider' ));
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            
            //clean image form
            $this->get('core_manager')->cleanImageForm($request->files->get('slider'), $slider);
            
            $em->persist($slider);
            $em->flush();
            
            $this->get('session')->getFlashBag()->add('success', 'slider.created');

            return $this->redirectToRoute('coreextra_slider_index');
        }

        return array(
            'entity' => $slider,
            'form' => $form->createView(),
        );
    }
136876
public function newAction()
        {

            $oCustomer = new Customer();
            $form      = $this->createCreateForm($oCustomer);

            return $this->render('SlashworksAppBundle:Customer:new.html.twig', array(
                'entity' => $oCustomer,
                'form'   => $form->createView(),
            ));
        }
314131
public function newAction(Request $request)
    {
        $this->get('white_october_breadcrumbs')
            ->addItem('Home', $this->get('router')->generate('_homepage'))
            ->addItem('Vendors', $this->get('router')->generate('phospr_vendor'))
            ->addItem('New', $this->get('router')->generate('phospr_vendor_new'))
        ;

        $vendor = new Vendor();
        $vendor->setOrganization(
            $this->get('phospr.organization_handler')->getOrganization()
        );

        $form = $this->createForm(new VendorType(), $vendor, array(
            'label' => 'Create',
        ));

        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->get('doctrine')->getManager();
            $em->persist($form->getData());
            $em->flush();

            return $this->redirect($this->generateUrl(
                'phospr_vendor_show', array(
                    'slug' => $vendor->getSlug(),
                )
            ));
        }

        return array('form'  => $form->createView());
    }
1054217
public function newAction(Request $request)
    {
        $operation = null;

        /*
         * Set Activity's context from user's choice.
         */
        /** @var ActivityWizard $wizard */
        $wizard = $this->get('campaignchain.core.activity.wizard');
        if (!$wizard->getCampaign()) {
            return $this->redirectToRoute('campaignchain_core_activities_new');
        }

        $campaignService = $this->get('campaignchain.core.campaign');
        $campaign = $campaignService->getCampaign($wizard->getCampaign());
        $locationService = $this->get('campaignchain.core.location');
        if($wizard->getLocation()) {
            $location = $locationService->getLocation($wizard->getLocation());
        } else {
            $location = null;
        }

        $this->setActivityContext($campaign, $location);

        $activity = $wizard->getNewActivity();
        $activity->setEqualsOperation($this->parameters['equals_operation']);

        $form = $this->createForm(
            ActivityType::class,
            $activity,
            $this->getActivityFormTypeOptions('new')
        );

        $form->handleRequest($request);

        $em = $this->getDoctrine()->getManager();

        if ($form->isValid()) {
            try {
                $em->getConnection()->beginTransaction();

                $activity = $this->createActivity($activity, $form);

                $this->addFlash(
                    'success',
                    'Your new activity <a href="' . $this->generateUrl('campaignchain_core_activity_edit', array('id' => $activity->getId())) . '">' . $activity->getName() . '</a> was created successfully.'
                );

                $wizard->end();

                $em->getConnection()->commit();

                return $this->redirect($this->generateUrl('campaignchain_core_activities'));
            } catch(\Exception $e) {
                $em->getConnection()->rollback();

                if($this->get('kernel')->getEnvironment() == 'dev'){
                    $message = $e->getMessage().' '.$e->getFile().' '.$e->getLine().'<br/>'.$e->getTraceAsString();
                } else {
                    $message = $e->getMessage();
                }
                $this->addFlash(
                    'warning',
                    $message
                );

                $this->getLogger()->error($e->getMessage(), array(
                    'file' => $e->getFile(),
                    'line' => $e->getLine(),
                    'trace' => $e->getTrace(),
                ));
            }
        }

        if($location){
            $channelModule = $wizard->getChannelModule();
            $channelModuleBundle = $wizard->getChannelModuleBundle();
        } else {
            $channelModule = null;
            $channelModuleBundle = null;
        }

        /*
         * Define default rendering options and then apply those defined by the
         * module's handler if applicable.
         */
        $defaultRenderOptions = array(
            'template' => 'CampaignChainCoreBundle:Operation:new.html.twig',
            'vars' => array(
                'page_title' => 'New Activity',
                'activity' => $activity,
                'campaign' => $this->campaign,
                'campaign_module' => $this->campaign->getCampaignModule(),
                'channel_module' => $channelModule,
                'channel_module_bundle' => $channelModuleBundle,
                'location' => $this->location,
                'form' => $form->createView(),
                'form_submit_label' => 'Save',
                'form_cancel_route' => 'campaignchain_core_activities_new'
            )
        );

        $handlerRenderOptions = $this->handler->getNewRenderOptions();

        return $this->renderWithHandlerOptions($defaultRenderOptions, $handlerRenderOptions);
    }
452685
public function newAction()
    {
        $entity = new Tag();
        $form   = $this->createForm(new TagType(), $entity);

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