* class=""
*
*
*
*
*
* class="{f:format.implode(values:'{0:\'className-1\', 1:\'className-2\'}')}"
*
*
*
*
*
* class=""
*
*
*
*/
class ImplodeViewHelper extends AbstractViewHelper implements CompilableInterface {
/**
* Render the view helper
*
* @param array $values array of elements to join
* @param string $glue String used as glue between elements
* @param bool $excludeEmptyValues Remove empty elements from $values
* @return string
*/
public function render(array $values, $glue = ', ', $excludeEmptyValues = TRUE) {
return self::renderStatic(
array(
'values' => $values,
'glue' => $glue,
'excludeEmptyValues' => $excludeEmptyValues
),
$this->buildRenderChildrenClosure(),
$this->renderingContext
);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
$values = (array)$arguments['values'];
if (empty($values)) {
$values =(array)$renderChildrenClosure();
}
$glue = $arguments['glue'];
$excludeEmptyValues = (bool)$arguments['excludeEmptyValues'];
$string = '';
if ($excludeEmptyValues) {
$values = array_filter($values);
}
if (!empty($values)) {
$string = implode($glue, $values);
}
return $string;
}
}