AdminInterface.php 14 KB

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