AdminInterface.php 19 KB

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