AdminInterface.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project 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\Builder\DatagridBuilderInterface;
  12. use Sonata\AdminBundle\Builder\FormContractorInterface;
  13. use Sonata\AdminBundle\Builder\ListBuilderInterface;
  14. use Sonata\AdminBundle\Builder\RouteBuilderInterface;
  15. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  16. use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
  17. use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;
  18. use Sonata\CoreBundle\Model\Metadata;
  19. use Sonata\CoreBundle\Validator\ErrorElement;
  20. use Symfony\Component\Form\Form;
  21. use Symfony\Component\Form\FormBuilderInterface;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\Translation\TranslatorInterface;
  24. use Symfony\Component\Validator\Validator\ValidatorInterface;
  25. use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
  26. /**
  27. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  28. */
  29. interface AdminInterface extends AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface
  30. {
  31. /**
  32. * @param FormContractorInterface $formContractor
  33. */
  34. public function setFormContractor(FormContractorInterface $formContractor);
  35. /**
  36. * Set ListBuilder.
  37. *
  38. * @param ListBuilderInterface $listBuilder
  39. */
  40. public function setListBuilder(ListBuilderInterface $listBuilder);
  41. /**
  42. * Get ListBuilder.
  43. *
  44. * @return ListBuilderInterface
  45. */
  46. public function getListBuilder();
  47. /**
  48. * Set DatagridBuilder.
  49. *
  50. * @param DatagridBuilderInterface $datagridBuilder
  51. */
  52. public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder);
  53. /**
  54. * Get DatagridBuilder.
  55. *
  56. * @return DatagridBuilderInterface
  57. */
  58. public function getDatagridBuilder();
  59. /**
  60. * Set translator.
  61. *
  62. * @param TranslatorInterface $translator
  63. */
  64. public function setTranslator(TranslatorInterface $translator);
  65. /**
  66. * Get translator.
  67. *
  68. * @return TranslatorInterface
  69. */
  70. public function getTranslator();
  71. /**
  72. * @param Request $request
  73. */
  74. public function setRequest(Request $request);
  75. /**
  76. * @param Pool $pool
  77. */
  78. public function setConfigurationPool(Pool $pool);
  79. /**
  80. * Returns subjectClass/class/subclass name managed
  81. * - subclass name if subclass parameter is defined
  82. * - subject class name if subject is defined
  83. * - class name if not.
  84. *
  85. * @return string
  86. */
  87. public function getClass();
  88. /**
  89. * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  90. */
  91. public function attachAdminClass(FieldDescriptionInterface $fieldDescription);
  92. /**
  93. * @return \Sonata\AdminBundle\Datagrid\DatagridInterface
  94. */
  95. public function getDatagrid();
  96. /**
  97. * Set base controller name.
  98. *
  99. * @param string $baseControllerName
  100. */
  101. public function setBaseControllerName($baseControllerName);
  102. /**
  103. * Get base controller name.
  104. *
  105. * @return string
  106. */
  107. public function getBaseControllerName();
  108. /**
  109. * @return \Sonata\AdminBundle\Model\ModelManagerInterface
  110. */
  111. public function getModelManager();
  112. /**
  113. * @return string the manager type of the admin
  114. */
  115. public function getManagerType();
  116. /**
  117. * @param string $context NEXT_MAJOR: remove this argument
  118. *
  119. * @return ProxyQueryInterface
  120. */
  121. public function createQuery($context = 'list');
  122. /**
  123. * @return FormBuilderInterface the form builder
  124. */
  125. public function getFormBuilder();
  126. /**
  127. * Returns a form depend on the given $object.
  128. *
  129. * @return Form
  130. */
  131. public function getForm();
  132. /**
  133. * @return Request
  134. *
  135. * @throws \RuntimeException if no request is set
  136. */
  137. public function getRequest();
  138. /**
  139. * @return bool true if a request object is linked to this Admin, false
  140. * otherwise
  141. */
  142. public function hasRequest();
  143. /**
  144. * @return string
  145. */
  146. public function getCode();
  147. /**
  148. * @return string
  149. */
  150. public function getBaseCodeRoute();
  151. /**
  152. * Return the roles and permissions per role
  153. * - different permissions per role for the acl handler
  154. * - one permission that has the same name as the role for the role handler
  155. * This should be used by experimented users.
  156. *
  157. * @return array [role] => array([permission], [permission])
  158. */
  159. public function getSecurityInformation();
  160. /**
  161. * @param FieldDescriptionInterface $parentFieldDescription
  162. */
  163. public function setParentFieldDescription(FieldDescriptionInterface $parentFieldDescription);
  164. /**
  165. * Get parent field description.
  166. *
  167. * @return FieldDescriptionInterface The parent field description
  168. */
  169. public function getParentFieldDescription();
  170. /**
  171. * Returns true if the Admin is linked to a parent FieldDescription.
  172. *
  173. * @return bool
  174. */
  175. public function hasParentFieldDescription();
  176. /**
  177. * translate a message id.
  178. *
  179. * NEXT_MAJOR: remove this method
  180. *
  181. * @param string $id
  182. * @param array $parameters
  183. * @param null $domain
  184. * @param null $locale
  185. *
  186. * @return string the translated string
  187. *
  188. * @deprecated since 3.9, to be removed in 4.0
  189. */
  190. public function trans($id, array $parameters = array(), $domain = null, $locale = null);
  191. /**
  192. * Returns the parameter representing request id, ie: id or childId.
  193. *
  194. * @return string
  195. */
  196. public function getIdParameter();
  197. /**
  198. * Returns true if the route $name is available.
  199. *
  200. * @param string $name
  201. *
  202. * @return bool
  203. */
  204. public function hasRoute($name);
  205. /**
  206. * Check the current request is given route or not.
  207. *
  208. * TODO: uncomment this method before releasing 4.0
  209. *
  210. * ```
  211. * $this->isCurrentRoute('create'); // is create page?
  212. * $this->isCurrentRoute('edit', 'some.admin.code'); // is some.admin.code admin's edit page?
  213. * ```
  214. *
  215. * @param string $name
  216. * @param string $adminCode
  217. *
  218. * @return bool
  219. */
  220. // public function isCurrentRoute($name, $adminCode = null);
  221. /**
  222. * @param SecurityHandlerInterface $securityHandler
  223. */
  224. public function setSecurityHandler(SecurityHandlerInterface $securityHandler);
  225. /**
  226. * @return SecurityHandlerInterface|null
  227. */
  228. public function getSecurityHandler();
  229. /**
  230. * @param string $name
  231. * @param object|null $object
  232. *
  233. * @return bool
  234. */
  235. public function isGranted($name, $object = null);
  236. /**
  237. * @param mixed $entity
  238. *
  239. * @return string a string representation of the identifiers for this instance
  240. */
  241. public function getNormalizedIdentifier($entity);
  242. /**
  243. * Shorthand method for templating.
  244. *
  245. * @param object $entity
  246. *
  247. * @return mixed
  248. */
  249. public function id($entity);
  250. /**
  251. * @param ValidatorInterface|LegacyValidatorInterface $validator
  252. */
  253. public function setValidator($validator);
  254. /**
  255. * @return ValidatorInterface|LegacyValidatorInterface
  256. */
  257. public function getValidator();
  258. /**
  259. * @return array
  260. */
  261. public function getShow();
  262. /**
  263. * @param array $formTheme
  264. */
  265. public function setFormTheme(array $formTheme);
  266. /**
  267. * @return array
  268. */
  269. public function getFormTheme();
  270. /**
  271. * @param array $filterTheme
  272. */
  273. public function setFilterTheme(array $filterTheme);
  274. /**
  275. * @return array
  276. */
  277. public function getFilterTheme();
  278. /**
  279. * @param AdminExtensionInterface $extension
  280. */
  281. public function addExtension(AdminExtensionInterface $extension);
  282. /**
  283. * Returns an array of extension related to the current Admin.
  284. *
  285. * @return AdminExtensionInterface[]
  286. */
  287. public function getExtensions();
  288. /**
  289. * @param RouteBuilderInterface $routeBuilder
  290. */
  291. public function setRouteBuilder(RouteBuilderInterface $routeBuilder);
  292. /**
  293. * @return RouteBuilderInterface
  294. */
  295. public function getRouteBuilder();
  296. /**
  297. * @param mixed $object
  298. *
  299. * @return string
  300. */
  301. public function toString($object);
  302. /**
  303. * @param LabelTranslatorStrategyInterface $labelTranslatorStrategy
  304. */
  305. public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy);
  306. /**
  307. * @return LabelTranslatorStrategyInterface
  308. */
  309. public function getLabelTranslatorStrategy();
  310. /**
  311. * Returning true will enable preview mode for
  312. * the target entity and show a preview button
  313. * when editing/creating an entity.
  314. *
  315. * @return bool
  316. */
  317. public function supportsPreviewMode();
  318. /**
  319. * @return mixed a new object instance
  320. */
  321. public function getNewInstance();
  322. /**
  323. * @param string $uniqId
  324. */
  325. public function setUniqid($uniqId);
  326. /**
  327. * Returns the uniqid.
  328. *
  329. * @return int
  330. */
  331. public function getUniqid();
  332. /**
  333. * @param mixed $id
  334. *
  335. * @return mixed
  336. */
  337. public function getObject($id);
  338. /**
  339. * @param object $subject
  340. */
  341. public function setSubject($subject);
  342. /**
  343. * @return mixed
  344. */
  345. public function getSubject();
  346. /**
  347. * Returns a list FieldDescription.
  348. *
  349. * @param string $name
  350. *
  351. * @return FieldDescriptionInterface
  352. */
  353. public function getListFieldDescription($name);
  354. /**
  355. * Returns true if the list FieldDescription exists.
  356. *
  357. * @param string $name
  358. *
  359. * @return bool
  360. */
  361. public function hasListFieldDescription($name);
  362. /**
  363. * Returns the collection of list FieldDescriptions.
  364. *
  365. * @return array
  366. */
  367. public function getListFieldDescriptions();
  368. /**
  369. * Returns the array of allowed export formats.
  370. *
  371. * @return array
  372. */
  373. public function getExportFormats();
  374. /**
  375. * Returns SourceIterator.
  376. *
  377. * @return \Exporter\Source\SourceIteratorInterface
  378. */
  379. public function getDataSourceIterator();
  380. public function configure();
  381. /**
  382. * Call before the batch action, allow you to alter the query and the idx.
  383. *
  384. * @param string $actionName
  385. * @param ProxyQueryInterface $query
  386. * @param array $idx
  387. * @param bool $allElements
  388. */
  389. public function preBatchAction($actionName, ProxyQueryInterface $query, array &$idx, $allElements);
  390. /**
  391. * Return array of filter parameters.
  392. *
  393. * @return array
  394. */
  395. public function getFilterParameters();
  396. /**
  397. * Return true if the Admin is related to a subject.
  398. *
  399. * @return bool
  400. */
  401. public function hasSubject();
  402. /**
  403. * NEXT_MAJOR: remove this method.
  404. *
  405. * @param ErrorElement $errorElement
  406. * @param mixed $object
  407. *
  408. * @deprecated this feature cannot be stable, use a custom validator,
  409. * the feature will be removed with Symfony 2.2
  410. */
  411. public function validate(ErrorElement $errorElement, $object);
  412. /**
  413. * @param string $context
  414. *
  415. * @return bool
  416. */
  417. public function showIn($context);
  418. /**
  419. * Add object security, fe. make the current user owner of the object.
  420. *
  421. * @param mixed $object
  422. */
  423. public function createObjectSecurity($object);
  424. /**
  425. * @return AdminInterface
  426. */
  427. public function getParent();
  428. /**
  429. * @param AdminInterface $admin
  430. */
  431. public function setParent(AdminInterface $admin);
  432. /**
  433. * Returns true if the Admin class has an Parent Admin defined.
  434. *
  435. * @return bool
  436. */
  437. public function isChild();
  438. /**
  439. * Returns template.
  440. *
  441. * @param string $name
  442. *
  443. * @return null|string
  444. */
  445. public function getTemplate($name);
  446. /**
  447. * Set the translation domain.
  448. *
  449. * @param string $translationDomain the translation domain
  450. */
  451. public function setTranslationDomain($translationDomain);
  452. /**
  453. * Returns the translation domain.
  454. *
  455. * @return string the translation domain
  456. */
  457. public function getTranslationDomain();
  458. /**
  459. * Return the form groups.
  460. *
  461. * @return array
  462. */
  463. public function getFormGroups();
  464. /**
  465. * Set the form groups.
  466. *
  467. * @param array $formGroups
  468. */
  469. public function setFormGroups(array $formGroups);
  470. public function getFormTabs();
  471. public function setFormTabs(array $formTabs);
  472. public function getShowTabs();
  473. public function setShowTabs(array $showTabs);
  474. /**
  475. * Remove a form group field.
  476. *
  477. * @param string $key
  478. */
  479. public function removeFieldFromFormGroup($key);
  480. /**
  481. * Returns the show groups.
  482. *
  483. * @return array
  484. */
  485. public function getShowGroups();
  486. /**
  487. * Set the show groups.
  488. *
  489. * @param array $showGroups
  490. */
  491. public function setShowGroups(array $showGroups);
  492. /**
  493. * Reorder items in showGroup.
  494. *
  495. * @param string $group
  496. * @param array $keys
  497. */
  498. public function reorderShowGroup($group, array $keys);
  499. /**
  500. * add a FieldDescription.
  501. *
  502. * @param string $name
  503. * @param FieldDescriptionInterface $fieldDescription
  504. */
  505. public function addFormFieldDescription($name, FieldDescriptionInterface $fieldDescription);
  506. /**
  507. * Remove a FieldDescription.
  508. *
  509. * @param string $name
  510. */
  511. public function removeFormFieldDescription($name);
  512. /**
  513. * Returns true if this admin uses ACL.
  514. *
  515. * @return bool
  516. */
  517. public function isAclEnabled();
  518. /**
  519. * Sets the list of supported sub classes.
  520. *
  521. * @param array $subClasses the list of sub classes
  522. */
  523. public function setSubClasses(array $subClasses);
  524. /**
  525. * Returns true if the admin has the sub classes.
  526. *
  527. * @param string $name The name of the sub class
  528. *
  529. * @return bool
  530. */
  531. public function hasSubClass($name);
  532. /**
  533. * Returns true if a subclass is currently active.
  534. *
  535. * @return bool
  536. */
  537. public function hasActiveSubClass();
  538. /**
  539. * Returns the currently active sub class.
  540. *
  541. * @return string the active sub class
  542. */
  543. public function getActiveSubClass();
  544. /**
  545. * Returns the currently active sub class code.
  546. *
  547. * @return string the code for active sub class
  548. */
  549. public function getActiveSubclassCode();
  550. /**
  551. * Returns the list of batchs actions.
  552. *
  553. * @return array the list of batchs actions
  554. */
  555. public function getBatchActions();
  556. /**
  557. * Returns Admin`s label.
  558. *
  559. * @return string
  560. */
  561. public function getLabel();
  562. /**
  563. * Returns an array of persistent parameters.
  564. *
  565. * @return array
  566. */
  567. public function getPersistentParameters();
  568. /**
  569. * NEXT_MAJOR: remove this signature
  570. * Get breadcrumbs for $action.
  571. *
  572. * @param string $action
  573. *
  574. * @return mixed array|Traversable
  575. */
  576. public function getBreadcrumbs($action);
  577. /**
  578. * Set the current child status.
  579. *
  580. * @param bool $currentChild
  581. */
  582. public function setCurrentChild($currentChild);
  583. /**
  584. * Returns the current child status.
  585. *
  586. * @return bool
  587. */
  588. public function getCurrentChild();
  589. /**
  590. * Get translation label using the current TranslationStrategy.
  591. *
  592. * @param string $label
  593. * @param string $context
  594. * @param string $type
  595. *
  596. * @return string
  597. */
  598. public function getTranslationLabel($label, $context = '', $type = '');
  599. /**
  600. * @param $object
  601. *
  602. * @return Metadata
  603. */
  604. public function getObjectMetadata($object);
  605. /**
  606. * @return array
  607. */
  608. public function getListModes();
  609. /**
  610. * @param string $mode
  611. */
  612. public function setListMode($mode);
  613. /**
  614. * return the list mode.
  615. *
  616. * @return string
  617. */
  618. public function getListMode();
  619. /*
  620. * Configure buttons for an action
  621. *
  622. * @param string $action
  623. * @param object $object
  624. *
  625. */
  626. // public function configureActionButtons($action, $object = null);
  627. //TODO: uncomment this method for 4.0
  628. /*
  629. * Returns the result link for an object.
  630. *
  631. * @param mixed $object
  632. *
  633. * @return string|null
  634. */
  635. //public function getSearchResultLink($object)
  636. // TODO: uncomment this method in 4.0
  637. // /**
  638. // * Setting to true will enable mosaic button for the admin screen.
  639. // * Setting to false will hide mosaic button for the admin screen.
  640. // *
  641. // * @param bool $isShown
  642. // */
  643. // public function showMosaicButton($isShown);
  644. /*
  645. * Checks if a filter type is set to a default value
  646. *
  647. * @param string $name
  648. *
  649. * @return bool
  650. */
  651. // NEXT_MAJOR: uncomment this method in 4.0
  652. // public function isDefaultFilter($name);
  653. }