Skip to content

Commit 0b2e7e8

Browse files
committed
Merge branch 'context'
2 parents 3a5d75d + d5e1ee3 commit 0b2e7e8

File tree

16 files changed

+158
-217
lines changed

16 files changed

+158
-217
lines changed

Annotation/Bigfoot/Context.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Bigfoot\Bundle\CoreBundle\Annotation\Bigfoot;
4+
5+
use Doctrine\Common\Annotations\Annotation;
6+
7+
/**
8+
* @Annotation
9+
* @Target("CLASS")
10+
*/
11+
final class Context extends Annotation
12+
{
13+
}

BigfootCoreBundle.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,4 @@
1212
*/
1313
class BigfootCoreBundle extends Bundle
1414
{
15-
/**
16-
* {@inheritdoc}
17-
*/
18-
public function boot()
19-
{
20-
$this->container->get('bigfoot_core.manager.route')->addBundle($this->getName());
21-
}
2215
}

Command/Bigfoot/ThemeInstallCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Symfony\Component\Finder\Finder;
1111

1212
use Bigfoot\Bundle\CoreBundle\Command\BaseCommand;
13-
use Bigfoot\Bundle\CoreBundle\Utils\CommonUtils;
13+
use Bigfoot\Bundle\CoreBundle\Util\CommonUtil;
1414

1515
/**
1616
* Command that places the active bigfoot theme web assets into a given directory.
@@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7575
$contentBundle = $this->getContainer()->get('kernel')->getBundle('BigfootContentBundle');
7676
$images = $contentBundle->getPath().'/Resources/public/images';
7777

78-
CommonUtils::recurseCopy($images, $targetArg.'/images');
78+
CommonUtil::recurseCopy($images, $targetArg.'/images');
7979

8080
if (is_dir($originDir = $themeBundle->getPath().'/Resources/assets')) {
8181
$targetDir = $targetArg.'/admin';

Controller/BaseController.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
namespace Bigfoot\Bundle\CoreBundle\Controller;
44

5-
use Doctrine\ORM\EntityManager;
6-
use Doctrine\ORM\EntityRepository;
7-
use Symfony\Component\EventDispatcher\EventDispatcher;
5+
use Bigfoot\Bundle\ContextBundle\Entity\ContextRepository;
86
use Symfony\Component\HttpFoundation\JsonResponse;
97
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
108
use Symfony\Component\Security\Core\SecurityContext;
9+
use Symfony\Component\EventDispatcher\EventDispatcher;
10+
use Symfony\Component\EventDispatcher\GenericEvent;
1111
use Symfony\Component\Translation\Translator;
12+
use Doctrine\ORM\EntityManager;
13+
use Doctrine\ORM\EntityRepository;
14+
15+
use Bigfoot\Bundle\CoreBundle\Event\FormEvent;
1216

1317
/**
1418
* Base Controller
@@ -106,6 +110,18 @@ protected function getThemeBundle()
106110
return $this->container->getParameter('bigfoot.theme.bundle');
107111
}
108112

113+
/**
114+
* Create form
115+
*/
116+
public function createForm($type, $data = null, array $options = array())
117+
{
118+
$form = parent::createForm($type, $data, $options);
119+
120+
$this->getEventDispatcher()->dispatch(FormEvent::CREATE, new GenericEvent($form));
121+
122+
return $form;
123+
}
124+
109125
/**
110126
* Render ajax
111127
*/
@@ -182,6 +198,22 @@ protected function getEventDispatcher()
182198
return $this->get('event_dispatcher');
183199
}
184200

201+
/**
202+
* Get the bigfoot context
203+
*/
204+
protected function getContext()
205+
{
206+
return $this->get('bigfoot_context');
207+
}
208+
209+
/**
210+
* Get the bigfoot context manager
211+
*/
212+
protected function getContextManager()
213+
{
214+
return $this->get('bigfoot_context.manager.context');
215+
}
216+
185217
/**
186218
* Get the user manager
187219
*/
@@ -191,11 +223,12 @@ protected function getUserManager()
191223
}
192224

193225
/**
194-
* Get the menu item manager
226+
* Get the context repository
227+
* @return ContextRepository
195228
*/
196-
protected function getMenuItemManager()
229+
protected function getContextRepository()
197230
{
198-
return $this->get('bigfoot_navigation.manager.menu_item');
231+
return $this->get('bigfoot_context.repository.context');
199232
}
200233

201234
/**

Controller/CrudController.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
99
use Symfony\Component\PropertyAccess\PropertyAccess;
1010
use Doctrine\ORM\Query;
11+
use Doctrine\ORM\Query\Expr\Comparison;
1112

1213
use Bigfoot\Bundle\CoreBundle\Controller\AdminControllerInterface;
1314
use Bigfoot\Bundle\CoreBundle\Controller\BaseController;
15+
use Bigfoot\Bundle\CoreBundle\Event\FormEvent;
1416
use Bigfoot\Bundle\UserBundle\Entity\User;
1517

1618
/**
@@ -87,6 +89,7 @@ protected function getBundleName()
8789
$names = $this->getBundleAndEntityName();
8890
$this->bundleName = $names['bundle'];
8991
}
92+
9093
return $this->bundleName;
9194
}
9295

@@ -134,6 +137,7 @@ protected function getFormType()
134137
protected function getEntityClass()
135138
{
136139
$namespace = $this->get('kernel')->getBundle($this->getBundleName())->getNamespace();
140+
137141
return sprintf('\\%s\\Entity\\%s', $namespace, $this->getEntityName());
138142
}
139143

@@ -143,6 +147,7 @@ protected function getEntityClass()
143147
protected function getEntityTypeClass()
144148
{
145149
$namespace = $this->container->get('kernel')->getBundle($this->getBundleName())->getNamespace();
150+
146151
return sprintf('\\%s\\Form\\%sType', $namespace, $this->getEntityName());
147152
}
148153

@@ -261,14 +266,17 @@ protected function getGlobalActions()
261266
*/
262267
protected function doIndex()
263268
{
269+
$entityClass = ltrim($this->getEntityClass(), '\\');
270+
264271
$query = $this
265-
->getRepository($this->getEntity())
266-
->createQueryBuilder('e')
272+
->getContextRepository()
273+
->createContextQueryBuilder($entityClass)
267274
->getQuery()
268275
->setHint(
269276
Query::HINT_CUSTOM_OUTPUT_WALKER,
270-
'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
271-
);
277+
'Gedmo\Translatable\Query\TreeWalker\TranslationWalker'
278+
)
279+
->getResult();
272280

273281
return $this->renderIndex($query);
274282
}
@@ -295,6 +303,8 @@ protected function doNew(Request $request)
295303

296304
$this->persistAndFlush($entity);
297305

306+
$this->postFlush($entity, 'new');
307+
298308
if (!$request->isXmlHttpRequest()) {
299309
$action = $this->generateUrl($this->getRouteNameForAction('edit'), array('id' => $entity->getId()));
300310

@@ -342,6 +352,8 @@ protected function doEdit(Request $request, $id)
342352

343353
$this->persistAndFlush($entity);
344354

355+
$this->postFlush($entity, 'edit');
356+
345357
if (!$request->isXmlHttpRequest()) {
346358
$this->addSuccessFlash('The %entity% has been updated.');
347359

@@ -485,4 +497,11 @@ protected function handleSuccessResponse($action, $entity = null)
485497
* @param object $entity entity
486498
*/
487499
protected function prePersist($entity, $action) {}
500+
501+
/**
502+
* Post flush entity
503+
*
504+
* @param object $entity entity
505+
*/
506+
protected function postFlush($entity, $action) {}
488507
}

Event/FormEvent.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Bigfoot\Bundle\CoreBundle\Event;
4+
5+
/**
6+
* Form Event
7+
*/
8+
final class FormEvent
9+
{
10+
const CREATE = 'bigfoot_core.event.form.create';
11+
}

Manager/RouteManager.php

Lines changed: 0 additions & 157 deletions
This file was deleted.

0 commit comments

Comments
 (0)