Skip to content

Commit ac3b53f

Browse files
authored
Merge pull request #89 from marcelglaeser/develop
Make TicketBundle more adaptable with template paths in config
2 parents 79018f3 + 07753a5 commit ac3b53f

8 files changed

Lines changed: 101 additions & 8 deletions

File tree

Controller/TicketController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function indexAction(Request $request)
4545
);
4646

4747
return $this->render(
48-
'HackzillaTicketBundle:Ticket:index.html.twig',
48+
$this->container->getParameter('hackzilla_ticket.templates.index'),
4949
[
5050
'pagination' => $pagination,
5151
'ticketState' => $ticketState,
@@ -81,7 +81,7 @@ public function createAction(Request $request)
8181
}
8282

8383
return $this->render(
84-
'HackzillaTicketBundle:Ticket:new.html.twig',
84+
$this->container->getParameter('hackzilla_ticket.templates.new'),
8585
[
8686
'entity' => $ticket,
8787
'form' => $form->createView(),
@@ -100,7 +100,7 @@ public function newAction()
100100
$form = $this->createForm(TicketType::class, $entity);
101101

102102
return $this->render(
103-
'HackzillaTicketBundle:Ticket:new.html.twig',
103+
$this->container->getParameter('hackzilla_ticket.templates.new'),
104104
[
105105
'entity' => $entity,
106106
'form' => $form->createView(),
@@ -143,7 +143,7 @@ public function showAction($ticketId)
143143
$data['delete_form'] = $this->createDeleteForm($ticket->getId())->createView();
144144
}
145145

146-
return $this->render('HackzillaTicketBundle:Ticket:show.html.twig', $data);
146+
return $this->render($this->container->getParameter('hackzilla_ticket.templates.show'), $data);
147147
}
148148

149149
/**
@@ -190,7 +190,7 @@ public function replyAction(Request $request, $ticketId)
190190
$data['delete_form'] = $this->createDeleteForm($ticket->getId())->createView();
191191
}
192192

193-
return $this->render('HackzillaTicketBundle:Ticket:show.html.twig', $data);
193+
return $this->render($this->container->getParameter('hackzilla_ticket.templates.show'), $data);
194194
}
195195

196196
/**

DependencyInjection/Configuration.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ public function getConfigTreeBuilder()
3030
->booleanNode('attachment')->defaultTrue()
3131
->end()
3232
->end()
33+
->arrayNode('templates')
34+
->addDefaultsIfNotSet()
35+
->canBeUnset()
36+
->children()
37+
->scalarNode('index')->defaultValue('HackzillaTicketBundle:Ticket:index.html.twig')->end()
38+
->scalarNode('new')->defaultValue('HackzillaTicketBundle:Ticket:new.html.twig')->end()
39+
->scalarNode('prototype')->defaultValue('HackzillaTicketBundle:Ticket:prototype.html.twig')->end()
40+
->scalarNode('show')->defaultValue('HackzillaTicketBundle:Ticket:show.html.twig')->end()
41+
->scalarNode('show_attachment')->defaultValue('HackzillaTicketBundle:Ticket:show_attachment.html.twig')->end()
42+
->scalarNode('macros')->defaultValue('HackzillaTicketBundle:Macros:macros.html.twig')->end()
43+
->end()
44+
->end()
3345
->end()
3446
;
3547

DependencyInjection/HackzillaTicketExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public function load(array $configs, ContainerBuilder $container)
3030
$container->setParameter('hackzilla_ticket.model.message.class', $config['message_class']);
3131

3232
$container->setParameter('hackzilla_ticket.features', $config['features']);
33+
34+
$container->setParameter('hackzilla_ticket.templates.index', $config['templates']['index']);
35+
$container->setParameter('hackzilla_ticket.templates.new', $config['templates']['new']);
36+
$container->setParameter('hackzilla_ticket.templates.prototype', $config['templates']['prototype']);
37+
$container->setParameter('hackzilla_ticket.templates.show', $config['templates']['show']);
38+
$container->setParameter('hackzilla_ticket.templates.show_attachment', $config['templates']['show_attachment']);
39+
$container->setParameter('hackzilla_ticket.templates.macros', $config['templates']['macros']);
3340
}
3441

3542
public static function bundleDirectory()

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ These optional features that can be turned on or off.
5353
* [Custom Entities](Resources/doc/setup/feature/custom-entities.md)
5454
* [Events](Resources/doc/setup/feature/events.md)
5555

56+
## Custom Templates (Optional)
57+
58+
```
59+
config.yml
60+
61+
hackzilla_ticket:
62+
templates:
63+
index: 'YOURTicketBundle:Ticket:index.html.twig'
64+
new: 'YOURTicketBundle:Ticket:new.html.twig'
65+
prototype: 'YOURTicketBundle:Ticket:prototype.html.twig'
66+
show: 'YOURTicketBundle:Ticket:show.html.twig'
67+
show_attachment: 'YOURTicketBundle:Ticket:show_attachment.html.twig'
68+
```
5669

5770
## Migrate a Previous Version
5871

Resources/config/services.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ services:
6161
- '@hackzilla_ticket.features'
6262
tags:
6363
- { name: twig.extension }
64+
65+
hackzilla_ticket.component.twig_extension.ticket_global:
66+
class: Hackzilla\Bundle\TicketBundle\TwigExtension\TicketGlobalExtension
67+
arguments:
68+
- @service_container
69+
tags:
70+
- { name: twig.extension }
6471

6572
hackzilla_ticket.file_upload_subscriber:
6673
class: Hackzilla\Bundle\TicketBundle\EventListener\FileSubscriber

Resources/views/Ticket/index.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends 'HackzillaTicketBundle::layout.html.twig' %}
2-
{% import 'HackzillaTicketBundle:Macros:macros.html.twig' as macros %}
2+
{% import hackzilla_ticket.templates.macros as macros %}
33

44
{% block hackzilla_ticket_content -%}
55
<h1>{{ 'HEADING_TICKET_LIST'|trans }}</h1>

Resources/views/Ticket/new.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
</div>
1515

1616
{% if form.messages|length == 0 %}
17-
{% include 'HackzillaTicketBundle:Ticket:prototype.html.twig' with {'form': form.messages.vars.prototype} %}
17+
{% include hackzilla_ticket.templates.prototype with {'form': form.messages.vars.prototype} %}
1818
{% else %}
19-
{% include 'HackzillaTicketBundle:Ticket:prototype.html.twig' with {'form': form.messages.__name__} %}
19+
{% include hackzilla_ticket.templates.prototype with {'form': form.messages.__name__} %}
2020
{% endif %}
2121

2222
{{ form_rest(form) }}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Hackzilla\Bundle\TicketBundle\TwigExtension;
4+
5+
use Symfony\Component\DependencyInjection\ContainerInterface;
6+
7+
class TicketGlobalExtension extends \Twig_Extension {
8+
9+
/**
10+
*
11+
* @access protected
12+
* @var \Symfony\Component\DependencyInjection\ContainerInterface $container
13+
*/
14+
protected $container;
15+
16+
/**
17+
*
18+
* @access public
19+
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
20+
*/
21+
public function __construct(ContainerInterface $container) {
22+
$this->container = $container;
23+
}
24+
25+
/**
26+
*
27+
* @access public
28+
* @return array
29+
*/
30+
public function getGlobals() {
31+
return array(
32+
'hackzilla_ticket' => array(
33+
'templates' => array(
34+
'index' => $this->container->getParameter('hackzilla_ticket.templates.index'),
35+
'new' => $this->container->getParameter('hackzilla_ticket.templates.new'),
36+
'show' => $this->container->getParameter('hackzilla_ticket.templates.show'),
37+
'show_attachment' => $this->container->getParameter('hackzilla_ticket.templates.show_attachment'),
38+
'prototype' => $this->container->getParameter('hackzilla_ticket.templates.prototype'),
39+
'macros' => $this->container->getParameter('hackzilla_ticket.templates.macros'),
40+
),
41+
)
42+
);
43+
}
44+
45+
/**
46+
*
47+
* @access public
48+
* @return string
49+
*/
50+
public function getName() {
51+
return 'ticketGlobal';
52+
}
53+
54+
}

0 commit comments

Comments
 (0)