AbstractSonataAdminExtension.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  13. /**
  14. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  15. */
  16. abstract class AbstractSonataAdminExtension extends Extension
  17. {
  18. /**
  19. * Fix template configuration.
  20. *
  21. * @param array $configs
  22. * @param ContainerBuilder $container
  23. * @param array $defaultSonataDoctrineConfig
  24. *
  25. * @return array
  26. */
  27. protected function fixTemplatesConfiguration(array $configs, ContainerBuilder $container, array $defaultSonataDoctrineConfig = array())
  28. {
  29. $defaultConfig = array(
  30. 'templates' => array(
  31. 'types' => array(
  32. 'list' => array(
  33. 'array' => 'SonataAdminBundle:CRUD:list_array.html.twig',
  34. 'boolean' => 'SonataAdminBundle:CRUD:list_boolean.html.twig',
  35. 'date' => 'SonataAdminBundle:CRUD:list_date.html.twig',
  36. 'time' => 'SonataAdminBundle:CRUD:list_time.html.twig',
  37. 'datetime' => 'SonataAdminBundle:CRUD:list_datetime.html.twig',
  38. 'text' => 'SonataAdminBundle:CRUD:list_string.html.twig',
  39. 'textarea' => 'SonataAdminBundle:CRUD:list_string.html.twig',
  40. 'email' => 'SonataAdminBundle:CRUD:list_email.html.twig',
  41. 'trans' => 'SonataAdminBundle:CRUD:list_trans.html.twig',
  42. 'string' => 'SonataAdminBundle:CRUD:list_string.html.twig',
  43. 'smallint' => 'SonataAdminBundle:CRUD:list_string.html.twig',
  44. 'bigint' => 'SonataAdminBundle:CRUD:list_string.html.twig',
  45. 'integer' => 'SonataAdminBundle:CRUD:list_string.html.twig',
  46. 'decimal' => 'SonataAdminBundle:CRUD:list_string.html.twig',
  47. 'identifier' => 'SonataAdminBundle:CRUD:list_string.html.twig',
  48. 'currency' => 'SonataAdminBundle:CRUD:list_currency.html.twig',
  49. 'percent' => 'SonataAdminBundle:CRUD:list_percent.html.twig',
  50. 'choice' => 'SonataAdminBundle:CRUD:list_choice.html.twig',
  51. 'url' => 'SonataAdminBundle:CRUD:list_url.html.twig',
  52. 'html' => 'SonataAdminBundle:CRUD:list_html.html.twig',
  53. ),
  54. 'show' => array(
  55. 'array' => 'SonataAdminBundle:CRUD:show_array.html.twig',
  56. 'boolean' => 'SonataAdminBundle:CRUD:show_boolean.html.twig',
  57. 'date' => 'SonataAdminBundle:CRUD:show_date.html.twig',
  58. 'time' => 'SonataAdminBundle:CRUD:show_time.html.twig',
  59. 'datetime' => 'SonataAdminBundle:CRUD:show_datetime.html.twig',
  60. 'text' => 'SonataAdminBundle:CRUD:base_show_field.html.twig',
  61. 'email' => 'SonataAdminBundle:CRUD:show_email.html.twig',
  62. 'trans' => 'SonataAdminBundle:CRUD:show_trans.html.twig',
  63. 'string' => 'SonataAdminBundle:CRUD:base_show_field.html.twig',
  64. 'smallint' => 'SonataAdminBundle:CRUD:base_show_field.html.twig',
  65. 'bigint' => 'SonataAdminBundle:CRUD:base_show_field.html.twig',
  66. 'integer' => 'SonataAdminBundle:CRUD:base_show_field.html.twig',
  67. 'decimal' => 'SonataAdminBundle:CRUD:base_show_field.html.twig',
  68. 'currency' => 'SonataAdminBundle:CRUD:show_currency.html.twig',
  69. 'percent' => 'SonataAdminBundle:CRUD:show_percent.html.twig',
  70. 'choice' => 'SonataAdminBundle:CRUD:show_choice.html.twig',
  71. 'url' => 'SonataAdminBundle:CRUD:show_url.html.twig',
  72. 'html' => 'SonataAdminBundle:CRUD:show_html.html.twig',
  73. ),
  74. ),
  75. ),
  76. );
  77. // let's add some magic, only overwrite template if the SonataIntlBundle is enabled
  78. $bundles = $container->getParameter('kernel.bundles');
  79. if (isset($bundles['SonataIntlBundle'])) {
  80. $defaultConfig['templates']['types']['list'] = array_merge($defaultConfig['templates']['types']['list'], array(
  81. 'date' => 'SonataIntlBundle:CRUD:list_date.html.twig',
  82. 'datetime' => 'SonataIntlBundle:CRUD:list_datetime.html.twig',
  83. 'smallint' => 'SonataIntlBundle:CRUD:list_decimal.html.twig',
  84. 'bigint' => 'SonataIntlBundle:CRUD:list_decimal.html.twig',
  85. 'integer' => 'SonataIntlBundle:CRUD:list_decimal.html.twig',
  86. 'decimal' => 'SonataIntlBundle:CRUD:list_decimal.html.twig',
  87. 'currency' => 'SonataIntlBundle:CRUD:list_currency.html.twig',
  88. 'percent' => 'SonataIntlBundle:CRUD:list_percent.html.twig',
  89. ));
  90. $defaultConfig['templates']['types']['show'] = array_merge($defaultConfig['templates']['types']['show'], array(
  91. 'date' => 'SonataIntlBundle:CRUD:show_date.html.twig',
  92. 'datetime' => 'SonataIntlBundle:CRUD:show_datetime.html.twig',
  93. 'smallint' => 'SonataIntlBundle:CRUD:show_decimal.html.twig',
  94. 'bigint' => 'SonataIntlBundle:CRUD:show_decimal.html.twig',
  95. 'integer' => 'SonataIntlBundle:CRUD:show_decimal.html.twig',
  96. 'decimal' => 'SonataIntlBundle:CRUD:show_decimal.html.twig',
  97. 'currency' => 'SonataIntlBundle:CRUD:show_currency.html.twig',
  98. 'percent' => 'SonataIntlBundle:CRUD:show_percent.html.twig',
  99. ));
  100. }
  101. if (!empty($defaultSonataDoctrineConfig)) {
  102. $defaultConfig = array_merge_recursive($defaultConfig, $defaultSonataDoctrineConfig);
  103. }
  104. array_unshift($configs, $defaultConfig);
  105. return $configs;
  106. }
  107. }