<?php
/**
* Hidden Column
*
* Could be used for adding data attributes to a row but not show as an visible column
*
* @author Bertin van den Ham <b.vandenham@visualmedia.nl>
*/
namespace VisualMedia\LisaBundle\Component\DataTable\Column;
use Closure;
use VisualMedia\LisaBundle\Helper\EntityHelper;
use VisualMedia\LisaBundle\Helper\Helper;
use VisualMedia\LisaBundle\Component\Interfaces\ColumnInterface;
use VisualMedia\LisaBundle\Component\Interfaces\DataTableInterface;
use VisualMedia\LisaBundle\Component\Interfaces\EntityInterface;
/**
* Hidden Column
*/
class HiddenColumn extends Column
{
public const DEFAULT_BODY_TEMPLATE = '@VisualMediaLisa/DataTable/HiddenColumn/body.html.twig';
public const DEFAULT_HEADER_TEMPLATE = '@VisualMediaLisa/DataTable/HiddenColumn/header.html.twig';
/**
* {@inheritdoc}
*/
public $bodyTemplate = self::DEFAULT_BODY_TEMPLATE;
public $headerTemplate = self::DEFAULT_HEADER_TEMPLATE;
/**
* DataAttributeClosuere
* Could be use to set data attributes to an hidden column
*
* @var Closure|null
*/
public $dataAttributeClosure = null;
/**
* {@inheritdoc}
*/
public function initialize(DataTableInterface $datatable, $title = null, $content = null, $orderBy = false, $dataAttributeClosure = null): ColumnInterface
{
$this->dataAttributeClosure = $dataAttributeClosure;
parent::initialize($datatable, $title, $content, $orderBy, $dataAttributeClosure);
return $this;
}
/**
* GetdataAttributeClosure
*
* @param EntityInterface|null $row
*
* @return Closure|mixed|string|array|null
*/
public function getdataAttributeClosure(EntityInterface $row = null)
{
$dataAttributeClosure = $this->dataAttributeClosure;
if ($row !== null) {
if ($dataAttributeClosure === null) {
return null;
} else if ($dataAttributeClosure instanceof Closure) {
return $dataAttributeClosure($row);
}
}
return $dataAttributeClosure;
}
}