Admin.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  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 . '.delete' => array(
  588. 'name' => $this->getBaseRouteName().'_delete',
  589. 'pattern' => $this->getBaseRoutePattern().'/'.$this->getRouterIdParameter().'/delete',
  590. 'defaults' => array(
  591. '_controller' => $this->getBaseControllerName().':delete',
  592. '_sonata_admin' => $this->baseCodeRoute
  593. ),
  594. 'requirements' => array(),
  595. 'options' => array(),
  596. 'params' => array(),
  597. ),
  598. $this->baseCodeRoute . '.batch' => array(
  599. 'name' => $this->getBaseRouteName().'_batch',
  600. 'pattern' => $this->getBaseRoutePattern().'/batch',
  601. 'defaults' => array(
  602. '_controller' => $this->getBaseControllerName().':batch',
  603. '_sonata_admin' => $this->baseCodeRoute
  604. ),
  605. 'requirements' => array(),
  606. 'options' => array(),
  607. 'params' => array(),
  608. )
  609. );
  610. // add children urls
  611. foreach ($this->getChildren() as $children) {
  612. $this->urls = array_merge($this->urls, $children->getUrls());
  613. }
  614. $this->configureUrls();
  615. }
  616. /**
  617. * return the url defined by the $name
  618. *
  619. * @param $name
  620. * @return bool
  621. */
  622. public function getUrl($name)
  623. {
  624. $urls = $this->getUrls();
  625. if (!isset($urls[$name])) {
  626. return false;
  627. }
  628. return $urls[$name];
  629. }
  630. /**
  631. * generate the url with the given $name
  632. *
  633. * @throws RuntimeException
  634. * @param $name
  635. * @param array $parameters
  636. *
  637. * @return return a complete url
  638. */
  639. public function generateUrl($name, array $parameters = array())
  640. {
  641. if (!$this->isChild()) {
  642. if (strpos($name, '.')) {
  643. $name = $this->getCode().'|'.$name;
  644. } else {
  645. $name = $this->getCode().'.'.$name;
  646. }
  647. }
  648. // if the admin is a child we automatically append the parent's id
  649. else if ($this->isChild()) {
  650. $name = $this->baseCodeRoute.'.'.$name;
  651. // twig template does not accept variable hash key ... so cannot use admin.idparameter ...
  652. // switch value
  653. if (isset($parameters['id'])) {
  654. $parameters[$this->getIdParameter()] = $parameters['id'];
  655. unset($parameters['id']);
  656. }
  657. $parameters[$this->getParent()->getIdParameter()] = $this->request->get($this->getParent()->getIdParameter());
  658. }
  659. // if the admin is linked to a parent FieldDescription (ie, embedded widget)
  660. if ($this->hasParentFieldDescription()) {
  661. // merge link parameter if any provided by the parent field
  662. $parameters = array_merge($parameters, $this->getParentFieldDescription()->getOption('link_parameters', array()));
  663. $parameters['uniqid'] = $this->getUniqid();
  664. $parameters['code'] = $this->getCode();
  665. $parameters['pcode'] = $this->getParentFieldDescription()->getAdmin()->getCode();
  666. $parameters['puniqid'] = $this->getParentFieldDescription()->getAdmin()->getUniqid();
  667. }
  668. if ($name == 'update' || substr($name, -7) == '|update') {
  669. $parameters['uniqid'] = $this->getUniqid();
  670. $parameters['code'] = $this->getCode();
  671. }
  672. // allows to define persistent parameters
  673. $parameters = array_merge($this->getPersistentParameters(), $parameters);
  674. $url = $this->getUrl($name);
  675. if (!$url) {
  676. throw new \RuntimeException(sprintf('unable to find the url `%s`', $name));
  677. }
  678. return $this->router->generate($url['name'], $parameters);
  679. }
  680. /**
  681. * return the list template
  682. *
  683. * @return string the list template
  684. */
  685. public function getListTemplate()
  686. {
  687. return 'SonataAdminBundle:CRUD:list.html.twig';
  688. }
  689. /**
  690. * return the edit template
  691. *
  692. * @return string the edit template
  693. */
  694. public function getEditTemplate()
  695. {
  696. return 'SonataAdminBundle:CRUD:edit.html.twig';
  697. }
  698. /**
  699. * return the reflection fields related to the classname
  700. *
  701. * @return array The reflection fields related to the classname
  702. */
  703. public function getReflectionFields()
  704. {
  705. return $this->getClassMetaData()->reflFields;
  706. }
  707. /**
  708. * return an instance of the related classname
  709. *
  710. * @return Object An instance of the related classname
  711. */
  712. public function getNewInstance()
  713. {
  714. $class = $this->getClass();
  715. return new $class;
  716. }
  717. /**
  718. *
  719. * @return Form the base form
  720. */
  721. public function getBaseForm($object, $options = array())
  722. {
  723. return $this->getFormBuilder()->getBaseForm(
  724. $this->getUniqid(),
  725. $object,
  726. array_merge($this->formOptions, $options)
  727. );
  728. }
  729. /**
  730. *
  731. * @return Form the base form
  732. */
  733. public function getBaseDatagrid($values = array())
  734. {
  735. return new Datagrid(
  736. $this->getClass(),
  737. $this->getModelManager(),
  738. $values
  739. );
  740. }
  741. /**
  742. * attach an admin instance to the given FieldDescription
  743. *
  744. * @param FieldDescription $fieldDescription
  745. */
  746. public function attachAdminClass(FieldDescription $fieldDescription)
  747. {
  748. $pool = $this->getConfigurationPool();
  749. $admin = $pool->getAdminByClass($fieldDescription->getTargetEntity());
  750. if (!$admin) {
  751. throw new \RuntimeException(sprintf('You must define an Admin class for the `%s` field (targetEntity=%s)', $fieldDescription->getFieldName(), $fieldDescription->getTargetEntity()));
  752. }
  753. $fieldDescription->setAssociationAdmin($admin);
  754. }
  755. /**
  756. * return the target object
  757. *
  758. * @param integer $id
  759. * @return
  760. */
  761. public function getObject($id)
  762. {
  763. return $this->getModelManager()
  764. ->find($this->getClass(), $id);
  765. }
  766. /**
  767. * build the form group array
  768. *
  769. * @return void
  770. */
  771. public function buildFormGroups()
  772. {
  773. if ($this->loaded['form_groups']) {
  774. return;
  775. }
  776. $this->loaded['form_groups'] = true;
  777. if (!$this->formGroups) {
  778. $this->formGroups = array(
  779. false => array('fields' => array_keys($this->getFormFieldDescriptions()))
  780. );
  781. }
  782. // normalize array
  783. foreach ($this->formGroups as $name => $group) {
  784. if (!isset($this->formGroups[$name]['collapsed'])) {
  785. $this->formGroups[$name]['collapsed'] = false;
  786. }
  787. }
  788. }
  789. /**
  790. * return a form depend on the given $object
  791. *
  792. * @param object $object
  793. * @param array $options the form options
  794. * @return Symfony\Component\Form\Form
  795. */
  796. public function getForm($object, array $options = array())
  797. {
  798. // append parent object if any
  799. // todo : clean the way the Admin class can retrieve set the object
  800. if ($this->isChild() && $this->getParentAssociationMapping()) {
  801. $mapping = $this->getParentAssociationMapping();
  802. $parent = $this->getParent()->getObject($this->request->get($this->getParent()->getIdParameter()));
  803. $propertyPath = new \Symfony\Component\Form\PropertyPath($mapping['fieldName']);
  804. $propertyPath->setValue($object, $parent);
  805. }
  806. $form = $this->getBaseForm($object, $options);
  807. $mapper = new FormMapper($this->getFormBuilder(), $form, $this);
  808. $this->buildFormFieldDescriptions();
  809. $this->configureFormFields($mapper);
  810. foreach ($this->getFormFieldDescriptions() as $fieldDescription) {
  811. // do not add field already set in the configureFormField method
  812. if ($mapper->has($fieldDescription->getFieldName())) {
  813. continue;
  814. }
  815. $mapper->add($fieldDescription);
  816. }
  817. return $form;
  818. }
  819. /**
  820. * return a list depend on the given $object
  821. *
  822. * @param $object
  823. * @return Symfony\Component\Datagrid\ListCollection
  824. */
  825. public function getList(array $options = array())
  826. {
  827. $list = $this->getListBuilder()->getBaseList($options);
  828. $mapper = new ListMapper($this->getListBuilder(), $list, $this);
  829. $this->buildListFieldDescriptions();
  830. $this->configureListFields($mapper);
  831. foreach ($this->getListFieldDescriptions() as $fieldDescription) {
  832. // do not add field already set in the configureFormField method
  833. if ($mapper->has($fieldDescription->getFieldName())) {
  834. continue;
  835. }
  836. $mapper->add($fieldDescription);
  837. }
  838. return $list;
  839. }
  840. /**
  841. * return a list depend on the given $object
  842. *
  843. * @param $object
  844. * @return Symfony\Component\Datagrid\Datagrid
  845. */
  846. public function getDatagrid()
  847. {
  848. $parameters = $this->request->query->all();
  849. $datagrid = $this->getBaseDatagrid($parameters);
  850. $datagrid->setMaxPerPage($this->maxPerPage);
  851. if ($this->isChild() && $this->getParentAssociationMapping()) {
  852. $mapping = $this->getParentAssociationMapping();
  853. $parameters[$mapping['fieldName']] = $this->request->get($this->getParent()->getIdParameter());
  854. }
  855. $datagrid->setValues($parameters);
  856. $mapper = new DatagridMapper($this->getDatagridBuilder(), $datagrid, $this);
  857. $this->buildFilterFieldDescriptions();
  858. $this->configureDatagridFilters($mapper);
  859. foreach ($this->getFilterFieldDescriptions() as $fieldDescription) {
  860. $mapper->add($fieldDescription);
  861. }
  862. return $datagrid;
  863. }
  864. /**
  865. * Build the side menu related to the current action
  866. *
  867. * @return MenuItem|false
  868. */
  869. public function getSideMenu($action)
  870. {
  871. return false;
  872. }
  873. /**
  874. * return the root code
  875. *
  876. * @return string the root code
  877. */
  878. public function getRootCode()
  879. {
  880. return $this->getRoot()->getCode();
  881. }
  882. /**
  883. * return the master admin
  884. *
  885. * @return Admin the root admin class
  886. */
  887. public function getRoot()
  888. {
  889. $parentFieldDescription = $this->getParentFieldDescription();
  890. if (!$parentFieldDescription) {
  891. return $this;
  892. }
  893. return $parentFieldDescription->getAdmin()->getRoot();
  894. }
  895. public function setBaseControllerName($baseControllerName)
  896. {
  897. $this->baseControllerName = $baseControllerName;
  898. }
  899. public function getBaseControllerName()
  900. {
  901. return $this->baseControllerName;
  902. }
  903. public function setLabel($label)
  904. {
  905. $this->label = $label;
  906. }
  907. public function getLabel()
  908. {
  909. return $this->label;
  910. }
  911. public function setMaxPerPage($maxPerPage)
  912. {
  913. $this->maxPerPage = $maxPerPage;
  914. }
  915. public function getMaxPerPage()
  916. {
  917. return $this->maxPerPage;
  918. }
  919. public function setFormGroups($formGroups)
  920. {
  921. $this->formGroups = $formGroups;
  922. }
  923. public function getFormGroups()
  924. {
  925. $this->buildFormGroups();
  926. return $this->formGroups;
  927. }
  928. /**
  929. * set the parent FieldDescription
  930. *
  931. * @param FieldDescription $parentFieldDescription
  932. * @return void
  933. */
  934. public function setParentFieldDescription(FieldDescription $parentFieldDescription)
  935. {
  936. $this->parentFieldDescription = $parentFieldDescription;
  937. }
  938. /**
  939. *
  940. * @return FieldDescription the parent field description
  941. */
  942. public function getParentFieldDescription()
  943. {
  944. return $this->parentFieldDescription;
  945. }
  946. /**
  947. * return true if the Admin is linked to a parent FieldDescription
  948. *
  949. * @return bool
  950. */
  951. public function hasParentFieldDescription()
  952. {
  953. return $this->parentFieldDescription instanceof FieldDescription;
  954. }
  955. /**
  956. * set the subject linked to the admin, the subject is the related model
  957. *
  958. * @param object $subject
  959. * @return void
  960. */
  961. public function setSubject($subject)
  962. {
  963. $this->subject = $subject;
  964. }
  965. /**
  966. * return the subject, if none is set try to load one from the request
  967. *
  968. * @return $object the subject
  969. */
  970. public function getSubject()
  971. {
  972. if ($this->subject === null) {
  973. $id = $this->request->get($this->getIdParameter());
  974. if (!is_numeric($id)) {
  975. $this->subject = false;
  976. } else {
  977. $this->subject = $this->getModelManager()->find(
  978. $this->getClass(),
  979. $id
  980. );
  981. }
  982. }
  983. return $this->subject;
  984. }
  985. /**
  986. * build and return the collection of form FieldDescription
  987. *
  988. * @return array collection of form FieldDescription
  989. */
  990. public function getFormFieldDescriptions()
  991. {
  992. $this->buildFormFieldDescriptions();
  993. return $this->formFieldDescriptions;
  994. }
  995. /**
  996. * return the form FieldDescription with the given $name
  997. *
  998. * @param string $name
  999. * @return FieldDescription
  1000. */
  1001. public function getFormFieldDescription($name)
  1002. {
  1003. return $this->hasFormFieldDescription($name) ? $this->formFieldDescriptions[$name] : null;
  1004. }
  1005. /**
  1006. * return true if the admin has a FieldDescription with the given $name
  1007. *
  1008. * @param string $name
  1009. * @return bool
  1010. */
  1011. public function hasFormFieldDescription($name)
  1012. {
  1013. $this->buildFormFieldDescriptions();
  1014. return array_key_exists($name, $this->formFieldDescriptions) ? true : false;
  1015. }
  1016. /**
  1017. * add a FieldDescription
  1018. *
  1019. * @param string $name
  1020. * @param FieldDescription $fieldDescription
  1021. * @return void
  1022. */
  1023. public function addFormFieldDescription($name, FieldDescription $fieldDescription)
  1024. {
  1025. $this->formFieldDescriptions[$name] = $fieldDescription;
  1026. }
  1027. /**
  1028. * remove a FieldDescription
  1029. *
  1030. * @param string $name
  1031. * @return void
  1032. */
  1033. public function removeFormFieldDescription($name)
  1034. {
  1035. unset($this->formFieldDescriptions[$name]);
  1036. }
  1037. /**
  1038. * return the collection of list FieldDescriptions
  1039. *
  1040. * @return array
  1041. */
  1042. public function getListFieldDescriptions()
  1043. {
  1044. $this->buildListFieldDescriptions();
  1045. return $this->listFieldDescriptions;
  1046. }
  1047. /**
  1048. * return a list FieldDescription
  1049. *
  1050. * @param string $name
  1051. * @return FieldDescription
  1052. */
  1053. public function getListFieldDescription($name) {
  1054. return $this->hasListFieldDescription($name) ? $this->listFieldDescriptions[$name] : null;
  1055. }
  1056. /**
  1057. * return true if the list FieldDescription exists
  1058. *
  1059. * @param string $name
  1060. * @return bool
  1061. */
  1062. public function hasListFieldDescription($name)
  1063. {
  1064. $this->buildListFieldDescriptions();
  1065. return array_key_exists($name, $this->listFieldDescriptions) ? true : false;
  1066. }
  1067. /**
  1068. * add a list FieldDescription
  1069. *
  1070. * @param string $name
  1071. * @param FieldDescription $fieldDescription
  1072. * @return void
  1073. */
  1074. public function addListFieldDescription($name, FieldDescription $fieldDescription)
  1075. {
  1076. $this->listFieldDescriptions[$name] = $fieldDescription;
  1077. }
  1078. /**
  1079. * remove a list FieldDescription
  1080. *
  1081. * @param string $name
  1082. * @return void
  1083. */
  1084. public function removeListFieldDescription($name)
  1085. {
  1086. unset($this->listFieldDescriptions[$name]);
  1087. }
  1088. /**
  1089. * return a filter FieldDescription
  1090. *
  1091. * @param string $name
  1092. * @return array|null
  1093. */
  1094. public function getFilterFieldDescription($name) {
  1095. return $this->hasFilterFieldDescription($name) ? $this->filterFieldDescriptions[$name] : null;
  1096. }
  1097. /**
  1098. * return true if the filter FieldDescription exists
  1099. *
  1100. * @param string $name
  1101. * @return bool
  1102. */
  1103. public function hasFilterFieldDescription($name)
  1104. {
  1105. $this->buildFilterFieldDescriptions();
  1106. return array_key_exists($name, $this->filterFieldDescriptions) ? true : false;
  1107. }
  1108. /**
  1109. * add a filter FieldDescription
  1110. *
  1111. * @param string $name
  1112. * @param FieldDescription $fieldDescription
  1113. * @return void
  1114. */
  1115. public function addFilterFieldDescription($name, FieldDescription $fieldDescription)
  1116. {
  1117. $this->filterFieldDescriptions[$name] = $fieldDescription;
  1118. }
  1119. /**
  1120. * remove a filter FieldDescription
  1121. *
  1122. * @param string $name
  1123. */
  1124. public function removeFilterFieldDescription($name)
  1125. {
  1126. unset($this->filterFieldDescriptions[$name]);
  1127. }
  1128. /**
  1129. * return the filter FieldDescription collection
  1130. *
  1131. * @param array filter FieldDescription collection
  1132. */
  1133. public function getFilterFieldDescriptions()
  1134. {
  1135. $this->buildFilterFieldDescriptions();
  1136. return $this->filterFieldDescriptions;
  1137. }
  1138. /**
  1139. * add an Admin child to the current one
  1140. *
  1141. * @param string $code
  1142. * @param Admin $child
  1143. * @return void
  1144. */
  1145. public function addChild($code, AdminInterface $child)
  1146. {
  1147. $this->children[$code] = $child;
  1148. $child->setCode($code);
  1149. $child->setBaseCodeRoute($this->getCode().'|'.$code);
  1150. $child->setParent($this);
  1151. }
  1152. /**
  1153. * Returns true or false if an Admin child exists for the given $code
  1154. *
  1155. * @param string $code Admin code
  1156. * @return bool True if child exist, false otherwise
  1157. */
  1158. public function hasChild($code)
  1159. {
  1160. return isset($this->children[$code]);
  1161. }
  1162. /**
  1163. * return an collection of admin children
  1164. *
  1165. * @return array list of Admin children
  1166. */
  1167. public function getChildren()
  1168. {
  1169. return $this->children;
  1170. }
  1171. /**
  1172. * return an admin child with the given $code
  1173. *
  1174. * @param string $code
  1175. * @return array|null
  1176. */
  1177. public function getChild($code)
  1178. {
  1179. return $this->hasChild($code) ? $this->children[$code] : null;
  1180. }
  1181. /**
  1182. * set the Parent Admin
  1183. *
  1184. * @param Admin $parent
  1185. * @return void
  1186. */
  1187. public function setParent(AdminInterface $parent)
  1188. {
  1189. $this->parent = $parent;
  1190. }
  1191. /**
  1192. * get the Parent Admin
  1193. *
  1194. * @return Admin|null
  1195. */
  1196. public function getParent()
  1197. {
  1198. return $this->parent;
  1199. }
  1200. /**
  1201. * return true if the Admin class has an Parent Admin defined
  1202. *
  1203. * @return boolean
  1204. */
  1205. public function isChild()
  1206. {
  1207. return $this->parent instanceof AdminInterface;
  1208. }
  1209. /**
  1210. * return true if the admin has children, false otherwise
  1211. *
  1212. * @return bool if the admin has children
  1213. */
  1214. public function hasChildren()
  1215. {
  1216. return count($this->children) > 0;
  1217. }
  1218. /**
  1219. * set the uniqid
  1220. *
  1221. * @param $uniqid
  1222. * @return void
  1223. */
  1224. public function setUniqid($uniqid)
  1225. {
  1226. $this->uniqid = $uniqid;
  1227. }
  1228. /**
  1229. * return the uniqid
  1230. *
  1231. * @return integer
  1232. */
  1233. public function getUniqid()
  1234. {
  1235. return $this->uniqid;
  1236. }
  1237. /**
  1238. * return the classname label
  1239. *
  1240. * @return string the classname label
  1241. */
  1242. public function getClassnameLabel()
  1243. {
  1244. return $this->classnameLabel;
  1245. }
  1246. /**
  1247. * return an array of persistent parameters
  1248. *
  1249. * @return array
  1250. */
  1251. public function getPersistentParameters()
  1252. {
  1253. return array();
  1254. }
  1255. /**
  1256. * generate the breadcrumbs array
  1257. *
  1258. * @param $action
  1259. * @param \Knplabs\MenuBundle\MenuItem|null $menu
  1260. * @return array the breadcrumbs
  1261. */
  1262. public function getBreadcrumbs($action, MenuItem $menu = null)
  1263. {
  1264. $menu = $menu ?: new Menu;
  1265. $child = $menu->addChild(
  1266. $this->trans(sprintf('link_%s_list', $this->getClassnameLabel())),
  1267. $this->generateUrl('list')
  1268. );
  1269. $childAdmin = $this->getCurrentChildAdmin();
  1270. if ($childAdmin) {
  1271. $id = $this->request->get($this->getIdParameter());
  1272. $child = $child->addChild(
  1273. (string) $this->getSubject(),
  1274. $this->generateUrl('edit', array('id' => $id))
  1275. );
  1276. return $childAdmin->getBreadcrumbs($action, $child);
  1277. } elseif ($this->isChild()) {
  1278. if ($action != 'list') {
  1279. $menu = $menu->addChild(
  1280. $this->trans(sprintf('link_%s_list', $this->getClassnameLabel())),
  1281. $this->generateUrl('list')
  1282. );
  1283. }
  1284. $breadcrumbs = $menu->getBreadcrumbsArray(
  1285. $this->trans(sprintf('link_%s_%s', $this->getClassnameLabel(), $action))
  1286. );
  1287. } else if ($action != 'list') {
  1288. $breadcrumbs = $child->getBreadcrumbsArray(
  1289. $this->trans(sprintf('link_%s_%s', $this->getClassnameLabel(), $action))
  1290. );
  1291. } else {
  1292. $breadcrumbs = $child->getBreadcrumbsArray();
  1293. }
  1294. // the generated $breadcrumbs contains an empty element
  1295. array_shift($breadcrumbs);
  1296. return $breadcrumbs;
  1297. }
  1298. /**
  1299. * set the current child status
  1300. *
  1301. * @param boolean $currentChild
  1302. * @return void
  1303. */
  1304. public function setCurrentChild($currentChild)
  1305. {
  1306. $this->currentChild = $currentChild;
  1307. }
  1308. /**
  1309. * return the current child status
  1310. *
  1311. * @return bool
  1312. */
  1313. public function getCurrentChild()
  1314. {
  1315. return $this->currentChild;
  1316. }
  1317. /**
  1318. * return the current child admin instance
  1319. *
  1320. * @return Admin|null the current child admin instance
  1321. */
  1322. public function getCurrentChildAdmin()
  1323. {
  1324. foreach ($this->children as $children) {
  1325. if ($children->getCurrentChild()) {
  1326. return $children;
  1327. }
  1328. }
  1329. return null;
  1330. }
  1331. /**
  1332. * translate a message id
  1333. *
  1334. * @param string $id
  1335. * @param array $parameters
  1336. * @param null $domain
  1337. * @param null $locale
  1338. * @return string the translated string
  1339. */
  1340. public function trans($id, array $parameters = array(), $domain = null, $locale = null)
  1341. {
  1342. $domain = $domain ?: $this->translationDomain;
  1343. if (!$this->translator) {
  1344. return $id;
  1345. }
  1346. return $this->translator->trans($id, $parameters, $domain, $locale);
  1347. }
  1348. /**
  1349. * set the translation domain
  1350. *
  1351. * @param string $translationDomain the translation domain
  1352. * @return void
  1353. */
  1354. public function setTranslationDomain($translationDomain)
  1355. {
  1356. $this->translationDomain = $translationDomain;
  1357. }
  1358. /**
  1359. * return the translation domain
  1360. *
  1361. * @return string the translation domain
  1362. */
  1363. public function getTranslationDomain()
  1364. {
  1365. return $this->translationDomain;
  1366. }
  1367. /**
  1368. *
  1369. */
  1370. public function setTranslator(TranslatorInterface $translator)
  1371. {
  1372. $this->translator = $translator;
  1373. }
  1374. /**
  1375. *
  1376. */
  1377. public function getTranslator()
  1378. {
  1379. return $this->translator;
  1380. }
  1381. /**
  1382. * @param \Symfony\Component\HttpFoundation\Request $request
  1383. * @return void
  1384. */
  1385. public function setRequest(Request $request)
  1386. {
  1387. $this->request = $request;
  1388. if ($request->get('uniqid')) {
  1389. $this->setUniqid($request->get('uniqid'));
  1390. }
  1391. }
  1392. /**
  1393. * @return Symfony\Component\HttpFoundation\Request
  1394. */
  1395. public function getRequest()
  1396. {
  1397. return $this->request;
  1398. }
  1399. /**
  1400. * @param \Sonata\AdminBundle\Builder\FormBuilderInterface $formBuilder
  1401. * @return void
  1402. */
  1403. public function setFormBuilder(FormBuilderInterface $formBuilder)
  1404. {
  1405. $this->formBuilder = $formBuilder;
  1406. }
  1407. /**
  1408. * @return Sonata\AdminBundle\Builder\FormBuilderInterface
  1409. */
  1410. public function getFormBuilder()
  1411. {
  1412. return $this->formBuilder;
  1413. }
  1414. /**
  1415. * @param \Sonata\AdminBundle\Builder\DatagridBuilderInterface $datagridBuilder
  1416. * @return void
  1417. */
  1418. public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder)
  1419. {
  1420. $this->datagridBuilder = $datagridBuilder;
  1421. }
  1422. /**
  1423. * @return Sonata\AdminBundle\Builder\DatagridBuilderInterface
  1424. */
  1425. public function getDatagridBuilder()
  1426. {
  1427. return $this->datagridBuilder;
  1428. }
  1429. /**
  1430. * @param \Sonata\AdminBundle\Builder\ListBuilderInterface $listBuilder
  1431. * @return void
  1432. */
  1433. public function setListBuilder(ListBuilderInterface $listBuilder)
  1434. {
  1435. $this->listBuilder = $listBuilder;
  1436. }
  1437. /**
  1438. * @return Sonata\AdminBundle\Builder\ListBuilderInterface
  1439. */
  1440. public function getListBuilder()
  1441. {
  1442. return $this->listBuilder;
  1443. }
  1444. /**
  1445. * @param Pool $configurationPool
  1446. * @return void
  1447. */
  1448. public function setConfigurationPool(Pool $configurationPool)
  1449. {
  1450. $this->configurationPool = $configurationPool;
  1451. }
  1452. /**
  1453. * @return Pool
  1454. */
  1455. public function getConfigurationPool()
  1456. {
  1457. return $this->configurationPool;
  1458. }
  1459. /**
  1460. * @param \Symfony\Component\Routing\RouterInterface $router
  1461. * @return void
  1462. */
  1463. public function setRouter(RouterInterface $router)
  1464. {
  1465. $this->router = $router;
  1466. }
  1467. /**
  1468. * @return Symfony\Component\Routing\RouterInterface
  1469. */
  1470. public function getRouter()
  1471. {
  1472. return $this->router;
  1473. }
  1474. /**
  1475. * @param $modelManager
  1476. * @return void
  1477. */
  1478. public function setModelManager($modelManager)
  1479. {
  1480. $this->modelManager = $modelManager;
  1481. }
  1482. /**
  1483. * @return object
  1484. */
  1485. public function getModelManager()
  1486. {
  1487. return $this->modelManager;
  1488. }
  1489. public function setCode($code)
  1490. {
  1491. $this->code = $code;
  1492. }
  1493. public function getCode()
  1494. {
  1495. return $this->code;
  1496. }
  1497. public function setBaseCodeRoute($baseCodeRoute)
  1498. {
  1499. $this->baseCodeRoute = $baseCodeRoute;
  1500. }
  1501. public function getBaseCodeRoute()
  1502. {
  1503. return $this->baseCodeRoute;
  1504. }
  1505. }