Admin.php 44 KB

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