Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 05bfdde

Browse files
author
maxence d'Espeuilles
committed
first commit
0 parents  commit 05bfdde

File tree

14 files changed

+652
-0
lines changed

14 files changed

+652
-0
lines changed

Controller/MetaController.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace Mdespeuilles\MetaBundle\Controller;
4+
5+
use Mdespeuilles\MetaBundle\Entity\Meta;
6+
use Mdespeuilles\MetaBundle\Form\MetaType;
7+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8+
use Symfony\Component\HttpFoundation\Request;
9+
10+
class MetaController extends Controller
11+
{
12+
public function metaAction(Request $request)
13+
{
14+
$url = $request->getUri();
15+
$url_array = parse_url($url);
16+
$path = str_replace("/app_dev.php", "", $url_array["path"]);
17+
$language = $request->getLocale();
18+
19+
/* @var \Mdespeuilles\MetaBundle\Entity\Meta $meta */
20+
$meta = $this->get('mdespeuilles.entity.meta')->findOneBy([
21+
'url' => $path,
22+
'language' => $request->getLocale()
23+
]);
24+
25+
$form = null;
26+
27+
if ($meta) {
28+
$form = $this->createForm(MetaType::class, $meta, [
29+
'action' => $this->generateUrl("meta_form_edit", [
30+
"metaId" => $meta->getId()
31+
])
32+
]);
33+
}
34+
else {
35+
$meta = new Meta();
36+
$meta->setUrl($path);
37+
$meta->setLanguage($language);
38+
$form = $this->createForm(MetaType::class, $meta, [
39+
'action' => $this->generateUrl("meta_form_add")
40+
]);
41+
}
42+
43+
return $this->render('MdespeuillesMetaBundle:Meta:meta_form.html.twig', array(
44+
'form' => $form->createView()
45+
));
46+
}
47+
48+
public function addMetaAction(Request $request) {
49+
$meta = new Meta();
50+
$form = $this->createForm(MetaType::class, $meta);
51+
52+
$form->handleRequest($request);
53+
if ($form->isValid()) {
54+
$em = $this->getDoctrine()->getManager();
55+
$em->persist($meta);
56+
$em->flush();
57+
}
58+
59+
$prefix = ($this->get('kernel')->getEnvironment() == "dev") ? "/app_dev.php" : null;
60+
61+
return $this->redirect($prefix.$meta->getUrl());
62+
}
63+
64+
public function editMetaAction(Request $request, $metaId) {
65+
66+
/* @var \Mdespeuilles\MetaBundle\Entity\Meta $meta */
67+
$meta = $this->get('mdespeuilles.entity.meta')->find($metaId);
68+
69+
$form = $this->createForm(MetaType::class, $meta);
70+
71+
$form->handleRequest($request);
72+
if ($form->isValid()) {
73+
$em = $this->getDoctrine()->getManager();
74+
$em->persist($meta);
75+
$em->flush();
76+
}
77+
78+
$prefix = ($this->get('kernel')->getEnvironment() == "dev") ? "/app_dev.php" : null;
79+
80+
return $this->redirect($prefix.$meta->getUrl());
81+
}
82+
83+
}

DependencyInjection/Configuration.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Mdespeuilles\MetaBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
/**
9+
* This is the class that validates and merges configuration from your app/config files.
10+
*
11+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
12+
*/
13+
class Configuration implements ConfigurationInterface
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function getConfigTreeBuilder()
19+
{
20+
$treeBuilder = new TreeBuilder();
21+
$rootNode = $treeBuilder->root('open_access_meta');
22+
23+
// Here you should define the parameters that are allowed to
24+
// configure your bundle. See the documentation linked above for
25+
// more information on that topic.
26+
27+
return $treeBuilder;
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Mdespeuilles\MetaBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8+
use Symfony\Component\DependencyInjection\Loader;
9+
10+
/**
11+
* This is the class that loads and manages your bundle configuration.
12+
*
13+
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
14+
*/
15+
class MdespeuillesMetaExtension extends Extension
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function load(array $configs, ContainerBuilder $container)
21+
{
22+
$configuration = new Configuration();
23+
$config = $this->processConfiguration($configuration, $configs);
24+
25+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26+
$loader->load('services.yml');
27+
}
28+
}

0 commit comments

Comments
 (0)