/** * Displays and processes a content creation form. Showing the form does not create a draft in the repository. * * @param int $contentTypeIdentifier ContentType id to create * @param string $language Language code to create the content in (eng-GB, ger-DE, ...)) * @param int $parentLocationId Location the content should be a child of * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function createWithoutDraftAction($contentTypeIdentifier, $language, $parentLocationId, Request $request) { $contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); $data = (new ContentCreateMapper())->mapToFormData($contentType, ['mainLanguageCode' => $language, 'parentLocation' => $this->locationService->newLocationCreateStruct($parentLocationId)]); $form = $this->createForm(ContentEditType::class, $data, ['languageCode' => $language]); $form->handleRequest($request); if ($form->isValid()) { $this->contentActionDispatcher->dispatchFormAction($form, $data, $form->getClickedButton()->getName()); if ($response = $this->contentActionDispatcher->getResponse()) { return $response; } } return $this->render('EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig', ['form' => $form->createView(), 'languageCode' => $language, 'pagelayout' => $this->pagelayout]); }
public function editPolicyAction(Request $request, $roleId, $policyId = null) { $role = $this->roleService->loadRole($roleId); try { $roleDraft = $this->roleService->loadRoleDraftByRoleId($roleId); } catch (NotFoundException $e) { // The draft doesn't exist, let's create one $roleDraft = $this->roleService->createRoleDraft($role); } $policy = new PolicyDraft(['innerPolicy' => new Policy()]); if ($policyId) { foreach ($roleDraft->getPolicies() as $policy) { if ($policy->originalId == $policyId) { goto buildFormData; } } throw new BadRequestHttpException($this->translator->trans('role.error.policy_not_found', ['%policyId%' => $policyId, '%roleId%' => $roleId], 'role')); } buildFormData: $limitationTypes = $policy->module ? $this->roleService->getLimitationTypesByModuleFunction($policy->module, $policy->function) : []; $policyData = (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft, 'initialRole' => $role, 'availableLimitationTypes' => $limitationTypes]); $actionUrl = $this->generateUrl('admin_policyEdit', ['roleId' => $roleId, 'policyId' => $policyId]); $form = $this->createForm('ezrepoforms_policy_edit', $policyData); $form->handleRequest($request); if ($form->isValid()) { $this->policyActionDispatcher->dispatchFormAction($form, $policyData, $form->getClickedButton() ? $form->getClickedButton()->getName() : null); if ($response = $this->policyActionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } return $this->render('eZPlatformUIBundle:Role:edit_policy.html.twig', ['form' => $form->createView(), 'actionUrl' => $actionUrl, 'policy' => $policyData]); }
public function updateContentTypeAction(Request $request, $contentTypeId, $languageCode = null) { $languageCode = $languageCode ?: $this->prioritizedLanguages[0]; // First try to load the draft. // If it doesn't exist, create it. try { $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId); } catch (NotFoundException $e) { $contentTypeDraft = $this->contentTypeService->createContentTypeDraft($this->contentTypeService->loadContentType($contentTypeId)); } $contentTypeData = (new ContentTypeDraftMapper())->mapToFormData($contentTypeDraft); $form = $this->createForm('ezrepoforms_contenttype_update', $contentTypeData, ['languageCode' => $languageCode]); $actionUrl = $this->generateUrl('admin_contenttypeUpdate', ['contentTypeId' => $contentTypeId, 'languageCode' => $languageCode]); // Synchronize form and data. $form->handleRequest($request); $hasErrors = false; if ($form->isValid()) { $this->contentTypeActionDispatcher->dispatchFormAction($form, $contentTypeData, $form->getClickedButton() ? $form->getClickedButton()->getName() : null, ['languageCode' => $languageCode]); if ($response = $this->contentTypeActionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } elseif ($form->isSubmitted()) { $hasErrors = true; } return $this->render('eZPlatformUIBundle:ContentType:update_content_type.html.twig', ['form' => $form->createView(), 'action_url' => $actionUrl, 'contentTypeName' => $contentTypeDraft->getName($languageCode), 'contentTypeDraft' => $contentTypeDraft, 'modifier' => $this->userService->loadUser($contentTypeDraft->modifierId), 'languageCode' => $languageCode, 'hasErrors' => $hasErrors]); }
/** * Updates a role. * * @param int $roleId Role ID * * @return \Symfony\Component\HttpFoundation\Response */ public function updateRoleAction(Request $request, $roleId) { try { $roleDraft = $this->roleService->loadRoleDraft($roleId); } catch (NotFoundException $e) { // The draft doesn't exist, let's create one $role = $this->roleService->loadRole($roleId); $roleDraft = $this->roleService->createRoleDraft($role); } $roleData = (new RoleMapper())->mapToFormData($roleDraft); $form = $this->createForm(new RoleUpdateType(), $roleData); $actionUrl = $this->generateUrl('admin_roleUpdate', ['roleId' => $roleId]); // Synchronize form and data. $form->handleRequest($request); $hasErrors = false; if ($form->isValid()) { $this->actionDispatcher->dispatchFormAction($form, $roleData, $form->getClickedButton()->getName()); if ($response = $this->actionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } elseif ($form->isSubmitted()) { $hasErrors = true; } $formView = $form->createView(); // Show empty text input when name is not set, while showing "New role" in the page title $roleName = $roleDraft->identifier; if ($roleData->isNew()) { $roleName = 'role.name_new'; $formView->vars['role_input_value'] = ''; } else { $formView->vars['role_input_value'] = $roleName; } return $this->render('eZPlatformUIBundle:Role:update_role.html.twig', ['form' => $formView, 'action_url' => $actionUrl, 'role_draft' => $roleDraft, 'role_name' => $roleName, 'hasErrors' => $hasErrors]); }
/** * Displays and processes a user registration form. * * @param Request $request * * @return \Symfony\Component\HttpFoundation\Response * * @throws \Exception if the current user isn't allowed to register an account */ public function registerAction(Request $request) { if (!$this->isGranted(new Attribute('user', 'register'))) { throw new UnauthorizedHttpException('You are not allowed to register a new account'); } $data = $this->userRegisterMapper->mapToFormData(); $language = $data->mainLanguageCode; $form = $this->createForm(UserRegisterType::class, $data, ['languageCode' => $language]); $form->handleRequest($request); if ($form->isValid()) { $this->contentActionDispatcher->dispatchFormAction($form, $data, $form->getClickedButton()->getName()); if ($response = $this->contentActionDispatcher->getResponse()) { return $response; } } return new UserRegisterFormView(null, ['form' => $form->createView()]); }
/** * Displays the edit form and processes it once submitted. * * @param \Symfony\Component\HttpFoundation\Request $request * @param mixed $languageId * * @return \Symfony\Component\HttpFoundation\Response */ public function editAction(Request $request, $languageId = null) { $language = $languageId ? $this->languageService->loadLanguageById($languageId) : new Language(['languageCode' => '__new__' . md5(microtime(true)), 'name' => 'New language']); $languageData = (new LanguageMapper())->mapToFormData($language); $actionUrl = $this->generateUrl('admin_languageedit', ['languageId' => $languageId]); $form = $this->createForm(new LanguageType(), $languageData); $form->handleRequest($request); if ($form->isValid()) { $this->actionDispatcher->dispatchFormAction($form, $languageData, $form->getClickedButton() ? $form->getClickedButton()->getName() : null); if ($response = $this->actionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } return $this->render('eZPlatformUIBundle:Language:edit.html.twig', ['form' => $form->createView(), 'actionUrl' => $actionUrl, 'language' => $languageData]); }
/** * Displays the edit form and processes it once submitted. * * @param \Symfony\Component\HttpFoundation\Request $request * @param mixed $sectionId * * @return \Symfony\Component\HttpFoundation\Response */ public function editAction(Request $request, $sectionId = null) { $section = $sectionId ? $this->sectionService->loadSection($sectionId) : new Section(['identifier' => '__new__' . md5(microtime(true)), 'name' => 'New section']); $sectionData = (new SectionMapper())->mapToFormData($section); $actionUrl = $this->generateUrl('admin_sectionedit', ['sectionId' => $sectionId]); $form = $this->createForm(new SectionType(), $sectionData); $form->handleRequest($request); if ($form->isValid()) { $this->actionDispatcher->dispatchFormAction($form, $sectionData, $form->getClickedButton() ? $form->getClickedButton()->getName() : null); if ($response = $this->actionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } return $this->render('eZPlatformUIBundle:Section:edit.html.twig', ['form' => $form->createView(), 'actionUrl' => $actionUrl, 'section' => $sectionData]); }