Example #1
0
 /**
  * @Route("/cms/get-attribute-form", name="cms.addAttributeForm")
  * @param Request $request
  * @return Response
  */
 public function addAttributeAction(Request $request)
 {
     $type = $request->get('type');
     if (in_array($type, array_keys(AttributeService::getAvailableTypes()))) {
         return $this->render(sprintf('YCMSBundle:_attributes:%s.html.twig', $type));
     } else {
         throw new NotFoundHttpException();
     }
 }
Example #2
0
 protected function processAction($module, Request $request)
 {
     $this->get('adminContext')->setActiveModuleName($module);
     $moduleConfig = $this->get('adminContext')->getActiveModuleForAction('add');
     /** @var AttributedInterface $object */
     $object = $this->getOrCreateObjectFromRequest($request);
     if (!$this->get('admin.security')->isGranted($object, $moduleConfig, 'add')) {
         throw new AccessDeniedException();
     }
     $form = $this->buildForm($object, $moduleConfig);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->get('cms.attribute')->saveAttributesStructure($object, $request);
         $this->saveValidObject($object);
         $this->addFlash('success', 'Your changes was has been saved');
         return $this->redirectToRoute($moduleConfig['actions']['edit']['route'], ['module' => $moduleConfig['name'], 'id' => $object->getId()]);
     }
     return $this->render('@YCMS/form/view.html.twig', ['object' => $object, 'form' => $form->createView(), 'moduleConfig' => $moduleConfig, 'attributes' => $object->getAttributes(), 'attributeTypes' => AttributeService::getAvailableTypes()]);
 }
Example #3
0
 /**
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('name')->add('type', 'choice', ['choices' => AttributeService::getAvailableTypes()])->add('system', 'checkbox', ['required' => false])->add('default_value', 'text', ['required' => false]);
 }