adds required fields to formbuilder
@param FormBuilderInterface $fb
@param Page $page
@return FormBuilderInterface
354912
public function addForm(FormBuilderInterface $fb, Page $page)
    {
        $data = $page->getData() == "" ? 0 : $page->getData();
        $fb->add('mode', ChoiceType::class,[
            "label" => "sitemap.behavior",
            "translation_domain" => "forms",
            "choices" => [
                "sitemap.absolute" => 0,
                "sitemap.relative" => 1,
                "sitemap.subpages" => 2,
            ],
            "data" => $data["mode"],
            "mapped" => false
        ])
            ->add("limit", NumberType::class, [
                "label" => "sitemap.limit",
                "translation_domain" => "forms",
                "mapped" => false,
                "data" => $data["limit"],
                "required" => false
            ]);
        return $fb;
    }
431201
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('query', CoreSearchType::class, ['required' => false])
            ->add('page', HiddenType::class)
            ->add('limit', HiddenType::class)
            ->add('content_types', ContentTypeChoiceType::class, [
                'multiple' => true,
                'expanded' => true,
            ])
            ->add('last_modified', DateIntervalType::class)
            ->add('created', DateIntervalType::class)
            ->add('creator', UserType::class)
            ->add('last_modified_select', ChoiceType::class, [
                'choices' => $this->getTimePeriodChoices(),
                'required' => false,
                'placeholder' => /** @Desc("Any time") */ 'search.any_time',
                'mapped' => false,
            ])
            ->add('created_select', ChoiceType::class, [
                'choices' => $this->getTimePeriodChoices(),
                'required' => false,
                'placeholder' => /** @Desc("Any time") */ 'search.any_time',
                'mapped' => false,
            ])
            ->add('subtree', HiddenType::class, [
                'required' => false,
            ])
        ;

        if ($this->permissionResolver->hasAccess('section', 'view')) {
            $builder->add('section', SectionChoiceType::class, [
                'required' => false,
                'multiple' => false,
                'placeholder' => /** @Desc("Any section") */ 'search.section.any',
            ]);
        }
    }
1242382
public function populateFormBuilder(FormBuilderInterface $fb, $model, $form = 'default', $context = [])
    {
        $configuration = $this->formConfigurationFactory->getConfiguration($form, $model, $context);
        foreach ($this->adjusterRegistry->getFormConfigurationModifiers() as $modifier) {
            if ($modifier->supports($model, $configuration, $context)) {
                $configuration = $modifier->modify($model, $configuration, $context);
            }
        }
        foreach ($configuration as $field => $options) {
            $type = null;
            if (isset($options['type'])) {
                $type = $options['type'];
                unset($options['type']);
            }
            foreach ($this->adjusterRegistry->getFormFieldResolvers() as $resolver) {
                if ($resolver->supports($model, $field, $type, $options, $context)) {
                    $fb->add($resolver->getFormField($fb, $field, $type, $options, $context));
                    continue 2;
                }
            }
            if (isset($options['options'])) {
                $options = $options['options'];
            }
            $fb->add($field, $type, $options);
        }
    }
193985
protected function addBankAccount(FormBuilderInterface $builder)
    {
        $builder->add(
            static::FIELD_BANK_ACCOUNT,
            TextType::class,
            [
                'label' => false,
                'required' => true,
                'constraints' => [
                ],
            ]
        );

        return $this;
    }
855823
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $fields = AppSettings::settings();
        foreach ($fields as $key => $value) {
            $builder->add($key, TextType::class, [
                'value' => $value,
                'required' => true,
                'constraints' => [ new Symfony\Component\Validator\Constraints\NotBlank()]
            ]);
        }
    }
620604
public function editAction(Page $page, Request $request)
    {
        $form = $this->container->get('form.factory')->createNamed(
            'page',
            EditionType::class,
            $page,
            array(
                'action' => $this->container->get('router')->generate(
                    'synapse_admin_page_edition',
                    array('id' => $page->getId())
                ),
                'synapse_theme' => $request->get('synapse_theme'),
                'method' => 'POST',
                'csrf_protection' => false,
            )
        );

        if ($request->request->has('page')) {
            $form->handleRequest($request);
            if ($form->isValid()) {
                $form->getData()->resolve();

                return $this->redirect(// refresh to rebuild dynamic form
                    $this->container->get('router')->generate(
                        $request->attributes->get('_route'),
                        $request->attributes->get('_route_params')
                    )
                );
            }
        }

        return $this->render('SynapsePageBundle:Admin/Page:edit.html.twig', array(
            'form' => $form->createView(),
            'page' => $page,
        ));
    }
1151856
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
            $view = $event->getData();
            $form = $event->getForm();

            $this->isNew = !$view || null === $view->getId();

            if ($this->isNew) {
                $getAllTemplateWithoutMe = function (EntityRepository $tr) {
                    return $tr->getAll()->getInstance();
                };
            } else {
                $getAllTemplateWithoutMe = function (EntityRepository $tr) use ($view) {
                    return $tr->getAll()
                        ->getInstance()
                        ->andWhere('template.id != :templateId')
                        ->setParameter('templateId', $view->getId());
                };
            }
            if (!$form->has('template')) {
                $form->add('template', null, [
                    'label'        => 'form.view.type.template.label',
                    'choice_label' => function ($view) {
                        return $view->getName();
                    },
                    'required'      => !$view instanceof Template || $view instanceof BusinessTemplate,
                    'query_builder' => $getAllTemplateWithoutMe,
                ]);
            }

            //If view is an Article BEP, we do not allow to choose parent because it will be set automatically
            if (!$view instanceof ArticleTemplate && ClassUtils::getClass($view) != 'Victoire\Bundle\TemplateBundle\Entity\Template') {
                if (!$view || null === $view->getId()) {
                    $getAllPageWithoutMe = function (EntityRepository $repo) {
                        return $repo->getAll()->getInstance();
                    };
                } else {
                    $getAllPageWithoutMe = function (EntityRepository $repo) use ($view) {
                        return $repo->getAll()
                            ->getInstance()
                            ->andWhere('view.id != :pageId')
                            ->setParameter('pageId', $view->getId());
                    };
                }

                $form->add('parent', null, [
                        'class'         => 'Victoire\Bundle\PageBundle\Entity\BasePage',
                        'label'         => 'form.view.type.parent.label',
                        'query_builder' => $getAllPageWithoutMe,
                        'required'      => true,
                    ]
                );
            }

            if ($view instanceof BasePage) {
                $translationOptions = [
                    'fields' => [
                        'name' => [
                            'label' => 'form.view.type.name.label',
                        ],
                    ],
                ];
                if ($view->getId() && !$view->isHomepage()) {
                    $translationOptions['fields']['slug'] = [
                        'label'      => 'form.page.type.slug.label',
                        'field_type' => UrlvalidatedType::class,
                    ];
                }
                $form->add('translations', TranslationsType::class, $translationOptions);
            }
        });

        if ($this->authorizationChecker->isGranted('ROLE_VICTOIRE_DEVELOPER')) {
            $builder->add('roles', TextType::class, [
                'label'          => 'form.page.type.roles.label',
                'vic_help_block' => 'form.page.type.roles.help_block',
            ]);
        }
    }
1260296
public function attachInputToFormBuilder(FormBuilder $formBuilder, $data = null)
    {
        //Convert the options to an array for the form builder
        $choices = array();
        $selected = null;
        if ($this->isAjax && $data !== null) {
            if (is_array($data)) {
                foreach($data as $d) {
                    $choices[$d] = ' ';
                }
            } else {
                $choices[$data] = ' ';
            }
        } else {
            foreach($this->optionList as $option) {
                $choices[$option->getId()] = $option->getLabel();
                if ($option->getSelected()) {
                    $selected = $option->getId();
                }
            }
        }

        //Add a new multi choice field to the builder
        $formBuilder->add(
            $this->id,
            $this->isAjax ? new AjaxSelectType() : 'choice',
            array(
                'label'     => $this->label,
                'choices'   => $choices,
                'multiple'  => false,
                'data'      => $selected,
                'required'  => $this->mandatory,
                'read_only' => $this->readOnly,
                'data_class'=> null,
                'constraints' => $this->mandatory ? [new NotBlank()] : []
            )
        );
    }
1068974
public function createFormBuilder($model, $form = 'default', $context = [], $options=[])
    {
        $fb = $this->formFactory->createBuilder(FormType::class, $model, $options);

        $this->populateFormBuilder($fb, $model, $form, $context);
        return $fb;
    }
643930
protected function addBIC(FormBuilderInterface $builder)
    {
        $builder->add(
            self::FIELD_BIC,
            TextType::class,
            [
                'label' => false,
                'required' => true,
                'constraints' => [
                    $this->createManageMandateConstraint(),
                ],
            ]
        );

        return $this;
    }
550428
final protected function initPageMetas(Page $page)
    {
        if (!isset($this->pageMetas))
        {
            $this->pageMetas = array();
            if ($page->getId() > 0)
            {
                $metas = $this->doctrine->getRepository('FulgurioLightCMSBundle:PageMeta')->findByPage($page->getId());
                foreach ($metas as $meta)
                {
                    $this->pageMetas[$meta->getMetaKey()] = $meta;
                }
            }
        }
    }
114799
protected function process(FormRequest $request, Page $page)
    {
        // Prepare required input fields
        $data = $request->validated();

        // Verify existing view
        if (! view()->exists($data['view'])) {
            return intend([
                'back' => true,
                'withInput' => $request->all(),
                'withErrors' => ['view' => trans('cortex/pages::messages.page.invalid_view')],
            ]);
        }

        // Save page
        $page->fill($data)->save();

        return intend([
            'url' => route('managerarea.pages.index'),
            'with' => ['success' => trans('cortex/foundation::messages.resource_saved', ['resource' => trans('cortex/pages::common.page'), 'identifier' => $page->name])],
        ]);
    }
257412
public function adaptForm(FormBuilderInterface $formBuilder, ArrayObject $fields, $sequence)
    {
        $ffsf = new FileFormSubmissionField();
        $ffsf->setFieldName('field_' . $this->getUniqueId());
        $ffsf->setLabel($this->getLabel());
        $ffsf->setSequence($sequence);

        $data = $formBuilder->getData();
        $data['formwidget_' . $this->getUniqueId()] = $ffsf;

        $constraints = array();
        if ($this->getRequired()) {
            $options = array();
            if (!empty($this->errorMessageRequired)) {
                $options['message'] = $this->errorMessageRequired;
            }
            $constraints[] = new NotBlank($options);
        }

        $formBuilder->add(
            'formwidget_' . $this->getUniqueId(),
            FileFormSubmissionType::class,
            array(
                'label' => $this->getLabel(),
                'constraints' => $constraints,
                'required' => $this->getRequired(),
            )
        );
        $formBuilder->setData($data);

        $fields->append($ffsf);
    }
614508
public function defineFormBuilder(FormBuilderInterface $formBuilder)
    {
        $mapper = new FormMapper($this->getFormContractor(), $formBuilder, $this);

        $this->configureFormFields($mapper);

        foreach ($this->getExtensions() as $extension) {
            $extension->configureFormFields($mapper);
        }

        $this->attachInlineValidator();
    }
683774
public function process(Page $page)
    {
        if ($this->request->getMethod() === 'POST')
        {
            if ($this->request->get('realSubmit') !== '1')
            {
                return FALSE;
            }
            $this->form->handleRequest($this->request);
            if ($this->form->isValid())
            {
                $data = $this->request->get('page');
                $this->updatePageMetas($page, $data);
                $this->updatePageMenuPosition($page);
                $em = $this->doctrine->getManager();
                // New page
                if ($page->getId() == 0)
                {
                    if (is_a($this->user, 'Symfony\Component\Security\Core\User\UserInterface')
                            && method_exists($this->user, 'getId'))
                    {
                        $page->setOwnerId($this->user->getId());
                    }
                    $page->setPosition($page->getParent() ? $this->doctrine->getRepository('FulgurioLightCMSBundle:Page')->getNextPosition($page->getParent()->getId()) : 1);
                }
                // Well, slug has been already made, but it s not easy to get the value, so we did it again
                $page->setSlug(LightCMSUtils::makeSlug(isset($data['lang']) ? $data['lang'] : $page->getTitle()));
                if (isset($data['lang']))
                {
                    $page->setLang($data['lang']);
                }
                else if ($page->getParent())
                {
                    $page->setLang($page->getParent()->getLang());
                }
                $this->makeFullpath($page);
                $this->beforePersist($page);
                $em->persist($page);
                $em->flush();
                return TRUE;
            }
        }
        return FALSE;
    }
199702
protected function settingsPostAction(Request $request, BasePage $page)
    {
        $entityManager = $this->getDoctrine()->getManager();
        $form = $this->createSettingsForm($page);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $entityManager->persist($page);
            $entityManager->flush();

            $this->congrat($this->get('translator')->trans('victoire_page.update.success', [], 'victoire'));

            return $this->getViewReferenceRedirect($request, $page);
        }

        return [
            'success' => false,
            'message' => $this->get('victoire_form.error_helper')->getRecursiveReadableErrors($form),
            'html'    => $this->get('templating')->render(
                $this->getBaseTemplatePath().':settings.html.twig',
                [
                    'page'               => $page,
                    'form'               => $form->createView(),
                    'businessProperties' => $this->getBusinessProperties($page),
                ]
            ),
        ];
    }
1300480
public function addPage(PageInterface $page, $route = null)
    {
        if (!isset($this->instances[$page->path()])) {
            $this->instances[$page->path()] = $page;
        }
        $route = $page->route($route);
        if ($page->parent()) {
            $this->children[$page->parent()->path()][$page->path()] = ['slug' => $page->slug()];
        }
        $this->routes[$route] = $page->path();

        $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page]));
    }