Skip to content

Commit

Permalink
Refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
Acrack authored and gmanen committed Feb 12, 2014
1 parent 5ef6d31 commit ed06de6
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 140 deletions.
2 changes: 1 addition & 1 deletion Controller/CoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ function homeAction()
{
$board = $this->container->get('bigfoot.dashboard')->getBoard();

return $this->render(sprintf('%s::base.html.twig', $this->container->getParameter('bigfoot.theme.bundle')), array('dashboard' => $board));
return $this->render(sprintf('%s::layout.html.twig', $this->container->getParameter('bigfoot.theme.bundle')), array('dashboard' => $board));
}
}
193 changes: 108 additions & 85 deletions Controller/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Bigfoot\Bundle\CoreBundle\Controller\AdminControllerInterface;
use Bigfoot\Bundle\CoreBundle\Controller\BaseController;
use Bigfoot\Bundle\CoreBundle\Theme\Menu\Item;
use Bigfoot\Bundle\UserBundle\Entity\BigfootUser;

/**
Expand Down Expand Up @@ -154,6 +153,16 @@ protected function getBundleAndEntityName()
return array('bundle' => $bundleName, 'entity' => $entityName);
}

public function getIndexTemplate()
{
return $this->container->getParameter('bigfoot.theme.bundle').':Crud:index.html.twig';
}

public function getFormTemplate()
{
return $this->container->getParameter('bigfoot.theme.bundle').':Crud:form.html.twig';
}

/**
* Will be used as a label for the "add new" menu item.
*
Expand Down Expand Up @@ -239,18 +248,21 @@ protected function doIndex()
'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
);

return array(
'list_items' => $this->getPagination($query, 10),
'list_title' => $this->getEntityLabelPlural(),
'list_fields' => $this->getFields(),
'actions' => $this->getActions(),
'globalActions' => $this->getGlobalActions(),
'breadcrumbs' => array(
array(
'label' => $this->getEntityLabelPlural(),
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
)
),
return $this->render(
$this->getIndexTemplate(),
array(
'list_items' => $this->getPagination($query, 10),
'list_title' => $this->getEntityLabelPlural(),
'list_fields' => $this->getFields(),
'actions' => $this->getActions(),
'globalActions' => $this->getGlobalActions(),
'breadcrumbs' => array(
array(
'label' => $this->getEntityLabelPlural(),
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
)
),
)
);
}

Expand Down Expand Up @@ -358,15 +370,16 @@ protected function doCreate(Request $request)

if ($request->isXmlHttpRequest()) {
$content = $this->renderView(
'BigfootNavigationBundle:Item:edit.html.twig',
$this->getFormTemplate(),
array(
'form' => $form->createView(),
'form_method' => $request->getMethod(),
'form_method' => 'POST',
'form_title' => sprintf('%s creation', $this->getEntityLabel()),
'form_action' => $this->generateUrl($this->getRouteNameForAction('create')),
'form_submit' => 'Create',
'cancel_route' => $this->getRouteNameForAction('index'),
'isAjax' => $request->isXmlHttpRequest(),
'modal' => true,
'breadcrumbs' => array(
array(
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
Expand All @@ -390,24 +403,27 @@ protected function doCreate(Request $request)
);
}

return array(
'form' => $form->createView(),
'form_method' => $request->getMethod(),
'form_title' => sprintf('%s creation', $this->getEntityLabel()),
'form_action' => $this->generateUrl($this->getRouteNameForAction('create')),
'form_submit' => 'Create',
'cancel_route' => $this->getRouteNameForAction('index'),
'isAjax' => $request->isXmlHttpRequest(),
'breadcrumbs' => array(
array(
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
'label' => $this->getEntityLabelPlural()
),
array(
'url' => $this->generateUrl($this->getRouteNameForAction('new')),
'label' => sprintf('%s creation', $this->getEntityLabel())
return $this->render(
$this->getFormTemplate(),
array(
'form' => $form->createView(),
'form_method' => 'POST',
'form_title' => sprintf('%s creation', $this->getEntityLabel()),
'form_action' => $this->generateUrl($this->getRouteNameForAction('create')),
'form_submit' => 'Create',
'cancel_route' => $this->getRouteNameForAction('index'),
'isAjax' => $request->isXmlHttpRequest(),
'breadcrumbs' => array(
array(
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
'label' => $this->getEntityLabelPlural()
),
array(
'url' => $this->generateUrl($this->getRouteNameForAction('new')),
'label' => sprintf('%s creation', $this->getEntityLabel())
),
),
),
)
);
}

Expand All @@ -423,24 +439,27 @@ protected function doNew()
$entity = new $entityClass();
$form = $this->createForm($this->getFormType(), $entity);

return array(
'form' => $form->createView(),
'form_method' => $this->getRequest()->getMethod(),
'form_title' => sprintf('%s creation', $this->getEntityLabel()),
'form_action' => $this->generateUrl($this->getRouteNameForAction('create')),
'form_submit' => 'Create',
'cancel_route' => $this->getRouteNameForAction('index'),
'isAjax' => $this->getRequest()->isXmlHttpRequest(),
'breadcrumbs' => array(
array(
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
'label' => $this->getEntityLabelPlural()
),
array(
'url' => $this->generateUrl($this->getRouteNameForAction('new')),
'label' => sprintf('%s creation', $this->getEntityLabel())
return $this->render(
$this->getFormTemplate(),
array(
'form' => $form->createView(),
'form_method' => 'POST',
'form_title' => sprintf('%s creation', $this->getEntityLabel()),
'form_action' => $this->generateUrl($this->getRouteNameForAction('create')),
'form_submit' => 'Create',
'cancel_route' => $this->getRouteNameForAction('index'),
'isAjax' => $this->getRequest()->isXmlHttpRequest(),
'breadcrumbs' => array(
array(
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
'label' => $this->getEntityLabelPlural()
),
array(
'url' => $this->generateUrl($this->getRouteNameForAction('new')),
'label' => sprintf('%s creation', $this->getEntityLabel())
),
),
),
)
);
}

Expand All @@ -461,26 +480,27 @@ protected function doEdit($id)

$editForm = $this->createForm($this->getFormType(), $entity);

$parameters = array(
'form' => $editForm->createView(),
'form_method' => 'PUT',
'form_action' => $this->generateUrl($this->getRouteNameForAction('update'), array('id' => $entity->getId())),
'form_cancel_route' => $this->getRouteNameForAction('index'),
'form_title' => sprintf('%s edit', $this->getEntityLabel()),
'isAjax' => $this->getRequest()->isXmlHttpRequest(),
'breadcrumbs' => array(
array(
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
'label' => $this->getEntityLabelPlural()
),
array(
'url' => $this->generateUrl($this->getRouteNameForAction('edit'), array('id' => $entity->getId())),
'label' => sprintf('%s edit', $this->getEntityLabel())
return $this->render(
$this->getFormTemplate(),
array(
'form' => $editForm->createView(),
'form_method' => 'GET',
'form_action' => $this->generateUrl($this->getRouteNameForAction('update'), array('id' => $entity->getId())),
'form_cancel_route' => $this->getRouteNameForAction('index'),
'form_title' => sprintf('%s edit', $this->getEntityLabel()),
'isAjax' => $this->getRequest()->isXmlHttpRequest(),
'breadcrumbs' => array(
array(
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
'label' => $this->getEntityLabelPlural()
),
array(
'url' => $this->generateUrl($this->getRouteNameForAction('edit'), array('id' => $entity->getId())),
'label' => sprintf('%s edit', $this->getEntityLabel())
),
),
),
)
);

return $parameters;
}

/**
Expand All @@ -504,7 +524,7 @@ protected function doUpdate(Request $request, $id)
throw new NotFoundHttpException(sprintf('Unable to find %s entity.', $this->getEntity()));
}

$editForm = $this->createForm($this->getFormType(), $entity);
$editForm = $this->createForm($this->getFormType(), $entity);
$editForm->submit($request);

if ($editForm->isValid()) {
Expand Down Expand Up @@ -573,24 +593,27 @@ protected function doUpdate(Request $request, $id)
return $this->redirect($this->generateUrl($this->getRouteNameForAction('edit'), array('id' => $id)));
}

return array(
'form' => $editForm->createView(),
'form_method' => 'PUT',
'form_action' => $this->generateUrl($this->getRouteNameForAction('update'), array('id' => $entity->getId())),
'form_cancel_route' => $this->getRouteNameForAction('index'),
'form_title' => sprintf('%s edit', $this->getEntityLabel()),
'delete_form_action' => $this->generateUrl($this->getRouteNameForAction('delete'), array('id' => $entity->getId())),
'isAjax' => $request->isXmlHttpRequest(),
'breadcrumbs' => array(
array(
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
'label' => $this->getEntityLabelPlural()
),
array(
'url' => $this->generateUrl($this->getRouteNameForAction('edit'), array('id' => $entity->getId())),
'label' => sprintf('%s edit', $this->getEntityLabel())
return $this->render(
$this->getFormTemplate(),
array(
'form' => $editForm->createView(),
'form_method' => 'POST',
'form_action' => $this->generateUrl($this->getRouteNameForAction('update'), array('id' => $entity->getId())),
'form_cancel_route' => $this->getRouteNameForAction('index'),
'form_title' => sprintf('%s edit', $this->getEntityLabel()),
'delete_form_action' => $this->generateUrl($this->getRouteNameForAction('delete'), array('id' => $entity->getId())),
'isAjax' => $request->isXmlHttpRequest(),
'breadcrumbs' => array(
array(
'url' => $this->generateUrl($this->getRouteNameForAction('index')),
'label' => $this->getEntityLabelPlural()
),
array(
'url' => $this->generateUrl($this->getRouteNameForAction('edit'), array('id' => $entity->getId())),
'label' => sprintf('%s edit', $this->getEntityLabel())
),
),
),
)
);
}

Expand Down
2 changes: 1 addition & 1 deletion Controller/QuickLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function getEntity()
protected function getFields()
{
return array(
'id' => 'id',
'id' => 'ID',
'linkLabel' => 'linkLabel'
);
}
Expand Down
16 changes: 7 additions & 9 deletions Controller/TagCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ protected function getEntity()

protected function getFields()
{
return array('id' => 'ID', 'name' => 'Name');
return array(
'id' => 'ID',
'name' => 'Name'
);
}

public function getEntityLabel()
Expand All @@ -54,7 +57,6 @@ protected function getEntityLabelPlural()
*
* @Route("/", name="admin_tag_category")
* @Method("GET")
* @Template("BigfootCoreBundle:crud:index.html.twig")
*/
public function indexAction()
{
Expand All @@ -66,7 +68,6 @@ public function indexAction()
*
* @Route("/", name="admin_tag_category_create")
* @Method("POST")
* @Template("BigfootCoreBundle:crud:form.html.twig")
*/
public function createAction(Request $request)
{
Expand All @@ -78,7 +79,6 @@ public function createAction(Request $request)
*
* @Route("/new", name="admin_tag_category_new")
* @Method("GET")
* @Template("BigfootCoreBundle:crud:form.html.twig")
*/
public function newAction()
{
Expand All @@ -90,7 +90,6 @@ public function newAction()
*
* @Route("/{id}/edit", name="admin_tag_category_edit")
* @Method("GET")
* @Template("BigfootCoreBundle:crud:form.html.twig")
*/
public function editAction($id)
{
Expand All @@ -101,8 +100,7 @@ public function editAction($id)
* Edits an existing TagCategory entity.
*
* @Route("/{id}", name="admin_tag_category_update")
* @Method("PUT")
* @Template("BigfootCoreBundle:crud:form.html.twig")
* @Method("GET|POST|PUT")
*/
public function updateAction(Request $request, $id)
{
Expand All @@ -111,8 +109,8 @@ public function updateAction(Request $request, $id)
/**
* Deletes a TagCategory entity.
*
* @Route("/{id}", name="admin_tag_category_delete")
* @Method("DELETE")
* @Route("/{id}/delete", name="admin_tag_category_delete")
* @Method("GET|DELETE")
*/
public function deleteAction(Request $request, $id)
{
Expand Down
Loading

0 comments on commit ed06de6

Please sign in to comment.