AdminInterface.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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 Sonata\AdminBundle\Admin\Pool;
  12. use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
  13. use Sonata\AdminBundle\Builder\FormContractorInterface;
  14. use Sonata\AdminBundle\Builder\ListBuilderInterface;
  15. use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
  16. use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
  17. use Sonata\AdminBundle\Builder\RouteBuilderInterface;
  18. use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;
  19. use Sonata\AdminBundle\Validator\ErrorElement;
  20. use Sonata\AdminBundle\Route\RouteGeneratorInterface;
  21. use Knp\Menu\FactoryInterface as MenuFactoryInterface;
  22. use Symfony\Component\Validator\ValidatorInterface;
  23. use Symfony\Component\Translation\TranslatorInterface;
  24. use Symfony\Component\HttpFoundation\Request;
  25. interface AdminInterface
  26. {
  27. /**
  28. * @param \Sonata\AdminBundle\Builder\FormContractorInterface $formContractor
  29. *
  30. * @return void
  31. */
  32. public function setFormContractor(FormContractorInterface $formContractor);
  33. /**
  34. * @param ListBuilderInterface $listBuilder
  35. *
  36. * @return void
  37. */
  38. public function setListBuilder(ListBuilderInterface $listBuilder);
  39. /**
  40. * @param \Sonata\AdminBundle\Builder\DatagridBuilderInterface $datagridBuilder
  41. *
  42. * @return void
  43. */
  44. public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder);
  45. /**
  46. * @param \Symfony\Component\Translation\TranslatorInterface $translator
  47. *
  48. * @return void
  49. */
  50. public function setTranslator(TranslatorInterface $translator);
  51. /**
  52. * @param \Symfony\Component\HttpFoundation\Request $request
  53. *
  54. * @return void
  55. */
  56. public function setRequest(Request $request);
  57. /**
  58. * @param Pool $pool
  59. *
  60. * @return void
  61. */
  62. public function setConfigurationPool(Pool $pool);
  63. /**
  64. * @param \Sonata\AdminBundle\Route\RouteGeneratorInterface $routeGenerator
  65. *
  66. * @return void
  67. */
  68. public function setRouteGenerator(RouteGeneratorInterface $routeGenerator);
  69. /**
  70. * Returns subjectClass/class/subclass name managed
  71. * - subclass name if subclass parameter is defined
  72. * - subject class name if subject is defined
  73. * - class name if not
  74. *
  75. * @return string
  76. */
  77. public function getClass();
  78. /**
  79. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  80. *
  81. * @return void
  82. */
  83. public function attachAdminClass(FieldDescriptionInterface $fieldDescription);
  84. /**
  85. * @return \Sonata\AdminBundle\Datagrid\DatagridInterface
  86. */
  87. public function getDatagrid();
  88. /**
  89. * Generates the object url with the given $name
  90. *
  91. * @param string $name
  92. * @param mixed $object
  93. * @param array $parameters
  94. * @param boolean $absolute
  95. *
  96. * @return string return a complete url
  97. */
  98. public function generateObjectUrl($name, $object, array $parameters = array(), $absolute = false);
  99. /**
  100. * Generates an url for the given parameters
  101. *
  102. * @param string $name
  103. * @param array $parameters
  104. * @param bool $absolute
  105. *
  106. * @return string return a complete url
  107. */
  108. public function generateUrl($name, array $parameters = array(), $absolute = false);
  109. /**
  110. * @return \Sonata\AdminBundle\Model\ModelManagerInterface;
  111. */
  112. public function getModelManager();
  113. /**
  114. * @return string the manager type of the admin
  115. */
  116. public function getManagerType();
  117. /**
  118. * @param string $context
  119. *
  120. * @return \Sonata\AdminBundle\Datagrid\ProxyQueryInterface
  121. */
  122. public function createQuery($context = 'list');
  123. /**
  124. * @return \Symfony\Component\Form\FormBuilder the form builder
  125. */
  126. public function getFormBuilder();
  127. /**
  128. * @param string $name
  129. *
  130. * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
  131. */
  132. public function getFormFieldDescription($name);
  133. /**
  134. * @return \Symfony\Component\HttpFoundation\Request
  135. *
  136. * @throws \RuntimeException if no request is set.
  137. */
  138. public function getRequest();
  139. /**
  140. * @return boolean true if a request object is linked to this Admin, false
  141. * otherwise.
  142. */
  143. public function hasRequest();
  144. /**
  145. *
  146. * @return string
  147. */
  148. public function getCode();
  149. /**
  150. * Return the roles and permissions per role
  151. * - different permissions per role for the acl handler
  152. * - one permission that has the same name as the role for the role handler
  153. * This should be used by experimented users
  154. *
  155. * @return array [role] => array([permission], [permission])
  156. */
  157. public function getSecurityInformation();
  158. /**
  159. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $parentFieldDescription
  160. *
  161. * @return void
  162. */
  163. public function setParentFieldDescription(FieldDescriptionInterface $parentFieldDescription);
  164. /**
  165. * translate a message id
  166. *
  167. * @param string $id
  168. * @param array $parameters
  169. * @param null $domain
  170. * @param null $locale
  171. *
  172. * @return string the translated string
  173. */
  174. public function trans($id, array $parameters = array(), $domain = null, $locale = null);
  175. /**
  176. * Return the parameter name used to represente the id in the url
  177. *
  178. * @return string
  179. */
  180. public function getRouterIdParameter();
  181. /**
  182. * add a FieldDescription
  183. *
  184. * @param string $name
  185. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  186. *
  187. * @return void
  188. */
  189. public function addShowFieldDescription($name, FieldDescriptionInterface $fieldDescription);
  190. /**
  191. * Remove a ShowFieldDescription
  192. *
  193. * @param string $name
  194. */
  195. public function removeShowFieldDescription($name);
  196. /**
  197. * add a list FieldDescription
  198. *
  199. * @param string $name
  200. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  201. *
  202. * @return void
  203. */
  204. public function addListFieldDescription($name, FieldDescriptionInterface $fieldDescription);
  205. /**
  206. * add a filter FieldDescription
  207. *
  208. * @param string $name
  209. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  210. *
  211. * @return void
  212. */
  213. public function addFilterFieldDescription($name, FieldDescriptionInterface $fieldDescription);
  214. /**
  215. * Returns a list depend on the given $object
  216. *
  217. * @return \Sonata\AdminBundle\Admin\FieldDescriptionCollection
  218. */
  219. public function getList();
  220. /**
  221. * @param \Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface $securityHandler
  222. *
  223. * @return void
  224. */
  225. public function setSecurityHandler(SecurityHandlerInterface $securityHandler);
  226. /**
  227. * @return \Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface|null
  228. */
  229. public function getSecurityHandler();
  230. /**
  231. * @param string $name
  232. * @param object|null $object
  233. *
  234. * @return boolean
  235. */
  236. public function isGranted($name, $object = null);
  237. /**
  238. * @param mixed $entity
  239. */
  240. public function getUrlsafeIdentifier($entity);
  241. /**
  242. * @param mixed $entity
  243. */
  244. public function getNormalizedIdentifier($entity);
  245. /**
  246. * Shorthand method for templating
  247. *
  248. * @param object $entity
  249. *
  250. * @return mixed
  251. */
  252. public function id($entity);
  253. /**
  254. * @param \Symfony\Component\Validator\ValidatorInterface $validator
  255. *
  256. * @return void
  257. */
  258. public function setValidator(ValidatorInterface $validator);
  259. /**
  260. * @return \Symfony\Component\Validator\ValidatorInterface
  261. */
  262. public function getValidator();
  263. /**
  264. * @return array
  265. */
  266. public function getShow();
  267. /**
  268. * @param array $formTheme
  269. *
  270. * @return void
  271. */
  272. public function setFormTheme(array $formTheme);
  273. /**
  274. * @return array
  275. */
  276. public function getFormTheme();
  277. /**
  278. * @param array $filterTheme
  279. *
  280. * @return void
  281. */
  282. public function setFilterTheme(array $filterTheme);
  283. /**
  284. * @return array
  285. */
  286. public function getFilterTheme();
  287. /**
  288. * @param AdminExtensionInterface $extension
  289. *
  290. * @return void
  291. */
  292. public function addExtension(AdminExtensionInterface $extension);
  293. /**
  294. * Returns an array of extension related to the current Admin
  295. *
  296. * @return AdminExtensionInterface[]
  297. */
  298. public function getExtensions();
  299. /**
  300. * @param \Knp\Menu\FactoryInterface $menuFactory
  301. *
  302. * @return void
  303. */
  304. public function setMenuFactory(MenuFactoryInterface $menuFactory);
  305. /**
  306. * @return \Knp\Menu\FactoryInterface
  307. */
  308. public function getMenuFactory();
  309. /**
  310. * @param \Sonata\AdminBundle\Builder\RouteBuilderInterface $routeBuilder
  311. */
  312. public function setRouteBuilder(RouteBuilderInterface $routeBuilder);
  313. /**
  314. * @return \Sonata\AdminBundle\Builder\RouteBuilderInterface
  315. */
  316. public function getRouteBuilder();
  317. /**
  318. * @param mixed $object
  319. *
  320. * @return string
  321. */
  322. public function toString($object);
  323. /**
  324. * @param \Sonata\Adminbundle\Translator\LabelTranslatorStrategyInterface $labelTranslatorStrategy
  325. */
  326. public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy);
  327. /**
  328. * @return \Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface
  329. */
  330. public function getLabelTranslatorStrategy();
  331. /**
  332. * add an Admin child to the current one
  333. *
  334. * @param \Sonata\AdminBundle\Admin\AdminInterface $child
  335. *
  336. * @return void
  337. */
  338. public function addChild(AdminInterface $child);
  339. /**
  340. * Returns true or false if an Admin child exists for the given $code
  341. *
  342. * @param string $code Admin code
  343. *
  344. * @return bool True if child exist, false otherwise
  345. */
  346. public function hasChild($code);
  347. /**
  348. * Returns an collection of admin children
  349. *
  350. * @return array list of Admin children
  351. */
  352. public function getChildren();
  353. /**
  354. * Returns an admin child with the given $code
  355. *
  356. * @param string $code
  357. *
  358. * @return array|null
  359. */
  360. public function getChild($code);
  361. /**
  362. * @return mixed a new object instance
  363. */
  364. public function getNewInstance();
  365. /**
  366. * @param string $uniqId
  367. *
  368. * @return mixed
  369. */
  370. public function setUniqid($uniqId);
  371. /**
  372. * @param mixed $id
  373. *
  374. * @return mixed
  375. */
  376. public function getObject($id);
  377. /**
  378. * @param string $subject
  379. *
  380. * @return mixed
  381. */
  382. public function setSubject($subject);
  383. /**
  384. * @return mixed
  385. */
  386. public function getSubject();
  387. /**
  388. * Returns a list FieldDescription
  389. *
  390. * @param string $name
  391. *
  392. * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
  393. */
  394. public function getListFieldDescription($name);
  395. /**
  396. * @return void
  397. */
  398. public function configure();
  399. /**
  400. * @param mixed $object
  401. *
  402. * @return mixed
  403. */
  404. public function update($object);
  405. /**
  406. * @param mixed $object
  407. *
  408. * @return mixed
  409. */
  410. public function create($object);
  411. /**
  412. * @param mixed $object
  413. *
  414. * @return mixed
  415. */
  416. public function delete($object);
  417. /**
  418. * @param mixed $object
  419. *
  420. * @return mixed
  421. */
  422. public function preUpdate($object);
  423. /**
  424. * @param mixed $object
  425. *
  426. * @return mixed
  427. */
  428. public function postUpdate($object);
  429. /**
  430. * @param mixed $object
  431. *
  432. * @return mixed
  433. */
  434. public function prePersist($object);
  435. /**
  436. * @param mixed $object
  437. *
  438. * @return mixed
  439. */
  440. public function postPersist($object);
  441. /**
  442. * @param mixed $object
  443. *
  444. * @return mixed
  445. */
  446. public function preRemove($object);
  447. /**
  448. * @param mixed $object
  449. *
  450. * @return mixed
  451. */
  452. public function postRemove($object);
  453. /**
  454. * Return true if the Admin is related to a subject
  455. *
  456. * @return boolean
  457. */
  458. public function hasSubject();
  459. /**
  460. *
  461. * @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
  462. * @param mixed $object
  463. *
  464. * @return void
  465. *
  466. * @deprecated this feature cannot be stable, use a custom validator,
  467. * the feature will be removed with Symfony 2.2
  468. */
  469. public function validate(ErrorElement $errorElement, $object);
  470. /**
  471. * @param string $context
  472. *
  473. * @return boolean
  474. */
  475. public function showIn($context);
  476. /**
  477. * Add object security, fe. make the current user owner of the object
  478. *
  479. * @param mixed $object
  480. */
  481. public function createObjectSecurity($object);
  482. /**
  483. * Returns the url defined by the $name
  484. *
  485. * @param string $name
  486. *
  487. * @return \Symfony\Component\Routing\Route
  488. */
  489. public function getRoute($name);
  490. /**
  491. * @return AdminInterface
  492. */
  493. public function getParent();
  494. /**
  495. * @param AdminInterface $admin
  496. *
  497. * @return void
  498. */
  499. public function setParent(AdminInterface $admin);
  500. /**
  501. * @param string $name
  502. *
  503. * @return null|string
  504. */
  505. public function getTemplate($name);
  506. /**
  507. * Set the translation domain
  508. *
  509. * @param string $translationDomain the translation domain
  510. *
  511. * @return void
  512. */
  513. public function setTranslationDomain($translationDomain);
  514. /**
  515. * Returns the translation domain
  516. *
  517. * @return string the translation domain
  518. */
  519. public function getTranslationDomain();
  520. /**
  521. * Return the form groups
  522. *
  523. * @return array
  524. */
  525. public function getFormGroups();
  526. /**
  527. * Set the form groups
  528. *
  529. * @param array $formGroups
  530. */
  531. public function setFormGroups(array $formGroups);
  532. /**
  533. * Returns the show groups
  534. *
  535. * @return array
  536. */
  537. public function getShowGroups();
  538. /**
  539. * Set the show groups
  540. *
  541. * @param array $showGroups
  542. */
  543. public function setShowGroups(array $showGroups);
  544. /**
  545. * Reorder items in showGroup
  546. *
  547. * @param string $group
  548. * @param array $keys
  549. */
  550. public function reorderShowGroup($group, array $keys);
  551. /**
  552. * add a FieldDescription
  553. *
  554. * @param string $name
  555. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  556. *
  557. * @return void
  558. */
  559. public function addFormFieldDescription($name, FieldDescriptionInterface $fieldDescription);
  560. /**
  561. * Returns true if this admin uses ACL
  562. *
  563. * @return boolean
  564. */
  565. public function isAclEnabled();
  566. /**
  567. * Sets the list of supported sub classes
  568. *
  569. * @param array $subClasses the list of sub classes
  570. */
  571. public function setSubClasses(array $subClasses);
  572. /**
  573. * Returns true if the admin has the sub classes
  574. *
  575. * @param string $name The name of the sub class
  576. *
  577. * @return bool
  578. */
  579. public function hasSubClass($name);
  580. /**
  581. * Returns true if a subclass is currently active
  582. *
  583. * @return bool
  584. */
  585. public function hasActiveSubClass();
  586. /**
  587. * Returns the currently active sub class
  588. *
  589. * @return string the active sub class
  590. */
  591. public function getActiveSubClass();
  592. /**
  593. * Returns the currently active sub class code
  594. *
  595. * @return string the code for active sub class
  596. */
  597. public function getActiveSubclassCode();
  598. /**
  599. * Returns Admin`s label
  600. *
  601. * @return string
  602. */
  603. public function getLabel();
  604. }