mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-21 18:11:10 +00:00
Implement simple config
This commit is contained in:
parent
7a577c519f
commit
4d85d7e9ba
10 changed files with 347 additions and 156 deletions
58
src/Wallabag/CoreBundle/Controller/ConfigController.php
Normal file
58
src/Wallabag/CoreBundle/Controller/ConfigController.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Wallabag\CoreBundle\Entity\Config;
|
||||
use Wallabag\CoreBundle\Form\Type\ConfigType;
|
||||
|
||||
class ConfigController extends Controller
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @Route("/config", name="config")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function indexAction(Request $request)
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
|
||||
$form = $this->createForm(new ConfigType(), $config);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($config);
|
||||
$em->flush();
|
||||
|
||||
$this->get('session')->getFlashBag()->add(
|
||||
'notice',
|
||||
'Config saved'
|
||||
);
|
||||
|
||||
return $this->redirect($this->generateUrl('config'));
|
||||
}
|
||||
|
||||
return $this->render('WallabagCoreBundle:Config:index.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
private function getConfig()
|
||||
{
|
||||
$config = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Config')
|
||||
->findOneByUser($this->getUser());
|
||||
|
||||
if (!$config) {
|
||||
$config = new Config($this->getUser());
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue