AdminInterface.php 18 KB

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