Skip to content

Commit

Permalink
Merge branch 'context'
Browse files Browse the repository at this point in the history
  • Loading branch information
gmanen committed Apr 14, 2014
2 parents 3a5d75d + d5e1ee3 commit 0b2e7e8
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 217 deletions.
13 changes: 13 additions & 0 deletions Annotation/Bigfoot/Context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Bigfoot\Bundle\CoreBundle\Annotation\Bigfoot;

use Doctrine\Common\Annotations\Annotation;

/**
* @Annotation
* @Target("CLASS")
*/
final class Context extends Annotation
{
}
7 changes: 0 additions & 7 deletions BigfootCoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,4 @@
*/
class BigfootCoreBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function boot()
{
$this->container->get('bigfoot_core.manager.route')->addBundle($this->getName());
}
}
4 changes: 2 additions & 2 deletions Command/Bigfoot/ThemeInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Symfony\Component\Finder\Finder;

use Bigfoot\Bundle\CoreBundle\Command\BaseCommand;
use Bigfoot\Bundle\CoreBundle\Utils\CommonUtils;
use Bigfoot\Bundle\CoreBundle\Util\CommonUtil;

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

CommonUtils::recurseCopy($images, $targetArg.'/images');
CommonUtil::recurseCopy($images, $targetArg.'/images');

if (is_dir($originDir = $themeBundle->getPath().'/Resources/assets')) {
$targetDir = $targetArg.'/admin';
Expand Down
45 changes: 39 additions & 6 deletions Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

namespace Bigfoot\Bundle\CoreBundle\Controller;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Bigfoot\Bundle\ContextBundle\Entity\ContextRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Translation\Translator;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;

use Bigfoot\Bundle\CoreBundle\Event\FormEvent;

/**
* Base Controller
Expand Down Expand Up @@ -106,6 +110,18 @@ protected function getThemeBundle()
return $this->container->getParameter('bigfoot.theme.bundle');
}

/**
* Create form
*/
public function createForm($type, $data = null, array $options = array())
{
$form = parent::createForm($type, $data, $options);

$this->getEventDispatcher()->dispatch(FormEvent::CREATE, new GenericEvent($form));

return $form;
}

/**
* Render ajax
*/
Expand Down Expand Up @@ -182,6 +198,22 @@ protected function getEventDispatcher()
return $this->get('event_dispatcher');
}

/**
* Get the bigfoot context
*/
protected function getContext()
{
return $this->get('bigfoot_context');
}

/**
* Get the bigfoot context manager
*/
protected function getContextManager()
{
return $this->get('bigfoot_context.manager.context');
}

/**
* Get the user manager
*/
Expand All @@ -191,11 +223,12 @@ protected function getUserManager()
}

/**
* Get the menu item manager
* Get the context repository
* @return ContextRepository
*/
protected function getMenuItemManager()
protected function getContextRepository()
{
return $this->get('bigfoot_navigation.manager.menu_item');
return $this->get('bigfoot_context.repository.context');
}

/**
Expand Down
27 changes: 23 additions & 4 deletions Controller/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr\Comparison;

use Bigfoot\Bundle\CoreBundle\Controller\AdminControllerInterface;
use Bigfoot\Bundle\CoreBundle\Controller\BaseController;
use Bigfoot\Bundle\CoreBundle\Event\FormEvent;
use Bigfoot\Bundle\UserBundle\Entity\User;

/**
Expand Down Expand Up @@ -87,6 +89,7 @@ protected function getBundleName()
$names = $this->getBundleAndEntityName();
$this->bundleName = $names['bundle'];
}

return $this->bundleName;
}

Expand Down Expand Up @@ -134,6 +137,7 @@ protected function getFormType()
protected function getEntityClass()
{
$namespace = $this->get('kernel')->getBundle($this->getBundleName())->getNamespace();

return sprintf('\\%s\\Entity\\%s', $namespace, $this->getEntityName());
}

Expand All @@ -143,6 +147,7 @@ protected function getEntityClass()
protected function getEntityTypeClass()
{
$namespace = $this->container->get('kernel')->getBundle($this->getBundleName())->getNamespace();

return sprintf('\\%s\\Form\\%sType', $namespace, $this->getEntityName());
}

Expand Down Expand Up @@ -261,14 +266,17 @@ protected function getGlobalActions()
*/
protected function doIndex()
{
$entityClass = ltrim($this->getEntityClass(), '\\');

$query = $this
->getRepository($this->getEntity())
->createQueryBuilder('e')
->getContextRepository()
->createContextQueryBuilder($entityClass)
->getQuery()
->setHint(
Query::HINT_CUSTOM_OUTPUT_WALKER,
'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
);
'Gedmo\Translatable\Query\TreeWalker\TranslationWalker'
)
->getResult();

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

$this->persistAndFlush($entity);

$this->postFlush($entity, 'new');

if (!$request->isXmlHttpRequest()) {
$action = $this->generateUrl($this->getRouteNameForAction('edit'), array('id' => $entity->getId()));

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

$this->persistAndFlush($entity);

$this->postFlush($entity, 'edit');

if (!$request->isXmlHttpRequest()) {
$this->addSuccessFlash('The %entity% has been updated.');

Expand Down Expand Up @@ -485,4 +497,11 @@ protected function handleSuccessResponse($action, $entity = null)
* @param object $entity entity
*/
protected function prePersist($entity, $action) {}

/**
* Post flush entity
*
* @param object $entity entity
*/
protected function postFlush($entity, $action) {}
}
11 changes: 11 additions & 0 deletions Event/FormEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bigfoot\Bundle\CoreBundle\Event;

/**
* Form Event
*/
final class FormEvent
{
const CREATE = 'bigfoot_core.event.form.create';
}
157 changes: 0 additions & 157 deletions Manager/RouteManager.php

This file was deleted.

Loading

0 comments on commit 0b2e7e8

Please sign in to comment.