'ChillCustomFieldsBundle:CustomFieldsGroup:render.html.twig', 'show_empty' => true, ]; /** * @param bool $showEmptyValues whether the empty values must be rendered */ public function __construct($showEmptyValues) { $this->defaultParams['show_empty'] = $showEmptyValues; } /** * (non-PHPdoc). * * @see Twig_Extension::getFunctions() */ public function getFunctions() { return [ new TwigFunction('chill_custom_fields_group_widget', [ $this, 'renderWidget', ], [ 'is_safe' => [ 'html', ], ]), ]; } /** (non-PHPdoc). * @see Twig_ExtensionInterface::getName() */ public function getName() { return 'chill_custom_fields_group_rendering'; } /** * Twig extension that is used to render the value of a custom field group. * * The presentation of the value is influenced by the document type. * * @param array $fields The array raw, as stored in the db * @param CustomFieldsGroud $customFielsGroup The custom field group * @param string $documentType The type of the document (csv, html) * @param array $params The parameters for rendering : * - layout : allow to choose a different layout by default : * ChillCustomFieldsBundle:CustomFieldsGroup:render.html.twig * - show_empty : force show empty field * * @return string HTML representation of the custom field group value, as described in * the CustomFieldInterface. Is HTML safe */ public function renderWidget(array $fields, $customFielsGroup, $documentType = 'html', array $params = []) { $resolvedParams = array_merge($this->defaultParams, $params); return $this->container->get('templating') ->render($resolvedParams['layout'], [ 'cFGroup' => $customFielsGroup, 'cFData' => $fields, 'show_empty' => $resolvedParams['show_empty'], ]); } /** * (non-PHPdoc). * * @see \Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer() */ public function setContainer(?ContainerInterface $container = null) { $this->container = $container; } }