PageRenderTime 68ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/Admin/Admin.php

https://github.com/stephaneerard/SonataAdminBundle
PHP | 2118 lines | 1161 code | 240 blank | 717 comment | 35 complexity | 6053753b48269d0c84e3a6eb8277f48a MD5 | raw file
Possible License(s): JSON

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Admin;
  11. use Symfony\Component\Form\Form;
  12. use Symfony\Component\Form\FormBuilder;
  13. use Symfony\Component\Validator\ValidatorInterface;
  14. use Symfony\Component\Routing\RouterInterface;
  15. use Symfony\Component\Translation\TranslatorInterface;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\Security\Acl\Model\DomainObjectInterface;
  18. use Sonata\AdminBundle\Form\FormMapper;
  19. use Sonata\AdminBundle\Datagrid\ListMapper;
  20. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  21. use Sonata\AdminBundle\Show\ShowMapper;
  22. use Sonata\AdminBundle\Admin\Pool;
  23. use Sonata\AdminBundle\Validator\ErrorElement;
  24. use Sonata\AdminBundle\Builder\FormContractorInterface;
  25. use Sonata\AdminBundle\Builder\ListBuilderInterface;
  26. use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
  27. use Sonata\AdminBundle\Builder\ShowBuilderInterface;
  28. use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
  29. use Sonata\AdminBundle\Route\RouteCollection;
  30. use Sonata\AdminBundle\Model\ModelManagerInterface;
  31. use Knp\Menu\FactoryInterface as MenuFactoryInterface;
  32. use Knp\Menu\ItemInterface as MenuItemInterface;
  33. use Knp\Menu\MenuItem;
  34. abstract class Admin implements AdminInterface, DomainObjectInterface
  35. {
  36. /**
  37. * The class name managed by the admin class
  38. *
  39. * @var string
  40. */
  41. protected $class;
  42. /**
  43. * The list collection
  44. *
  45. * @var array
  46. */
  47. private $list;
  48. /**
  49. * The list FieldDescription constructed from the configureListField method
  50. *
  51. * @var array
  52. */
  53. protected $listFieldDescriptions = array();
  54. private $show;
  55. /**
  56. * The show FieldDescription constructed from the configureShowField method
  57. *
  58. * @var array
  59. */
  60. protected $showFieldDescriptions = array();
  61. /**
  62. * @var Form
  63. */
  64. private $form;
  65. /**
  66. * The list FieldDescription constructed from the configureFormField method
  67. *
  68. * @var array
  69. */
  70. protected $formFieldDescriptions = array();
  71. /**
  72. * @var DatagridInterface
  73. */
  74. private $filter;
  75. /**
  76. * The filter FieldDescription constructed from the configureFilterField method
  77. *
  78. * @var array
  79. */
  80. protected $filterFieldDescriptions = array();
  81. /**
  82. * The number of result to display in the list
  83. *
  84. * @var integer
  85. */
  86. protected $maxPerPage = 25;
  87. /**
  88. * The base route name used to generate the routing information
  89. *
  90. * @var string
  91. */
  92. protected $baseRouteName;
  93. /**
  94. * The base route pattern used to generate the routing information
  95. *
  96. * @var string
  97. */
  98. protected $baseRoutePattern;
  99. /**
  100. * The base name controller used to generate the routing information
  101. *
  102. * @var string
  103. */
  104. protected $baseControllerName;
  105. /**
  106. * The form group disposition
  107. *
  108. * @var array|boolean
  109. */
  110. private $formGroups = false;
  111. /**
  112. * The view group disposition
  113. *
  114. * @var array|boolean
  115. */
  116. private $showGroups = false;
  117. /**
  118. * The label class name (used in the title/breadcrumb ...)
  119. *
  120. * @var string
  121. */
  122. protected $classnameLabel;
  123. /**
  124. * The translation domain to be used to translate messages
  125. *
  126. * @var string
  127. */
  128. protected $translationDomain = 'messages';
  129. /**
  130. * Options to set to the form (ie, validation_groups)
  131. *
  132. * @var array
  133. */
  134. protected $formOptions = array();
  135. /**
  136. * Default values to the datagrid
  137. *
  138. * @var array
  139. */
  140. protected $datagridValues = array(
  141. '_page' => 1,
  142. );
  143. /**
  144. * The code related to the admin
  145. *
  146. * @var string
  147. */
  148. protected $code;
  149. /**
  150. * The label
  151. *
  152. * @var string
  153. */
  154. protected $label;
  155. /**
  156. * Array of routes related to this admin
  157. *
  158. * @var \Sonata\AdminBundle\Route\RouteCollection
  159. */
  160. protected $routes;
  161. /**
  162. * The subject only set in edit/update/create mode
  163. *
  164. * @var object
  165. */
  166. protected $subject;
  167. /**
  168. * Define a Collection of child admin, ie /admin/order/{id}/order-element/{childId}
  169. *
  170. * @var array
  171. */
  172. protected $children = array();
  173. /**
  174. * Reference the parent collection
  175. *
  176. * @var Admin
  177. */
  178. protected $parent = null;
  179. /**
  180. * The base code route refer to the prefix used to generate the route name
  181. *
  182. * @var string
  183. */
  184. protected $baseCodeRoute = '';
  185. /**
  186. * The related field reflection, ie if OrderElement is linked to Order,
  187. * then the $parentReflectionProperty must be the ReflectionProperty of
  188. * the order (OrderElement::$order)
  189. *
  190. * @var \ReflectionProperty $parentReflectionProperty
  191. */
  192. protected $parentAssociationMapping = null;
  193. /**
  194. * Reference the parent FieldDescription related to this admin
  195. * only set for FieldDescription which is associated to an Sub Admin instance
  196. *
  197. * @var FieldDescription
  198. */
  199. protected $parentFieldDescription;
  200. /**
  201. * If true then the current admin is part of the nested admin set (from the url)
  202. *
  203. * @var boolean
  204. */
  205. protected $currentChild = false;
  206. /**
  207. * The uniqid is used to avoid clashing with 2 admin related to the code
  208. * ie: a Block linked to a Block
  209. *
  210. * @var string
  211. */
  212. protected $uniqid;
  213. /**
  214. * The Entity or Document manager
  215. *
  216. * @var \Sonata\AdminBundle\Model\ModelManagerInterface
  217. */
  218. protected $modelManager;
  219. /**
  220. * The current request object
  221. *
  222. * @var \Symfony\Component\HttpFoundation\Request
  223. */
  224. protected $request;
  225. /**
  226. * The translator component
  227. *
  228. * @var \Symfony\Component\Translation\TranslatorInterface
  229. */
  230. protected $translator;
  231. /**
  232. * The related form contractor
  233. *
  234. * @var \Sonata\AdminBundle\Builder\FormContractorInterface
  235. */
  236. protected $formContractor;
  237. /**
  238. * The related list builder
  239. *
  240. * @var \Sonata\AdminBundle\Builder\ListBuilderInterface
  241. */
  242. protected $listBuilder;
  243. /**
  244. * The related view builder
  245. *
  246. * @var \Sonata\AdminBundle\View\ShowBuilderInterface
  247. */
  248. protected $showBuilder;
  249. /**
  250. * The related datagrid builder
  251. *
  252. * @var \Sonata\AdminBundle\Builder\DatagridBuilderInterface
  253. */
  254. protected $datagridBuilder;
  255. /**
  256. * The datagrid instance
  257. *
  258. * @var \Sonata\AdminBundle\Datagrid\DatagridInterface
  259. */
  260. protected $datagrid;
  261. /**
  262. * The router intance
  263. *
  264. * @var \Symfony\Component\Routing\RouterInterface
  265. */
  266. protected $router;
  267. /**
  268. * The generated breadcrumbs
  269. *
  270. * @var array
  271. */
  272. protected $breadcrumbs = array();
  273. protected $securityHandler = null;
  274. protected $validator = null;
  275. /**
  276. * The configuration pool
  277. *
  278. * @var Pool
  279. */
  280. protected $configurationPool;
  281. protected $menu;
  282. /**
  283. * @var \Knp\Menu\MenuFactoryInterface
  284. */
  285. protected $menuFactory;
  286. protected $loaded = array(
  287. 'view_fields' => false,
  288. 'view_groups' => false,
  289. 'routes' => false,
  290. 'side_menu' => false,
  291. );
  292. protected $formTheme = array('SonataAdminBundle:Form:form_admin_fields.html.twig');
  293. protected $filterTheme = array('SonataAdminBundle:Form:filter_admin_fields.html.twig');
  294. protected $extensions = array();
  295. /**
  296. * This method can be overwritten to tweak the form construction, by default the form
  297. * is built by reading the FieldDescription
  298. *
  299. * @param \Sonata\AdminBundle\Form\FormMapper $form
  300. * @return void
  301. */
  302. protected function configureFormFields(FormMapper $form)
  303. {
  304. }
  305. /**
  306. * overwrite this method to configure the list FormField definition
  307. *
  308. * @param \Sonata\AdminBundle\Datagrid\ListMapper $list
  309. * @return void
  310. */
  311. protected function configureListFields(ListMapper $list)
  312. {
  313. }
  314. /**
  315. * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $filter
  316. * @return void
  317. */
  318. protected function configureDatagridFilters(DatagridMapper $filter)
  319. {
  320. }
  321. /**
  322. * @param \Sonata\AdminBundle\Show\ShowMapper $filter
  323. * @return void
  324. */
  325. protected function configureShowField(ShowMapper $filter)
  326. {
  327. }
  328. /**
  329. * configure the Admin routes
  330. *
  331. * @param \Sonata\AdminBundle\Route\RouteCollection $collection
  332. * @return void
  333. */
  334. protected function configureRoutes(RouteCollection $collection)
  335. {
  336. }
  337. /**
  338. * @param \Knp\Menu\ItemInterface $menu
  339. * @param $action
  340. * @param null|Admin $childAdmin
  341. * @return void
  342. */
  343. protected function configureSideMenu(MenuItemInterface $menu, $action, Admin $childAdmin = null)
  344. {
  345. }
  346. /**
  347. * @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
  348. * @param $object
  349. * @return void
  350. */
  351. public function validate(ErrorElement $errorElement, $object)
  352. {
  353. }
  354. /**
  355. * @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
  356. * @param $object
  357. * @return void
  358. */
  359. public function doValidate(ErrorElement $errorElement, $object)
  360. {
  361. $this->validate($errorElement, $object);
  362. foreach ($this->extensions as $extension) {
  363. $extension->validate($this, $errorElement, $object);
  364. }
  365. }
  366. /**
  367. * @param string $code
  368. * @param string $class
  369. * @param string $baseControllerName
  370. */
  371. public function __construct($code, $class, $baseControllerName)
  372. {
  373. $this->code = $code;
  374. $this->class = $class;
  375. $this->baseControllerName = $baseControllerName;
  376. }
  377. public function configure()
  378. {
  379. $this->uniqid = uniqid();
  380. if (!$this->classnameLabel) {
  381. $this->classnameLabel = $this->urlize(substr($this->class, strrpos($this->class, '\\') + 1), '_');
  382. }
  383. $this->baseCodeRoute = $this->getCode();
  384. }
  385. public function update($object)
  386. {
  387. $this->preUpdate($object);
  388. $this->modelManager->update($object);
  389. $this->postUpdate($object);
  390. }
  391. public function create($object)
  392. {
  393. $this->prePersist($object);
  394. $this->modelManager->create($object);
  395. $this->postPersist($object);
  396. }
  397. public function delete($object)
  398. {
  399. $this->preRemove($object);
  400. $this->modelManager->delete($object);
  401. $this->postRemove($object);
  402. }
  403. public function preUpdate($object)
  404. {
  405. }
  406. public function postUpdate($object)
  407. {
  408. }
  409. public function prePersist($object)
  410. {
  411. }
  412. public function postPersist($object)
  413. {
  414. }
  415. public function preRemove($object)
  416. {
  417. }
  418. public function postRemove($object)
  419. {
  420. }
  421. /**
  422. * build the view FieldDescription array
  423. *
  424. * @return void
  425. */
  426. protected function buildShow()
  427. {
  428. if ($this->show) {
  429. return;
  430. }
  431. $collection = new FieldDescriptionCollection();
  432. $mapper = new ShowMapper($this->showBuilder, $collection, $this);
  433. $this->configureShowField($mapper);
  434. $this->show = $collection;
  435. }
  436. /**
  437. * build the list FieldDescription array
  438. *
  439. * @return void
  440. */
  441. protected function buildList()
  442. {
  443. if ($this->list) {
  444. return;
  445. }
  446. $this->list = $this->getListBuilder()->getBaseList();
  447. $mapper = new ListMapper($this->getListBuilder(), $this->list, $this);
  448. if (count($this->getBatchActions()) > 0) {
  449. $fieldDescription = $this->modelManager->getNewFieldDescriptionInstance($this->getClass(), 'batch', array(
  450. 'label' => 'batch',
  451. 'code' => '_batch',
  452. 'sortable' => false
  453. ));
  454. $fieldDescription->setAdmin($this);
  455. $fieldDescription->setTemplate('SonataAdminBundle:CRUD:list__batch.html.twig');
  456. $mapper->add($fieldDescription, 'batch');
  457. }
  458. $this->configureListFields($mapper);
  459. foreach($this->extensions as $extension) {
  460. $extension->configureListFields($mapper);
  461. }
  462. }
  463. /**
  464. * Get parameters that are currently bound to the filter.
  465. *
  466. * @return array
  467. */
  468. public function getFilterParameters()
  469. {
  470. $parameters = array();
  471. // build the values array
  472. if ($this->hasRequest()) {
  473. $parameters = array_merge(
  474. $this->getModelManager()->getDefaultSortValues($this->getClass()),
  475. $this->datagridValues,
  476. $this->request->query->get('filter', array())
  477. );
  478. // always force the parent value
  479. if ($this->isChild() && $this->getParentAssociationMapping()) {
  480. $parameters[$this->getParentAssociationMapping()] = array('value' => $this->request->get($this->getParent()->getIdParameter()));
  481. }
  482. }
  483. return $parameters;
  484. }
  485. /**
  486. * build the filter FieldDescription array
  487. *
  488. * @return void
  489. */
  490. public function buildDatagrid()
  491. {
  492. if ($this->datagrid) {
  493. return;
  494. }
  495. // initialize the datagrid
  496. $this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $this->getFilterParameters());
  497. $this->datagrid->getPager()->setMaxPerPage($this->maxPerPage);
  498. $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this);
  499. // build the datagrid filter
  500. $this->configureDatagridFilters($mapper);
  501. // ok, try to limit to add parent filter
  502. if ($this->getParentAssociationMapping()) {
  503. $mapper->add($this->getParentAssociationMapping(), null, array(
  504. 'field_type' => 'sonata_type_model_reference',
  505. 'field_options' => array(
  506. 'model_manager' => $this->getModelManager()
  507. ),
  508. 'operator_type' => 'hidden'
  509. ));
  510. }
  511. foreach($this->extensions as $extension) {
  512. $extension->configureDatagridFilters($mapper);
  513. }
  514. }
  515. /**
  516. * Returns the name of the parent related field, so the field can be use to set the default
  517. * value (ie the parent object) or to filter the object
  518. *
  519. * @return string the name of the parent related field
  520. */
  521. public function getParentAssociationMapping()
  522. {
  523. return $this->parentAssociationMapping;
  524. }
  525. /**
  526. * Build the form FieldDescription collection
  527. *
  528. * @return void
  529. */
  530. protected function buildForm()
  531. {
  532. if ($this->form) {
  533. return;
  534. }
  535. // append parent object if any
  536. // todo : clean the way the Admin class can retrieve set the object
  537. if ($this->isChild() && $this->getParentAssociationMapping()) {
  538. $parent = $this->getParent()->getObject($this->request->get($this->getParent()->getIdParameter()));
  539. $propertyPath = new \Symfony\Component\Form\Util\PropertyPath($this->getParentAssociationMapping());
  540. $object = $this->getSubject();
  541. $propertyPath->setValue($object, $parent);
  542. }
  543. $this->form = $this->getFormBuilder()->getForm();
  544. }
  545. /**
  546. * Returns the baseRoutePattern used to generate the routing information
  547. *
  548. * @throws RuntimeException
  549. * @return string the baseRoutePattern used to generate the routing information
  550. */
  551. public function getBaseRoutePattern()
  552. {
  553. if (!$this->baseRoutePattern) {
  554. preg_match('@([A-Za-z0-9]*)\\\([A-Za-z0-9]*)Bundle\\\(Entity|Document|Model)\\\(.*)@', $this->getClass(), $matches);
  555. if (!$matches) {
  556. throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', get_class($this)));
  557. }
  558. if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name
  559. $this->baseRoutePattern = sprintf('%s/{id}/%s',
  560. $this->getParent()->getBaseRoutePattern(),
  561. $this->urlize($matches[4], '-')
  562. );
  563. } else {
  564. $this->baseRoutePattern = sprintf('/%s/%s/%s',
  565. $this->urlize($matches[1], '-'),
  566. $this->urlize($matches[2], '-'),
  567. $this->urlize($matches[4], '-')
  568. );
  569. }
  570. }
  571. return $this->baseRoutePattern;
  572. }
  573. /**
  574. * Returns the baseRouteName used to generate the routing information
  575. *
  576. * @throws RuntimeException
  577. * @return string the baseRouteName used to generate the routing information
  578. */
  579. public function getBaseRouteName()
  580. {
  581. if (!$this->baseRouteName) {
  582. preg_match('@([A-Za-z0-9]*)\\\([A-Za-z0-9]*)Bundle\\\(Entity|Document|Model)\\\(.*)@', $this->getClass(), $matches);
  583. if (!$matches) {
  584. throw new \RuntimeException(sprintf('Please define a default `baseRouteName` value for the admin class `%s`', get_class($this)));
  585. }
  586. if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name
  587. $this->baseRouteName = sprintf('%s_%s',
  588. $this->getParent()->getBaseRouteName(),
  589. $this->urlize($matches[4])
  590. );
  591. } else {
  592. $this->baseRouteName = sprintf('admin_%s_%s_%s',
  593. $this->urlize($matches[1]),
  594. $this->urlize($matches[2]),
  595. $this->urlize($matches[4])
  596. );
  597. }
  598. }
  599. return $this->baseRouteName;
  600. }
  601. /**
  602. * urlize the given word
  603. *
  604. * @param string $word
  605. * @param string $sep the separator
  606. *
  607. * @return string
  608. */
  609. public function urlize($word, $sep = '_')
  610. {
  611. return strtolower(preg_replace('/[^a-z0-9_]/i', $sep.'$1', $word));
  612. }
  613. /**
  614. * Returns the class name handled by the Admin instance
  615. *
  616. * @return string the class name handled by the Admin instance
  617. */
  618. public function getClass()
  619. {
  620. return $this->class;
  621. }
  622. /**
  623. * Returns the list of batchs actions
  624. *
  625. * @return array the list of batchs actions
  626. */
  627. public function getBatchActions()
  628. {
  629. $actions = array();
  630. if ($this->isGranted('DELETE')) {
  631. $actions['delete'] = array(
  632. 'label' => $this->trans('action_delete', array(), 'SonataAdminBundle'),
  633. 'ask_confirmation' => true, // by default always true
  634. );
  635. }
  636. return $actions;
  637. }
  638. /**
  639. * Returns the list of available urls
  640. *
  641. * @return \Sonata\AdminBundle\Route\RouteCollection the list of available urls
  642. */
  643. public function getRoutes()
  644. {
  645. $this->buildRoutes();
  646. return $this->routes;
  647. }
  648. /**
  649. * Returns the parameter representing router id, ie: {id} or {childId}
  650. *
  651. * @return string
  652. */
  653. public function getRouterIdParameter()
  654. {
  655. return $this->isChild() ? '{childId}' : '{id}';
  656. }
  657. /**
  658. * Returns the parameter representing request id, ie: id or childId
  659. *
  660. * @return string
  661. */
  662. public function getIdParameter()
  663. {
  664. return $this->isChild() ? 'childId' : 'id';
  665. }
  666. /**
  667. * Build all the related urls to the current admin
  668. *
  669. * @return void
  670. */
  671. public function buildRoutes()
  672. {
  673. if ($this->loaded['routes']) {
  674. return;
  675. }
  676. $this->loaded['routes'] = true;
  677. $collection = new RouteCollection(
  678. $this->getBaseCodeRoute(),
  679. $this->getBaseRouteName(),
  680. $this->getBaseRoutePattern(),
  681. $this->getBaseControllerName()
  682. );
  683. $collection->add('list');
  684. $collection->add('create');
  685. $collection->add('batch');
  686. $collection->add('edit', $this->getRouterIdParameter().'/edit');
  687. $collection->add('delete', $this->getRouterIdParameter().'/delete');
  688. $collection->add('show', $this->getRouterIdParameter().'/show');
  689. // add children urls
  690. foreach ($this->getChildren() as $children) {
  691. $collection->addCollection($children->getRoutes());
  692. }
  693. $this->configureRoutes($collection);
  694. foreach($this->extensions as $extension) {
  695. $extension->configureRoutes($this, $collection);
  696. }
  697. $this->routes = $collection;
  698. }
  699. /**
  700. * Returns the url defined by the $name
  701. *
  702. * @param strinf $name
  703. * @return Route
  704. */
  705. public function getRoute($name)
  706. {
  707. $this->buildRoutes();
  708. if (!$this->routes->has($name)) {
  709. return false;
  710. }
  711. return $this->routes->get($name);
  712. }
  713. public function hasRoute($name)
  714. {
  715. $this->buildRoutes();
  716. return $this->routes->has($name);
  717. }
  718. /**
  719. * generate the object url with the given $name
  720. *
  721. * @param string $name
  722. * @param $object
  723. * @param array $parameters
  724. *
  725. * @return return a complete url
  726. */
  727. public function generateObjectUrl($name, $object, array $parameters = array())
  728. {
  729. $parameters['id'] = $this->getNormalizedIdentifier($object);
  730. return $this->generateUrl($name, $parameters);
  731. }
  732. /**
  733. * generate the url with the given $name
  734. *
  735. * @throws RuntimeException
  736. * @param string $name
  737. * @param array $parameters
  738. *
  739. * @return return a complete url
  740. */
  741. public function generateUrl($name, array $parameters = array())
  742. {
  743. if (!$this->isChild()) {
  744. if (strpos($name, '.')) {
  745. $name = $this->getCode().'|'.$name;
  746. } else {
  747. $name = $this->getCode().'.'.$name;
  748. }
  749. }
  750. // if the admin is a child we automatically append the parent's id
  751. else if ($this->isChild()) {
  752. $name = $this->baseCodeRoute.'.'.$name;
  753. // twig template does not accept variable hash key ... so cannot use admin.idparameter ...
  754. // switch value
  755. if (isset($parameters['id'])) {
  756. $parameters[$this->getIdParameter()] = $parameters['id'];
  757. unset($parameters['id']);
  758. }
  759. $parameters[$this->getParent()->getIdParameter()] = $this->request->get($this->getParent()->getIdParameter());
  760. }
  761. // if the admin is linked to a parent FieldDescription (ie, embedded widget)
  762. if ($this->hasParentFieldDescription()) {
  763. // merge link parameter if any provided by the parent field
  764. $parameters = array_merge($parameters, $this->getParentFieldDescription()->getOption('link_parameters', array()));
  765. $parameters['uniqid'] = $this->getUniqid();
  766. $parameters['code'] = $this->getCode();
  767. $parameters['pcode'] = $this->getParentFieldDescription()->getAdmin()->getCode();
  768. $parameters['puniqid'] = $this->getParentFieldDescription()->getAdmin()->getUniqid();
  769. }
  770. if ($name == 'update' || substr($name, -7) == '|update') {
  771. $parameters['uniqid'] = $this->getUniqid();
  772. $parameters['code'] = $this->getCode();
  773. }
  774. // allows to define persistent parameters
  775. if ($this->hasRequest()) {
  776. $parameters = array_merge($this->getPersistentParameters(), $parameters);
  777. }
  778. $route = $this->getRoute($name);
  779. if (!$route) {
  780. throw new \RuntimeException(sprintf('unable to find the route `%s`', $name));
  781. }
  782. return $this->router->generate($route->getDefault('_sonata_name'), $parameters);
  783. }
  784. /**
  785. * Returns the list template
  786. *
  787. * @return string the list template
  788. */
  789. public function getListTemplate()
  790. {
  791. return 'SonataAdminBundle:CRUD:list.html.twig';
  792. }
  793. /**
  794. * Returns the edit template
  795. *
  796. * @return string the edit template
  797. */
  798. public function getEditTemplate()
  799. {
  800. return 'SonataAdminBundle:CRUD:edit.html.twig';
  801. }
  802. /**
  803. * Returns the view template
  804. *
  805. * @return string the view template
  806. */
  807. public function getShowTemplate()
  808. {
  809. return 'SonataAdminBundle:CRUD:show.html.twig';
  810. }
  811. /**
  812. * Returns an instance of the related classname
  813. *
  814. * @return Object An instance of the related classname
  815. */
  816. public function getNewInstance()
  817. {
  818. return $this->modelManager->getModelInstance($this->getClass());
  819. }
  820. /**
  821. * @return \Symfony\Component\Form\FormBuilder the form builder
  822. */
  823. public function getFormBuilder()
  824. {
  825. // add the custom inline validation option
  826. $metadata = $this->validator->getMetadataFactory()->getClassMetadata($this->class);
  827. $metadata->addConstraint(new \Sonata\AdminBundle\Validator\Constraints\InlineConstraint(array(
  828. 'service' => $this,
  829. 'method' => 'doValidate'
  830. )));
  831. $this->formOptions['data_class'] = $this->getClass();
  832. $formBuilder = $this->getFormContractor()->getFormBuilder(
  833. $this->getUniqid(),
  834. $this->formOptions
  835. );
  836. $this->defineFormBuilder($formBuilder);
  837. return $formBuilder;
  838. }
  839. /**
  840. * @param \Symfony\Component\Form\FormBuilder $formBuilder
  841. * @return void
  842. */
  843. public function defineFormBuilder(FormBuilder $formBuilder)
  844. {
  845. $mapper = new FormMapper($this->getFormContractor(), $formBuilder, $this);
  846. $this->configureFormFields($mapper);
  847. foreach($this->extensions as $extension) {
  848. $extension->configureFormFields($mapper);
  849. }
  850. }
  851. /**
  852. * attach an admin instance to the given FieldDescription
  853. *
  854. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  855. */
  856. public function attachAdminClass(FieldDescriptionInterface $fieldDescription)
  857. {
  858. $pool = $this->getConfigurationPool();
  859. $admin = $pool->getAdminByClass($fieldDescription->getTargetEntity());
  860. if (!$admin) {
  861. return;
  862. }
  863. $fieldDescription->setAssociationAdmin($admin);
  864. }
  865. /**
  866. * Returns the target object
  867. *
  868. * @param integer $id
  869. * @return object
  870. */
  871. public function getObject($id)
  872. {
  873. return $this->modelManager->find($this->getClass(), $id);
  874. }
  875. /**
  876. * Returns a form depend on the given $object
  877. *
  878. * @return \Symfony\Component\Form\Form
  879. */
  880. public function getForm()
  881. {
  882. $this->buildForm();
  883. return $this->form;
  884. }
  885. /**
  886. * Returns a list depend on the given $object
  887. *
  888. * @return \Sonata\AdminBundle\Admin\FieldDescriptionCollection
  889. */
  890. public function getList()
  891. {
  892. $this->buildList();
  893. return $this->list;
  894. }
  895. /**
  896. * Returns a list depend on the given $object
  897. *
  898. * @return \Sonata\AdminBundle\Datagrid\DatagridInterface
  899. */
  900. public function getDatagrid()
  901. {
  902. $this->buildDatagrid();
  903. return $this->datagrid;
  904. }
  905. /**
  906. * Build the side menu related to the current action
  907. *
  908. * @param string $action
  909. * @param \Sonata\AdminBundle\Admin\AdminInterface $childAdmin
  910. * @return MenuItem|false
  911. */
  912. public function buildSideMenu($action, AdminInterface $childAdmin = null)
  913. {
  914. if ($this->loaded['side_menu']) {
  915. return;
  916. }
  917. $this->loaded['side_menu'] = true;
  918. $menu = $this->menuFactory->createItem('root');
  919. $this->configureSideMenu($menu, $action, $childAdmin);
  920. foreach ($this->extensions as $extension) {
  921. $extension->configureSideMenu($this, $menu, $action, $childAdmin);
  922. }
  923. $this->menu = $menu;
  924. }
  925. /**
  926. * @param string $action
  927. * @param \Sonata\AdminBundle\Admin\AdminInterface $childAdmin
  928. * @return \Knp\MenuBundle\Menu
  929. */
  930. public function getSideMenu($action, AdminInterface $childAdmin = null)
  931. {
  932. if ($this->isChild()) {
  933. return $this->getParent()->getSideMenu($action, $this);
  934. }
  935. $this->buildSideMenu($action, $childAdmin);
  936. return $this->menu;
  937. }
  938. /**
  939. * Returns the root code
  940. *
  941. * @return string the root code
  942. */
  943. public function getRootCode()
  944. {
  945. return $this->getRoot()->getCode();
  946. }
  947. /**
  948. * Returns the master admin
  949. *
  950. * @return \Sonata\AdminBundle\Admin\Admin the root admin class
  951. */
  952. public function getRoot()
  953. {
  954. $parentFieldDescription = $this->getParentFieldDescription();
  955. if (!$parentFieldDescription) {
  956. return $this;
  957. }
  958. return $parentFieldDescription->getAdmin()->getRoot();
  959. }
  960. public function setBaseControllerName($baseControllerName)
  961. {
  962. $this->baseControllerName = $baseControllerName;
  963. }
  964. public function getBaseControllerName()
  965. {
  966. return $this->baseControllerName;
  967. }
  968. public function setLabel($label)
  969. {
  970. $this->label = $label;
  971. }
  972. public function getLabel()
  973. {
  974. return $this->label;
  975. }
  976. public function setMaxPerPage($maxPerPage)
  977. {
  978. $this->maxPerPage = $maxPerPage;
  979. }
  980. public function getMaxPerPage()
  981. {
  982. return $this->maxPerPage;
  983. }
  984. public function getFormGroups()
  985. {
  986. return $this->formGroups;
  987. }
  988. public function setFormGroups(array $formGroups)
  989. {
  990. $this->formGroups = $formGroups;
  991. }
  992. public function getShowGroups()
  993. {
  994. return $this->showGroups;
  995. }
  996. public function setShowGroups(array $showGroups)
  997. {
  998. $this->showGroups = $showGroups;
  999. }
  1000. /**
  1001. * set the parent FieldDescription
  1002. *
  1003. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $parentFieldDescription
  1004. * @return void
  1005. */
  1006. public function setParentFieldDescription(FieldDescriptionInterface $parentFieldDescription)
  1007. {
  1008. $this->parentFieldDescription = $parentFieldDescription;
  1009. }
  1010. /**
  1011. *
  1012. * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface the parent field description
  1013. */
  1014. public function getParentFieldDescription()
  1015. {
  1016. return $this->parentFieldDescription;
  1017. }
  1018. /**
  1019. * Returns true if the Admin is linked to a parent FieldDescription
  1020. *
  1021. * @return bool
  1022. */
  1023. public function hasParentFieldDescription()
  1024. {
  1025. return $this->parentFieldDescription instanceof FieldDescriptionInterface;
  1026. }
  1027. /**
  1028. * set the subject linked to the admin, the subject is the related model
  1029. *
  1030. * @param object $subject
  1031. * @return void
  1032. */
  1033. public function setSubject($subject)
  1034. {
  1035. $this->subject = $subject;
  1036. }
  1037. /**
  1038. * Returns the subject, if none is set try to load one from the request
  1039. *
  1040. * @return $object the subject
  1041. */
  1042. public function getSubject()
  1043. {
  1044. if ($this->subject === null && $this->request) {
  1045. $id = $this->request->get($this->getIdParameter());
  1046. if (!is_numeric($id)) {
  1047. $this->subject = false;
  1048. } else {
  1049. $this->subject = $this->getModelManager()->find($this->getClass(), $id);
  1050. }
  1051. }
  1052. return $this->subject;
  1053. }
  1054. /**
  1055. * build and return the collection of form FieldDescription
  1056. *
  1057. * @return array collection of form FieldDescription
  1058. */
  1059. public function getFormFieldDescriptions()
  1060. {
  1061. $this->buildForm();
  1062. return $this->formFieldDescriptions;
  1063. }
  1064. /**
  1065. * Returns the form FieldDescription with the given $name
  1066. *
  1067. * @param string $name
  1068. * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
  1069. */
  1070. public function getFormFieldDescription($name)
  1071. {
  1072. return $this->hasFormFieldDescription($name) ? $this->formFieldDescriptions[$name] : null;
  1073. }
  1074. /**
  1075. * Returns true if the admin has a FieldDescription with the given $name
  1076. *
  1077. * @param string $name
  1078. * @return bool
  1079. */
  1080. public function hasFormFieldDescription($name)
  1081. {
  1082. return array_key_exists($name, $this->formFieldDescriptions) ? true : false;
  1083. }
  1084. /**
  1085. * add a FieldDescription
  1086. *
  1087. * @param string $name
  1088. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  1089. * @return void
  1090. */
  1091. public function addFormFieldDescription($name, FieldDescriptionInterface $fieldDescription)
  1092. {
  1093. $this->formFieldDescriptions[$name] = $fieldDescription;
  1094. }
  1095. /**
  1096. * remove a FieldDescription
  1097. *
  1098. * @param string $name
  1099. * @return void
  1100. */
  1101. public function removeFormFieldDescription($name)
  1102. {
  1103. unset($this->formFieldDescriptions[$name]);
  1104. }
  1105. /**
  1106. * build and return the collection of form FieldDescription
  1107. *
  1108. * @return array collection of form FieldDescription
  1109. */
  1110. public function getShowFieldDescriptions()
  1111. {
  1112. return $this->showFieldDescriptions;
  1113. }
  1114. /**
  1115. * Returns the form FieldDescription with the given $name
  1116. *
  1117. * @param string $name
  1118. * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
  1119. */
  1120. public function getShowFieldDescription($name)
  1121. {
  1122. return $this->hasShowFieldDescription($name) ? $this->showFieldDescriptions[$name] : null;
  1123. }
  1124. /**
  1125. * Returns true if the admin has a FieldDescription with the given $name
  1126. *
  1127. * @param string $name
  1128. * @return bool
  1129. */
  1130. public function hasShowFieldDescription($name)
  1131. {
  1132. return array_key_exists($name, $this->showFieldDescriptions);
  1133. }
  1134. /**
  1135. * add a FieldDescription
  1136. *
  1137. * @param string $name
  1138. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  1139. * @return void
  1140. */
  1141. public function addShowFieldDescription($name, FieldDescriptionInterface $fieldDescription)
  1142. {
  1143. $this->showFieldDescriptions[$name] = $fieldDescription;
  1144. }
  1145. /**
  1146. * remove a FieldDescription
  1147. *
  1148. * @param string $name
  1149. * @return void
  1150. */
  1151. public function removeShowFieldDescription($name)
  1152. {
  1153. unset($this->showFieldDescriptions[$name]);
  1154. }
  1155. /**
  1156. * Returns the collection of list FieldDescriptions
  1157. *
  1158. * @return array
  1159. */
  1160. public function getListFieldDescriptions()
  1161. {
  1162. $this->buildList();
  1163. return $this->listFieldDescriptions;
  1164. }
  1165. /**
  1166. * Returns a list FieldDescription
  1167. *
  1168. * @param string $name
  1169. * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
  1170. */
  1171. public function getListFieldDescription($name)
  1172. {
  1173. return $this->hasListFieldDescription($name) ? $this->listFieldDescriptions[$name] : null;
  1174. }
  1175. /**
  1176. * Returns true if the list FieldDescription exists
  1177. *
  1178. * @param string $name
  1179. * @return bool
  1180. */
  1181. public function hasListFieldDescription($name)
  1182. {
  1183. $this->buildList();
  1184. return array_key_exists($name, $this->listFieldDescriptions) ? true : false;
  1185. }
  1186. /**
  1187. * add a list FieldDescription
  1188. *
  1189. * @param string $name
  1190. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  1191. * @return void
  1192. */
  1193. public function addListFieldDescription($name, FieldDescriptionInterface $fieldDescription)
  1194. {
  1195. $this->listFieldDescriptions[$name] = $fieldDescription;
  1196. }
  1197. /**
  1198. * remove a list FieldDescription
  1199. *
  1200. * @param string $name
  1201. * @return void
  1202. */
  1203. public function removeListFieldDescription($name)
  1204. {
  1205. unset($this->listFieldDescriptions[$name]);
  1206. }
  1207. /**
  1208. * Returns a filter FieldDescription
  1209. *
  1210. * @param string $name
  1211. * @return array|null
  1212. */
  1213. public function getFilterFieldDescription($name)
  1214. {
  1215. return $this->hasFilterFieldDescription($name) ? $this->filterFieldDescriptions[$name] : null;
  1216. }
  1217. /**
  1218. * Returns true if the filter FieldDescription exists
  1219. *
  1220. * @param string $name
  1221. * @return bool
  1222. */
  1223. public function hasFilterFieldDescription($name)
  1224. {
  1225. return array_key_exists($name, $this->filterFieldDescriptions) ? true : false;
  1226. }
  1227. /**
  1228. * add a filter FieldDescription
  1229. *
  1230. * @param string $name
  1231. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  1232. * @return void
  1233. */
  1234. public function addFilterFieldDescription($name, FieldDescriptionInterface $fieldDescription)
  1235. {
  1236. $this->filterFieldDescriptions[$name] = $fieldDescription;
  1237. }
  1238. /**
  1239. * remove a filter FieldDescription
  1240. *
  1241. * @param string $name
  1242. */
  1243. public function removeFilterFieldDescription($name)
  1244. {
  1245. unset($this->filterFieldDescriptions[$name]);
  1246. }
  1247. /**
  1248. * Returns the filter FieldDescription collection
  1249. *
  1250. * @param array filter FieldDescription collection
  1251. */
  1252. public function getFilterFieldDescriptions()
  1253. {
  1254. $this->buildDatagrid();
  1255. return $this->filterFieldDescriptions;
  1256. }
  1257. /**
  1258. * add an Admin child to the current one
  1259. *
  1260. * @param \Sonata\AdminBundle\Admin\AdminInterface $child
  1261. * @return void
  1262. */
  1263. public function addChild(AdminInterface $child)
  1264. {
  1265. $this->children[$child->getCode()] = $child;
  1266. $child->setBaseCodeRoute($this->getCode().'|'.$child->getCode());
  1267. $child->setParent($this);
  1268. }
  1269. /**
  1270. * Returns true or false if an Admin child exists for the given $code
  1271. *
  1272. * @param string $code Admin code
  1273. * @return bool True if child exist, false otherwise
  1274. */
  1275. public function hasChild($code)
  1276. {
  1277. return isset($this->children[$code]);
  1278. }
  1279. /**
  1280. * Returns an collection of admin children
  1281. *
  1282. * @return array list of Admin children
  1283. */
  1284. public function getChildren()
  1285. {
  1286. return $this->children;
  1287. }
  1288. /**
  1289. * Returns an admin child with the given $code
  1290. *
  1291. * @param string $code
  1292. * @return array|null
  1293. */
  1294. public function getChild($code)
  1295. {
  1296. return $this->hasChild($code) ? $this->children[$code] : null;
  1297. }
  1298. /**
  1299. * set the Parent Admin
  1300. *
  1301. * @param \Sonata\AdminBundle\Admin\AdminInterface $parent
  1302. * @return void
  1303. */
  1304. public function setParent(AdminInterface $parent)
  1305. {
  1306. $this->parent = $parent;
  1307. }
  1308. /**
  1309. * get the Parent Admin
  1310. *
  1311. * @return \Sonata\AdminBundle\Admin\AdminInterface|null
  1312. */
  1313. public function getParent()
  1314. {
  1315. return $this->parent;
  1316. }
  1317. /**
  1318. * Returns true if the Admin class has an Parent Admin defined
  1319. *
  1320. * @return boolean
  1321. */
  1322. public function isChild()
  1323. {
  1324. return $this->parent instanceof AdminInterface;
  1325. }
  1326. /**
  1327. * Returns true if the admin has children, false otherwise
  1328. *
  1329. * @return bool if the admin has children
  1330. */
  1331. public function hasChildren()
  1332. {
  1333. return count($this->children) > 0;
  1334. }
  1335. /**
  1336. * set the uniqid
  1337. *
  1338. * @param $uniqid
  1339. * @return void
  1340. */
  1341. public function setUniqid($uniqid)
  1342. {
  1343. $this->uniqid = $uniqid;
  1344. }
  1345. /**
  1346. * Returns the uniqid
  1347. *
  1348. * @return integer
  1349. */
  1350. public function getUniqid()
  1351. {
  1352. return $this->uniqid;
  1353. }
  1354. /**
  1355. * Returns the classname label
  1356. *
  1357. * @return string the classname label
  1358. */
  1359. public function getClassnameLabel()
  1360. {
  1361. return $this->classnameLabel;
  1362. }
  1363. /**
  1364. * Returns an array of persistent parameters
  1365. *
  1366. * @return array
  1367. */
  1368. public function getPersistentParameters()
  1369. {
  1370. return array();
  1371. }
  1372. /**
  1373. * @param string $action
  1374. * @return array
  1375. */
  1376. public function getBreadcrumbs($action)
  1377. {
  1378. if ($this->isChild()) {
  1379. return $this->getParent()->getBreadcrumbs($action);
  1380. }
  1381. return $this->buildBreadcrumbs($action);
  1382. }
  1383. /**
  1384. * Generates the breadcrumbs array
  1385. *
  1386. * @param string $action
  1387. * @param \Knp\Menu\MenuItem|null $menu
  1388. * @return array
  1389. */
  1390. public function buildBreadcrumbs($action, MenuItemInterface $menu = null)
  1391. {
  1392. if (isset($this->breadcrumbs[$action])) {
  1393. return $this->breadcrumbs[$action];
  1394. }
  1395. if (!$menu) {
  1396. $menu = $this->menuFactory->createItem('root');
  1397. }
  1398. $child = $menu->addChild(
  1399. $this->trans('breadcrumb.dashboard', array(), 'SonataAdminBundle'),
  1400. array('uri' => $this->router->generate('sonata_admin_dashboard'))
  1401. );
  1402. $child = $child->addChild(
  1403. $this->trans(sprintf('breadcrumb.link_%s_list', $this->getClassnameLabel())),
  1404. array('uri' => $this->generateUrl('list'))
  1405. );
  1406. $childAdmin = $this->getCurrentChildAdmin();
  1407. if ($childAdmin) {
  1408. $id = $this->request->get($this->getIdParameter());
  1409. $child = $child->addChild(
  1410. (string) $this->getSubject(),
  1411. array('uri' => $this->generateUrl('edit', array('id' => $id)))
  1412. );
  1413. return $childAdmin->buildBreadcrumbs($action, $child);
  1414. } elseif ($this->isChild()) {
  1415. if ($action != 'list') {
  1416. $menu = $menu->addChild(
  1417. $this->trans(sprintf('breadcrumb.link_%s_list', $this->getClassnameLabel())),
  1418. array('uri' => $this->generateUrl('list'))
  1419. );
  1420. }
  1421. $breadcrumbs = $menu->getBreadcrumbsArray(
  1422. $this->trans(sprintf('breadcrumb.link_%s_%s', $this->getClassnameLabel(), $action))
  1423. );
  1424. } else if ($action != 'list') {
  1425. $breadcrumbs = $child->getBreadcrumbsArray(
  1426. $this->trans(sprintf('breadcrumb.link_%s_%s', $this->getClassnameLabel(), $action))
  1427. );
  1428. } else {
  1429. $breadcrumbs = $child->getBreadcrumbsArray();
  1430. }
  1431. // the generated $breadcrumbs contains an empty element
  1432. array_shift($breadcrumbs);
  1433. return $this->breadcrumbs[$action] = $breadcrumbs;
  1434. }
  1435. /**
  1436. * set the current child status
  1437. *
  1438. * @param boolean $currentChild
  1439. * @return void
  1440. */
  1441. public function setCurrentChild($currentChild)
  1442. {
  1443. $this->currentChild = $currentChild;
  1444. }
  1445. /**
  1446. * Returns the current child status
  1447. *
  1448. * @return bool
  1449. */
  1450. public function getCurrentChild()
  1451. {
  1452. return $this->currentChild;
  1453. }
  1454. /**
  1455. * Returns the current child admin instance
  1456. *
  1457. * @return \Sonata\AdminBundle\Admin\AdminInterface|null the current child admin instance
  1458. */
  1459. public function getCurrentChildAdmin()
  1460. {
  1461. foreach ($this->children as $children) {
  1462. if ($children->getCurrentChild()) {
  1463. return $children;
  1464. }
  1465. }
  1466. return null;
  1467. }
  1468. /**
  1469. * translate a message id
  1470. *
  1471. * @param string $id
  1472. * @param array $parameters
  1473. * @param null $domain
  1474. * @param null $locale
  1475. * @return string the translated string
  1476. */
  1477. public function trans($id, array $parameters = array(), $domain = null, $locale = null)
  1478. {
  1479. $domain = $domain ?: $this->translationDomain;
  1480. if (!$this->translator) {
  1481. return $id;
  1482. }
  1483. return $this->translator->trans($id, $parameters, $domain, $locale);
  1484. }
  1485. /**
  1486. * set the translation domain
  1487. *
  1488. * @param string $translationDomain the translation domain
  1489. * @return void
  1490. */
  1491. public function setTranslationDomain($translationDomain)
  1492. {
  1493. $this->translationDomain = $translationDomain;
  1494. }
  1495. /**
  1496. * Returns the translation domain
  1497. *
  1498. * @return string the translation domain
  1499. */
  1500. public function getTranslationDomain()
  1501. {
  1502. return $this->translationDomain;
  1503. }
  1504. /**
  1505. * @param \Symfony\Component\Translation\TranslatorInterface $translator
  1506. * @return void
  1507. */
  1508. public function setTranslator(TranslatorInterface $translator)
  1509. {
  1510. $this->translator = $translator;
  1511. }
  1512. /**
  1513. * @return \Symfony\Component\Translation\TranslatorInterface
  1514. */
  1515. public function getTranslator()
  1516. {
  1517. return $this->translator;
  1518. }
  1519. /**
  1520. * @param \Symfony\Component\HttpFoundation\Request $request
  1521. * @return void
  1522. */
  1523. public function setRequest(Request $request)
  1524. {
  1525. $this->request = $request;
  1526. if ($request->get('uniqid')) {
  1527. $this->setUniqid($request->get('uniqid'));
  1528. }
  1529. foreach ($this->getChildren() as $children) {
  1530. $children->setRequest($request);
  1531. }
  1532. }
  1533. /**
  1534. * @return \Symfony\Component\HttpFoundation\Request
  1535. */
  1536. public function getRequest()
  1537. {
  1538. if (!$this->request) {
  1539. throw new \RuntimeException('The Request object has not been set');
  1540. }
  1541. return $this->request;
  1542. }
  1543. /**
  1544. *
  1545. * @return true if the request object is linked to the Admin
  1546. */
  1547. public function hasRequest()
  1548. {
  1549. return $this->request !== null;
  1550. }
  1551. /**
  1552. * @param \Sonata\AdminBundle\Builder\FormContractorInterface $formBuilder
  1553. * @return void
  1554. */
  1555. public function setFormContractor(FormContractorInterface $formBuilder)
  1556. {
  1557. $this->formContractor = $formBuilder;
  1558. }
  1559. /**
  1560. * @return \Sonata\AdminBundle\Builder\FormContractorInterface
  1561. */
  1562. public function getFormContractor()
  1563. {
  1564. return $this->formContractor;
  1565. }
  1566. /**
  1567. * @param \Sonata\AdminBundle\Builder\DatagridBuilderInterface $datagridBuilder
  1568. * @return void
  1569. */
  1570. public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder)
  1571. {
  1572. $this->datagridBuilder = $datagridBuilder;
  1573. }
  1574. /**
  1575. * @return \Sonata\AdminBundle\Builder\DatagridBuilderInterface
  1576. */
  1577. public function getDatagridBuilder()
  1578. {
  1579. return $this->datagridBuilder;
  1580. }
  1581. /**
  1582. * @param \Sonata\AdminBundle\Builder\ListBuilderInterface $listBuilder
  1583. * @return void
  1584. */
  1585. public function setListBuilder(ListBuilderInterface $listBuilder)
  1586. {
  1587. $this->listBuilder = $listBuilder;
  1588. }
  1589. /**
  1590. * @return \Sonata\AdminBundle\Builder\ListBuilderInterface
  1591. */
  1592. public function getListBuilder()
  1593. {
  1594. return $this->listBuilder;
  1595. }
  1596. /**
  1597. * @param \Sonata\AdminBundle\Builder\ShowBuilderInterface $showBuilder
  1598. * @return void
  1599. */
  1600. public function setShowBuilder(ShowBuilderInterface $showBuilder)
  1601. {
  1602. $this->showBuilder = $showBuilder;
  1603. }
  1604. /**
  1605. * @return \Sonata\AdminBundle\Builder\ShowBuilderInterface
  1606. */
  1607. public function getShowBuilder()
  1608. {
  1609. return $this->showBuilder;
  1610. }
  1611. /**
  1612. * @param Pool $configurationPool
  1613. * @return void
  1614. */
  1615. public function setConfigurationPool(Pool $configurationPool)
  1616. {
  1617. $this->configurationPool = $configurationPool;
  1618. }
  1619. /**
  1620. * @return Pool
  1621. */
  1622. public function getConfigurationPool()
  1623. {
  1624. return $this->configurationPool;
  1625. }
  1626. /**
  1627. * @param \Symfony\Component\Routing\RouterInterface $router
  1628. * @return void
  1629. */
  1630. public function setRouter(RouterInterface $router)
  1631. {
  1632. $this->router = $router;
  1633. }
  1634. /**
  1635. * @return \Symfony\Component\Routing\RouterInterface
  1636. */
  1637. public function getRouter()
  1638. {
  1639. return $this->router;
  1640. }
  1641. public function getCode()
  1642. {
  1643. return $this->code;
  1644. }
  1645. public function setBaseCodeRoute($baseCodeRoute)
  1646. {
  1647. $this->baseCodeRoute = $baseCodeRoute;
  1648. }
  1649. public function getBaseCodeRoute()
  1650. {
  1651. return $this->baseCodeRoute;
  1652. }
  1653. /**
  1654. * @return \Sonata\AdminBundle\Model\ModelManagerInterface
  1655. */
  1656. public function getModelManager()
  1657. {
  1658. return $this->modelManager;
  1659. }
  1660. public function setModelManager(ModelManagerInterface $modelManager)
  1661. {
  1662. $this->modelManager = $modelManager;
  1663. }
  1664. /**
  1665. * Returns a unique identifier for this domain object.
  1666. *
  1667. * @return string
  1668. */
  1669. function getObjectIdentifier()
  1670. {
  1671. return $this->getCode();
  1672. }
  1673. /**
  1674. * Return the list of security name available for the current admin
  1675. * This should be used by experimented users
  1676. *
  1677. * @return array
  1678. */
  1679. public function getSecurityInformation()
  1680. {
  1681. return array(
  1682. 'EDIT' => array('EDIT'),
  1683. 'LIST' => array('LIST'),
  1684. 'CREATE' => array('CREATE'),
  1685. 'VIEW' => array('VIEW'),
  1686. 'DELETE' => array('DELETE'),
  1687. 'OPERATOR' => array('OPERATOR')
  1688. );
  1689. }
  1690. public function setSecurityHandler(SecurityHandlerInterface $securityHandler)
  1691. {
  1692. $this->securityHandler = $securityHandler;
  1693. }
  1694. public function getSecurityHandler()
  1695. {
  1696. return $this->securityHandler;
  1697. }
  1698. /**
  1699. * @param string $name
  1700. * @return boolean
  1701. */
  1702. public function isGranted($name)
  1703. {
  1704. return $this->securi

Large files files are truncated, but you can click here to view the full file