public function configure() { $adminCode = $this->container->get('request')->get('_sonata_admin'); if ($adminCode) { parent::configure(); } }
/** * @param object $object * @return \Symfony\Component\HttpFoundation\Response */ public function redirectTo($object) { if ($this->get('request')->get('btn_create_and_edit')) { $this->get('request')->query->set('btn_update_and_list', $this->get('request')->get('btn_create_and_edit')); } return parent::redirectTo($object); }
/** * {@inheritdoc} */ public function deleteAction($id) { if (!$this->_canUserBeDeleted($id)) { return $this->redirect($this->admin->generateUrl('edit', array('id' => $id))); } return parent::deleteAction($id); }
public function listAction(Request $request = null) { if (!$this->admin->getRequest()->get('form_id')) { return $this->formsListAction(); } return parent::listAction(); }
/** * Surcharge pour ne pas autoriser de nouvelles configurations si il y en a déja en base */ public function createAction() { if ($this->admin->getDatagrid()->getResults()->count() > 0) { $this->addFlash('sonata_flash_error', $this->admin->trans('flash_configuration_already_exists_error', array(), 'RedkingCoreRestBundle')); return new RedirectResponse($this->admin->generateUrl('list')); } return parent::createAction(); }
public function createAction() { $repo = $this->getDoctrine()->getManager()->getRepository('IndicadoresBundle:OrigenDatos'); $this->admin->setRepository($repo); $vitacora = $this->get('vitacora.siig'); $vitacora->addInfo('Se Creo nuevo significado de Campo'); return parent::createAction(); }
public function configure() { parent::configure(); $this->admin->setUniqid('news'); $templates = $this->admin->getTemplates(); $templates['edit'] = 'CMSNewsBundle:Admin:edit.html.twig'; $this->admin->setTemplates($templates); }
/** * @param string $view * @param array $parameters * @param Response $response * @return Response */ public function render($view, array $parameters = array(), Response $response = null) { if (array_key_exists('action', $parameters) && $parameters['action'] == 'edit') { $event = new CmsEvent($parameters['object']); $this->dispatcher->dispatch(CRUDController::EDIT_ENTITY, $event); } return parent::render($view, $parameters, $response); }
public function editAction($id = null) { if ($this->getRestMethod() == 'POST') { $request = $this->container->get('request'); $this->saveMenuItems($id, $request); } return parent::editAction($id); // TODO: Change the autogenerated stub }
protected function addFlash($type, $message, $flashIcon = null) { $icon = $flashIcon !== null ? $flashIcon : $this->admin->flashIcon; if (null !== $icon) { $flash = '<div class="admin-flash-icon">%s</div><div class="admin-flash-content">%s</div>'; $message = sprintf($flash, $icon, $message); } parent::addFlash($type, $message); }
public function deleteAction($id) { /** @var $action RedirectResponse */ $action = parent::deleteAction($id); if ($this->getRequest()->getMethod() == 'DELETE' && $this->isXmlHttpRequest()) { return $this->renderJson(array('result' => 'ok')); } return $action; }
public function editAction($id = NULL) { $result = parent::editAction($id); if ($this->getRestMethod() == 'POST' && $this->admin->getForm()->isValid()) { /** @var SeoFile $seo_file */ $seo_file = $this->admin->getSubject(); $this->writeFile($seo_file->getName(), $seo_file->getContent()); } return $result; }
/** * Batch forms deletion * * @param ProxyQueryInterface $query * @param Request $request * @return RedirectResponse */ public function batchActionDelete(ProxyQueryInterface $query, Request $request = null) { /** @var FcForm $fc_form */ foreach ($query->find() as $fc_form) { if ($fc_form->isUsedAsWidget()) { $this->addFlash('sonata_flash_error', $this->admin->trans('fc.message.admin.form.is_used_as_widget', array(), 'FenrizbesFormConstructorBundle')); return new RedirectResponse($this->admin->generateUrl('list', array('filter' => $this->admin->getFilterParameters()))); } } return parent::batchActionDelete($query); }
/** * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException * @return \Symfony\Bundle\FrameworkBundle\Controller\Response|\Symfony\Component\HttpFoundation\Response */ public function createAction() { if (false === $this->admin->isGranted('CREATE')) { throw new AccessDeniedException(); } $parameters = $this->admin->getPersistentParameters(); if (!$parameters['provider']) { return $this->render('SonataProductBundle:ProductAdmin:select_provider.html.twig', array('providers' => $this->get('sonata.product.pool')->getProducts(), 'base_template' => $this->getBaseTemplate(), 'admin' => $this->admin, 'action' => 'create')); } return parent::createAction(); }
public function createAction() { if (false === $this->admin->isGranted('CREATE')) { throw new AccessDeniedException(); } $parameters = $this->admin->getPersistentParameters(); $routeTypes = $this->admin->getRouteTypePool()->getRouteTypes(); if (!isset($parameters['route_type'])) { return $this->render('GravityCmsBundle:Route:create_select_route_type.html.twig', ['route_types' => $routeTypes, 'base_template' => $this->getBaseTemplate(), 'admin' => $this->admin, 'action' => 'create']); } return parent::createAction(); }
/** * @return \Symfony\Component\HttpFoundation\Response */ public function createAction(Request $request = null) { $this->admin->checkAccess('create'); $sharedBlockAdminClass = $this->container->getParameter('sonata.page.admin.shared_block.class'); if (!$this->admin->getParent() && get_class($this->admin) !== $sharedBlockAdminClass) { throw new PageNotFoundException('You cannot create a block without a page'); } $parameters = $this->admin->getPersistentParameters(); if (!$parameters['type']) { return $this->render('SonataPageBundle:BlockAdmin:select_type.html.twig', array('services' => $this->get('sonata.block.manager')->getServicesByContext('sonata_page_bundle'), 'base_template' => $this->getBaseTemplate(), 'admin' => $this->admin, 'action' => 'create')); } return parent::createAction(); }
public function testBatchActionNoItems() { $batchActions = array('delete' => array('label' => 'Foo Bar', 'ask_confirmation' => true)); $this->admin->expects($this->once())->method('getBatchActions')->will($this->returnValue($batchActions)); $datagrid = $this->getMock('\\Sonata\\AdminBundle\\Datagrid\\DatagridInterface'); $this->admin->expects($this->once())->method('getDatagrid')->will($this->returnValue($datagrid)); $this->request->setMethod('POST'); $this->request->request->set('action', 'delete'); $this->request->request->set('idx', array()); $result = $this->controller->batchAction(); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $result); $this->assertSame(array('flash_batch_empty'), $this->session->getFlashBag()->get('sonata_flash_info')); $this->assertEquals('list?', $result->getTargetUrl()); }
/** * @return \Symfony\Component\HttpFoundation\Response */ public function createAction() { if (false === $this->admin->isGranted('CREATE')) { throw new AccessDeniedException(); } if (!$this->admin->getParent()) { throw new PageNotFoundException('You cannot create a block without a page'); } $parameters = $this->admin->getPersistentParameters(); if (!$parameters['type']) { return $this->render('SonataPageBundle:BlockAdmin:select_type.html.twig', array('services' => $this->get('sonata.block.manager')->getServices(), 'base_template' => $this->getBaseTemplate(), 'admin' => $this->admin, 'action' => 'create')); } return parent::createAction(); }
public function editAction($id = null) { if ($this->getRestMethod() == 'POST') { $object = $this->admin->getObject($id); $user = $this->getDoctrine()->getRepository('\\Application\\Sonata\\UserBundle\\Entity\\User')->find($this->getUser()->getId()); $order = $object->getOrder(); $object->setCanceledBy($user); $this->admin->update($object); if ($order) { $order->setInvoiceNumber(""); $this->admin->update($order); } } return parent::editAction($id); }
public function createAction() { $parameters = $this->admin->getPersistentParameters(); if (!$parameters['provider']) { return $this->render('SonataMediaBundle:MediaAdmin:select_provider.html.twig', array( 'providers' => $this->get('sonata.media.pool')->getProvidersByContext($this->get('request')->get('context', 'default')), 'base_template' => $this->getBaseTemplate(), 'admin' => $this->admin, 'action' => 'create' )); } return parent::createAction(); }
/** * @param Request $request * * @return Response */ public function createAction(Request $request = null) { $this->admin->checkAccess('create'); if (!$this->admin->getParent()) { throw new NotFoundHttpException('You cannot create a block without a dashboard'); } $parameters = $this->admin->getPersistentParameters(); if (!$parameters['type']) { return $this->render('SonataDashboardBundle:BlockAdmin:select_type.html.twig', array('services' => $this->get('sonata.block.manager')->getServicesByContext('sonata_dashboard_bundle'), 'base_template' => $this->getBaseTemplate(), 'admin' => $this->admin, 'action' => 'create')); } elseif ($parameters['type'] == $this->admin->getDefaultContainerType()) { $dashboard = $this->admin->getParent()->getSubject(); $position = count($dashboard->getBlocks()) + 1; $name = $request->get('name') != '' ? $request->get('name') : $this->admin->trans('composer.default.container.name', array('%position%' => $position), ''); $container = $this->get('sonata.dashboard.block_interactor')->createNewContainer(array('name' => $name, 'dashboard' => $dashboard, 'position' => $position, 'code' => $name)); return $this->render('SonataDashboardBundle:BlockAdmin:block_container.html.twig', array('admin' => $this->admin->getParent(), 'object' => $container)); } return parent::createAction(); }
/** * Contextualize the admin class depends on the current request. * * @throws \RuntimeException */ protected function configure() { parent::configure(); $this->appadmin = $this->container->get('sonata.admin.pool')->getAdminByAdminCode('sonata.admin.application'); if (!$this->appadmin) { throw new \RuntimeException(sprintf('Unable to find the admin class related to the current controller (%s)', get_class($this))); } $rootAdmin = $this->appadmin; if ($this->appadmin->isChild()) { $this->appadmin->setCurrentChild(true); $rootAdmin = $rootAdmin->getParent(); } $request = $this->container->get('request'); $rootAdmin->setRequest($request); if ($request->get('uniqid')) { $this->appadmin->setUniqid($request->get('uniqid')); } }
/** * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response * * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function createAction() { if (false === $this->admin->isGranted('CREATE')) { throw new AccessDeniedException(); } if ($this->getRequest()->getMethod() == 'GET' && !$this->getRequest()->get('siteId')) { $sites = $this->get('sonata.page.manager.site')->findBy(array()); if (count($sites) == 1) { return $this->redirect($this->admin->generateUrl('create', array('siteId' => $sites[0]->getId(), 'uniqid' => $this->admin->getUniqid()))); } try { $current = $this->get('sonata.page.site.selector')->retrieve(); } catch (\RuntimeException $e) { $current = false; } return $this->render('SonataPageBundle:PageAdmin:select_site.html.twig', array('sites' => $sites, 'current' => $current)); } return parent::createAction(); }
public function testBatchActionWithRequesData() { $batchActions = array('delete' => array('label' => 'Foo Bar', 'ask_confirmation' => false)); $this->admin->expects($this->once())->method('getBatchActions')->will($this->returnValue($batchActions)); $datagrid = $this->getMock('\\Sonata\\AdminBundle\\Datagrid\\DatagridInterface'); $query = $this->getMock('\\Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface'); $datagrid->expects($this->once())->method('getQuery')->will($this->returnValue($query)); $this->admin->expects($this->once())->method('getDatagrid')->will($this->returnValue($datagrid)); $modelManager = $this->getMock('Sonata\\AdminBundle\\Model\\ModelManagerInterface'); $this->admin->expects($this->once())->method('checkAccess')->with($this->equalTo('batchDelete'))->will($this->returnValue(true)); $this->admin->expects($this->any())->method('getModelManager')->will($this->returnValue($modelManager)); $this->admin->expects($this->any())->method('getClass')->will($this->returnValue('Foo')); $modelManager->expects($this->once())->method('addIdentifiersToQuery')->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(array('123', '456')))->will($this->returnValue(true)); $this->request->setMethod('POST'); $this->request->request->set('data', json_encode(array('action' => 'delete', 'idx' => array('123', '456'), 'all_elements' => false))); $this->request->request->set('foo', 'bar'); $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); $result = $this->controller->batchAction($this->request); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $result); $this->assertSame(array('flash_batch_delete_success'), $this->session->getFlashBag()->get('sonata_flash_success')); $this->assertSame('list?', $result->getTargetUrl()); $this->assertSame('bar', $this->request->request->get('foo')); }
/** * {@inheritdoc} */ public function render($view, array $parameters = array(), Response $response = null, Request $request = null) { $parameters['media_pool'] = $this->container->get('sonata.media.pool'); $parameters['persistent_parameters'] = $this->admin->getPersistentParameters(); return parent::render($view, $parameters, $response, $request); }
/** * @return mixed|string */ public function getBaseTemplate() { return str_replace('SonataAdminBundle', 'ApplicationSonataDevisesBundle', parent::getBaseTemplate()); }
/** * @param string $view * @param array $parameters * @param Response $response * * @return Response */ public function render($view, array $parameters = array(), Response $response = null) { if ($parameters && isset($parameters['action'])) { switch ($parameters['action']) { case 'edit': case 'create': $parameters['base_template'] = $this->admin->getTemplate('ajax'); break; } } return parent::render($view, $parameters, $response); }
/** * @param string $view * @param array $parameters * @param Response $response * * @return Response */ public function render($view, array $parameters = array(), Response $response = null) { if ($parameters && isset($parameters['action'])) { switch ($parameters['action']) { case 'list': case 'edit': case 'create': if ($this->get('request')->getMethod() != 'POST') { $parameters['base_template'] = 'ApplicationSonataClientBundle::ajax_layout.html.twig'; } break; } } return parent::render($view, $parameters, $response); }
public function deleteAction($id) { Request::enableHttpMethodParameterOverride(); // <-- add this line return parent::deleteAction($id); }
public function createAction() { $repo = $this->getDoctrine()->getEntityManager()->getRepository('IndicadoresBundle:OrigenDatos'); $this->admin->setRepository($repo); return parent::createAction(); }