Render for title

This commit is contained in:
Marc Ducobu 2014-11-12 12:28:57 +01:00
parent 978f2eea5e
commit 8fa75e2dd6
3 changed files with 23 additions and 3 deletions

View File

@ -25,6 +25,7 @@ use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Bundle\TwigBundle\TwigEngine;
class CustomFieldTitle implements CustomFieldInterface
{
@ -34,9 +35,16 @@ class CustomFieldTitle implements CustomFieldInterface
private $requestStack;
public function __construct(RequestStack $requestStack)
/**
*
* @var TwigEngine
*/
private $templating;
public function __construct(RequestStack $requestStack, TwigEngine $templating)
{
$this->requestStack = $requestStack;
$this->templating = $templating;
}
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
@ -53,7 +61,13 @@ class CustomFieldTitle implements CustomFieldInterface
public function render($value, CustomField $customField)
{
return $value;
return $this->templating
->render('ChillCustomFieldsBundle:CustomFieldsRendering:title.html.twig',
array(
'title' => $customField->getName(),
'type' => $customField->getOptions()[self::TYPE]
)
);
}
public function serialize($value, CustomField $customField)

View File

@ -68,6 +68,7 @@ services:
class: Chill\CustomFieldsBundle\CustomFields\CustomFieldTitle
arguments:
- "@request_stack"
- "@templating"
tags:
- { name: 'chill.custom_field', type: 'title' }

View File

@ -0,0 +1,5 @@
{% if type == "title"%}
<h2>{{ title[app.request.locale] }}</h2>
{% else %}
<h3>{{ title[app.request.locale] }}</h3>
{% endif %}