Configuration.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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\UserBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  12. use Symfony\Component\Config\Definition\ConfigurationInterface;
  13. /**
  14. * This is the class that validates and merges configuration from your app/config files.
  15. *
  16. * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
  17. */
  18. class Configuration implements ConfigurationInterface
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function getConfigTreeBuilder()
  24. {
  25. $treeBuilder = new TreeBuilder();
  26. $rootNode = $treeBuilder->root('sonata_user');
  27. $supportedManagerTypes = array('orm', 'mongodb');
  28. $rootNode
  29. ->children()
  30. ->booleanNode('security_acl')->defaultFalse()->end()
  31. ->arrayNode('table')
  32. ->addDefaultsIfNotSet()
  33. ->children()
  34. ->scalarNode('user_group')->defaultValue('fos_user_user_group')->end()
  35. ->end()
  36. ->end()
  37. ->scalarNode('impersonating_route')->end()
  38. ->arrayNode('impersonating')
  39. ->children()
  40. ->scalarNode('route')->defaultFalse()->end()
  41. ->arrayNode('parameters')
  42. ->useAttributeAsKey('id')
  43. ->prototype('scalar')->end()
  44. ->end()
  45. ->end()
  46. ->end()
  47. ->arrayNode('google_authenticator')
  48. ->addDefaultsIfNotSet()
  49. ->children()
  50. ->scalarNode('server')->cannotBeEmpty()->end()
  51. ->scalarNode('enabled')->defaultFalse()->end()
  52. ->end()
  53. ->end()
  54. ->scalarNode('manager_type')
  55. ->defaultValue('orm')
  56. ->validate()
  57. ->ifNotInArray($supportedManagerTypes)
  58. ->thenInvalid('The manager type %s is not supported. Please choose one of '.json_encode($supportedManagerTypes))
  59. ->end()
  60. ->end()
  61. ->arrayNode('class')
  62. ->children()
  63. ->scalarNode('group')->cannotBeEmpty()->end()
  64. ->scalarNode('user')->cannotBeEmpty()->end()
  65. ->end()
  66. ->end()
  67. ->arrayNode('admin')
  68. ->addDefaultsIfNotSet()
  69. ->children()
  70. ->arrayNode('group')
  71. ->addDefaultsIfNotSet()
  72. ->children()
  73. ->scalarNode('class')->cannotBeEmpty()->end()
  74. ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataAdminBundle:CRUD')->end()
  75. ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataUserBundle')->end()
  76. ->end()
  77. ->end()
  78. ->arrayNode('user')
  79. ->addDefaultsIfNotSet()
  80. ->children()
  81. ->scalarNode('class')->cannotBeEmpty()->end()
  82. ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataAdminBundle:CRUD')->end()
  83. ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataUserBundle')->end()
  84. ->end()
  85. ->end()
  86. ->end()
  87. ->end()
  88. // Original code from the FOS User Bundle
  89. ->arrayNode('profile')
  90. ->addDefaultsIfNotSet()
  91. ->canBeUnset()
  92. ->children()
  93. ->scalarNode('default_avatar')->defaultValue('bundles/sonatauser/default_avatar.png')->end()
  94. ->arrayNode('dashboard')
  95. ->addDefaultsIfNotSet()
  96. ->fixXmlConfig('group')
  97. ->fixXmlConfig('block')
  98. ->children()
  99. ->arrayNode('groups')
  100. ->useAttributeAsKey('id')
  101. ->prototype('array')
  102. ->fixXmlConfig('item')
  103. ->fixXmlConfig('item_add')
  104. ->children()
  105. ->scalarNode('label')->end()
  106. ->scalarNode('label_catalogue')->end()
  107. ->arrayNode('items')
  108. ->prototype('scalar')->end()
  109. ->end()
  110. ->arrayNode('item_adds')
  111. ->prototype('scalar')->end()
  112. ->end()
  113. ->arrayNode('roles')
  114. ->prototype('scalar')->defaultValue(array())->end()
  115. ->end()
  116. ->end()
  117. ->end()
  118. ->end()
  119. ->arrayNode('blocks')
  120. ->defaultValue(array(array('position' => 'left', 'settings' => array('content' => '<h2>Welcome!</h2> This is a sample user profile dashboard, feel free to override it in the configuration!'), 'type' => 'sonata.block.service.text')))
  121. ->prototype('array')
  122. ->fixXmlConfig('setting')
  123. ->children()
  124. ->scalarNode('type')->cannotBeEmpty()->end()
  125. ->arrayNode('settings')
  126. ->useAttributeAsKey('id')
  127. ->prototype('variable')->defaultValue(array())->end()
  128. ->end()
  129. ->scalarNode('position')->defaultValue('right')->end()
  130. ->end()
  131. ->end()
  132. ->end()
  133. ->end()
  134. ->end()
  135. ->arrayNode('form')
  136. ->addDefaultsIfNotSet()
  137. ->children()
  138. ->scalarNode('type')->defaultValue('sonata_user_profile')->end()
  139. ->scalarNode('handler')->defaultValue('sonata.user.profile.form.handler.default')->end()
  140. ->scalarNode('name')->defaultValue('sonata_user_profile_form')->cannotBeEmpty()->end()
  141. ->arrayNode('validation_groups')
  142. ->prototype('scalar')->end()
  143. ->defaultValue(array('Profile', 'Default'))
  144. ->end()
  145. ->end()
  146. ->end()
  147. ->arrayNode('menu')
  148. ->prototype('array')
  149. ->addDefaultsIfNotSet()
  150. ->cannotBeEmpty()
  151. ->children()
  152. ->scalarNode('route')->cannotBeEmpty()->end()
  153. ->arrayNode('route_parameters')
  154. ->defaultValue(array())
  155. ->prototype('array')->end()
  156. ->end()
  157. ->scalarNode('label')->cannotBeEmpty()->end()
  158. ->scalarNode('domain')->defaultValue('messages')->end()
  159. ->end()
  160. ->end()
  161. ->defaultValue($this->getProfileMenuDefaultValues())
  162. ->end()
  163. ->arrayNode('register')
  164. ->addDefaultsIfNotSet()
  165. ->children()
  166. ->arrayNode('form')
  167. ->addDefaultsIfNotSet()
  168. ->children()
  169. ->scalarNode('type')->defaultValue('sonata_user_registration')->end()
  170. ->scalarNode('handler')->defaultValue('sonata.user.registration.form.handler.default')->end()
  171. ->scalarNode('name')->defaultValue('sonata_user_registration_form')->cannotBeEmpty()->end()
  172. ->arrayNode('validation_groups')
  173. ->prototype('scalar')->end()
  174. ->defaultValue(array('Registration', 'Default'))
  175. ->end()
  176. ->end()
  177. ->end()
  178. ->arrayNode('confirm')
  179. ->addDefaultsIfNotSet()
  180. ->children()
  181. ->arrayNode('redirect')
  182. ->addDefaultsIfNotSet()
  183. ->children()
  184. ->scalarNode('route')->defaultValue('sonata_user_profile_show')->end()
  185. ->arrayNode('route_parameters')
  186. ->defaultValue(array())
  187. ->prototype('array')->end()
  188. ->end()
  189. ->end()
  190. ->end()
  191. ->end()
  192. ->end()
  193. ->end()
  194. ->end()
  195. ->end()
  196. ->end()
  197. ->end()
  198. ;
  199. return $treeBuilder;
  200. }
  201. /**
  202. * Returns default values for profile menu (to avoid BC Break).
  203. *
  204. * @return array
  205. */
  206. protected function getProfileMenuDefaultValues()
  207. {
  208. return array(
  209. array(
  210. 'route' => 'sonata_user_profile_edit',
  211. 'label' => 'link_edit_profile',
  212. 'domain' => 'SonataUserBundle',
  213. 'route_parameters' => array(),
  214. ),
  215. array(
  216. 'route' => 'sonata_user_profile_edit_authentication',
  217. 'label' => 'link_edit_authentication',
  218. 'domain' => 'SonataUserBundle',
  219. 'route_parameters' => array(),
  220. ),
  221. );
  222. }
  223. }