示例#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();
     }
 }
示例#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()]);
 }
示例#3
0
 public function setAttributes($attributes)
 {
     $newAttributes = new ArrayCollection();
     foreach ($attributes as $key => $info) {
         if (is_array($info) && array_key_exists('type', $info)) {
             $newAttribute = AttributeService::getAttributeForType($info['type'], $info);
         } elseif (is_object($info) && $info instanceof BaseAttribute) {
             $newAttribute = AttributeService::getAttributeForType($info->getType(), $info);
             if ($newAttribute) {
                 $newAttribute->setValue($info->getValue());
             }
         }
         if (!empty($newAttribute)) {
             $existedAttribute = $this->findAttributeWithName(is_object($info) ? $info->getName() : $info['name']);
             if (!empty($existedAttribute)) {
                 $newAttribute->setValue($existedAttribute->getValue());
             }
             $newAttributes[$key] = clone $newAttribute;
         }
     }
     $this->attributes = $newAttributes;
     return $this;
 }
示例#4
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]);
 }