AdminInterface.php 18 KB

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