Skip to content

Commit

Permalink
EZP-24361: Added a base template to render field blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lolautruche committed May 19, 2015
1 parent 0b53f74 commit 08d0e45
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Expand Up @@ -123,12 +123,9 @@ services:

ezpublish.templating.field_block_renderer.twig:
class: %ezpublish.templating.field_block_renderer.twig.class%
arguments:
- @ezpublish.api.service.content_type
- @ezpublish.fieldType.parameterProviderRegistry
- @ezpublish.translation_helper
calls:
- [setTwig, [@twig]]
- [setBaseTemplate, [%ezpublish.content_view.viewbase_layout%]]
- [setFieldViewResources, ["$field_templates$"]]
- [setFieldEditResources, ["$field_edit_templates$"]]
- [setFieldDefinitionViewResources, ["$fielddefinition_settings_templates$"]]
Expand Down
Expand Up @@ -28,6 +28,7 @@ public function getExtensions()
$configResolver = $this->getConfigResolverMock();

$fieldBlockRenderer = new FieldBlockRenderer();
$fieldBlockRenderer->setBaseTemplate($this->getTemplatePath('base.html.twig'));

This comment has been minimized.

Copy link
@pspanja

pspanja May 19, 2015

Contributor

CS :)

This comment has been minimized.

Copy link
@lolautruche

lolautruche May 19, 2015

Author Contributor

Damn it, thanks

This comment has been minimized.

Copy link
@lolautruche

lolautruche May 19, 2015

Author Contributor

Fixed in dbeb04c

$fieldBlockRenderer->setFieldViewResources(
array(
array(
Expand Down
28 changes: 17 additions & 11 deletions eZ/Publish/Core/MVC/Symfony/Templating/Twig/FieldBlockRenderer.php
Expand Up @@ -68,11 +68,11 @@ class FieldBlockRenderer implements FieldBlockRendererInterface
private $fieldDefinitionEditResources = [];

/**
* A \Twig_Template instance used to render template blocks.
* A \Twig_Template instance used to render template blocks, or path to the template to use.
*
* @var Twig_Template
* @var Twig_Template|string
*/
private $template;
private $baseTemplate;

/**
* Template blocks
Expand All @@ -89,6 +89,14 @@ public function setTwig( Twig_Environment $twig )
$this->twig = $twig;
}

/**
* @param string|Twig_Template $baseTemplate
*/
public function setBaseTemplate($baseTemplate)
{
$this->baseTemplate = $baseTemplate;
}

/**
* @param array $fieldViewResources
*/
Expand Down Expand Up @@ -162,13 +170,12 @@ private function renderContentField( Field $field, $fieldTypeIdentifier, array $
$params += ['field' => $field];

// Getting instance of Twig_Template that will be used to render blocks
if ( !$this->template instanceof Twig_Template )
if ( is_string( $this->baseTemplate ) )
{
$tpl = reset( $this->fieldViewResources );
$this->template = $this->twig->loadTemplate( $tpl['template'] );
$this->baseTemplate = $this->twig->loadTemplate( $this->baseTemplate );
}

return $this->template->renderBlock(
return $this->baseTemplate->renderBlock(
$this->getRenderFieldBlockName( $fieldTypeIdentifier, $type ),
$params,
$this->getBlocksByField( $fieldTypeIdentifier, $type, $localTemplate )
Expand All @@ -194,18 +201,17 @@ public function renderFieldDefinitionEdit( FieldDefinition $fieldDefinition, arr
*/
private function renderFieldDefinition( FieldDefinition $fieldDefinition, array $params, $type )
{
if ( !$this->template instanceof Twig_Template )
if ( is_string( $this->baseTemplate ) )
{
$tpl = reset( $this->fieldDefinitionViewResources );
$this->template = $this->twig->loadTemplate( $tpl['template'] );
$this->baseTemplate = $this->twig->loadTemplate( $this->baseTemplate );
}

$params += [
'fielddefinition' => $fieldDefinition,
'settings' => $fieldDefinition->getFieldSettings(),
];

return $this->template->renderBlock(
return $this->baseTemplate->renderBlock(
$this->getRenderFieldDefinitionBlockName( $fieldDefinition->fieldTypeIdentifier, $type ),
$params,
$this->getBlocksByFieldDefinition( $fieldDefinition, $type )
Expand Down

0 comments on commit 08d0e45

Please sign in to comment.