diff --git a/src/PaymentSuite/PaymillBundle/DependencyInjection/Configuration.php b/src/PaymentSuite/PaymillBundle/DependencyInjection/Configuration.php index da8a481..0af3bd5 100644 --- a/src/PaymentSuite/PaymillBundle/DependencyInjection/Configuration.php +++ b/src/PaymentSuite/PaymillBundle/DependencyInjection/Configuration.php @@ -42,7 +42,17 @@ public function getConfigTreeBuilder() ->isRequired() ->cannotBeEmpty() ->end() - + ->arrayNode('templates') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('view_template') + ->defaultValue('PaymillBundle:Paymill:view.html.twig') + ->end() + ->scalarNode('scripts_template') + ->defaultValue('PaymillBundle:Paymill:scripts.html.twig') + ->end() + ->end() + ->end() ->arrayNode('form') ->children() ->scalarNode('submit_label') diff --git a/src/PaymentSuite/PaymillBundle/DependencyInjection/PaymillExtension.php b/src/PaymentSuite/PaymillBundle/DependencyInjection/PaymillExtension.php index 39e73b2..c8610cd 100644 --- a/src/PaymentSuite/PaymillBundle/DependencyInjection/PaymillExtension.php +++ b/src/PaymentSuite/PaymillBundle/DependencyInjection/PaymillExtension.php @@ -37,6 +37,9 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('paymill.public.key', $config['public_key']); $container->setParameter('paymill.controller.route', $config['controller_route']); + $container->setParameter('paymill.templates.view_template', $config['templates']['view_template']); + $container->setParameter('paymill.templates.scripts_template', $config['templates']['scripts_template']); + $container->setParameter('paymill.form.submit.label', $config['form']['submit_label']); $container->setParameter('paymill.form.submit.css.class', $config['form']['submit_css_class']); diff --git a/src/PaymentSuite/PaymillBundle/Resources/config/services.yml b/src/PaymentSuite/PaymillBundle/Resources/config/services.yml index 669ff37..23de636 100644 --- a/src/PaymentSuite/PaymillBundle/Resources/config/services.yml +++ b/src/PaymentSuite/PaymillBundle/Resources/config/services.yml @@ -29,6 +29,8 @@ services: paymill.public.key: %paymill.public.key% form.factory: @form.factory payment.bridge: @payment.bridge + view_template: %paymill.templates.view_template% + scripts_template: %paymill.templates.scripts_template% tags: - { name: twig.extension } diff --git a/src/PaymentSuite/PaymillBundle/Twig/PaymillExtension.php b/src/PaymentSuite/PaymillBundle/Twig/PaymillExtension.php index 75ea5f5..8ae8d12 100644 --- a/src/PaymentSuite/PaymillBundle/Twig/PaymillExtension.php +++ b/src/PaymentSuite/PaymillBundle/Twig/PaymillExtension.php @@ -14,6 +14,7 @@ namespace PaymentSuite\PaymillBundle\Twig; use Symfony\Component\Form\FormFactory; +use Twig_Environment; use Twig_Extension; use Twig_SimpleFunction; @@ -30,28 +31,42 @@ class PaymillExtension extends Twig_Extension * * Form factory */ - private $formFactory; + protected $formFactory; /** * @var Twig_Environment * * Twig environment */ - private $environment; + protected $environment; /** * @var string * * Public key */ - private $publicKey; + protected $publicKey; /** - * @var PaymentBridgeInterfaces + * @var PaymentBridgeInterface * * Payment Bridge */ - private $paymentBridgeInterface; + protected $paymentBridgeInterface; + + /** + * @var string + * + * View template name in Bundle notation + */ + protected $viewTemplate; + + /** + * @var string + * + * Scripts template in Bundle notation + */ + protected $scriptsTemplate; /** * Construct method @@ -59,12 +74,21 @@ class PaymillExtension extends Twig_Extension * @param string $publicKey Public key * @param FormFactory $formFactory Form factory * @param PaymentBridgeInterface $paymentBridgeInterface Payment Bridge + * @param string $viewTemplate Twig template name for displaying the form + * @param string $scriptstemplate Twig template name for scripts/js */ - public function __construct($publicKey, FormFactory $formFactory, PaymentBridgeInterface $paymentBridgeInterface) + public function __construct( + $publicKey, + FormFactory $formFactory, + PaymentBridgeInterface $paymentBridgeInterface, + $viewTemplate, + $scriptsTemplate) { $this->publicKey = $publicKey; $this->formFactory = $formFactory; $this->paymentBridgeInterface = $paymentBridgeInterface; + $this->viewTemplate = $viewTemplate; + $this->scriptsTemplate = $scriptsTemplate; } /** @@ -97,13 +121,13 @@ public function getFunctions() /** * Render paymill form view * - * @return string view html + * @return void */ - public function renderPaymentView() + public function renderPaymentView($viewTemplate = null) { $formType = $this->formFactory->create('paymill_view'); - return $this->environment->display('PaymillBundle:Paymill:view.html.twig', array( + $this->environment->display($viewTemplate ?: $this->viewTemplate, array( 'paymill_form' => $formType->createView(), )); } @@ -111,11 +135,11 @@ public function renderPaymentView() /** * Render paymill scripts view * - * @return string js code needed by Paymill behaviour + * @return void */ public function renderPaymentScripts() { - return $this->environment->display('PaymillBundle:Paymill:scripts.html.twig', array( + $this->environment->display($this->scriptsTemplate, array( 'public_key' => $this->publicKey, 'currency' => $this->paymentBridgeInterface->getCurrency(), ));