src/Kunstmaan/ConfigBundle/Controller/ConfigController.php
public function indexAction(Request $request, $internalName)
    {
        /**
         * @var AbstractConfig
         */
        $entity = $this->getConfigEntityByInternalName($internalName);
        $entityClass = get_class($entity);

        // Check if current user has permission for the site config.
        foreach ($entity->getRoles() as $role) {
            $this->checkPermission($role);
        }

        $repo = $this->em->getRepository($entityClass);
        $config = $repo->findOneBy(array());

        if (!$config) {
            $config = new $entityClass();
        }

        $form = $this->formFactory->create(
            $entity->getDefaultAdminType(),
            $config
        );

        if ($request->isMethod('POST')) {
            $form->handleRequest($request);

            if ($form->isSubmitted() && $form->isValid()) {
                $this->em->persist($config);
                $this->em->flush();

                return new RedirectResponse($this->router->generate('kunstmaanconfigbundle_default', array('internalName' => $internalName)));
            }
        }

        return $this->templating->renderResponse(
            '@KunstmaanConfig/Settings/configSettings.html.twig',
            array(
                'form' => $form->createView(),
            )
        );
    }
public function indexAction(Request $request, $internalName)
    {
        /**
         * @var AbstractConfig
         */
        $entity = $this->getConfigEntityByInternalName($internalName);
        $entityClass = get_class($entity);

        // Check if current user has permission for the site config.
        foreach ($entity->getRoles() as $role) {
            $this->checkPermission($role);
        }

        $repo = $this->em->getRepository($entityClass);
        $config = $repo->findOneBy(array());

        if (!$config) {
            $config = new $entityClass();
        }

        $form = $this->formFactory->create(
            $entity->getDefaultAdminType(),
            $config
        );

        if ($request->isMethod('POST')) {
            $form->handleRequest($request);

            if ($form->isSubmitted() && $form->isValid()) {
                $this->em->persist($config);
                $this->em->flush();

                return new RedirectResponse($this->router->generate('kunstmaanconfigbundle_default', array('internalName' => $internalName)));
            }
        }

        return $this->templating->renderResponse(
            '@KunstmaanConfig/Settings/configSettings.html.twig',
            array(
                'form' => $form->createView(),
            )
        );
    }
public function indexAction ( Request $ request , $ internalName ) { /**
         * @var AbstractConfig
         */ $ entity = $ this -> getConfigEntityByInternalName ( $ internalName ) ; $ entityClass = get_class ( $ entity ) ; // Check if current user has permission for the site config. foreach ( $ entity -> getRoles ( ) as $ role ) { $ this -> checkPermission ( $ role ) ; } $ repo = $ this -> em -> getRepository ( $ entityClass ) ; $ config = $ repo -> findOneBy ( array ( ) ) ; if ( ! $ config ) { $ config = new $ entityClass ( ) ; } $ form = $ this -> formFactory -> create ( $ entity -> getDefaultAdminType ( ) , $ config ) ; if ( $ request -> isMethod ( 'POST' ) ) { $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ this -> em -> persist ( $ config ) ; $ this -> em -> flush ( ) ; return new RedirectResponse ( $ this -> router -> generate ( 'kunstmaanconfigbundle_default' , array ( 'internalName' => $ internalName ) ) ) ; } } return $ this -> templating -> renderResponse ( '@KunstmaanConfig/Settings/configSettings.html.twig' , array ( 'form' => $ form -> createView ( ) , ) ) ; }
Generates the site config administration form and fills it with a default value if needed.

@param Request $request
@param string  $internalName

@return array|RedirectResponse
Generates the site config administration form and fills it with a default value if needed .