Added links to category, footprint and manufacturer columns

This commit is contained in:
Jan Böhmer 2019-09-08 16:56:05 +02:00
parent 73f8ee36a5
commit 748905c325
2 changed files with 27 additions and 1 deletions

View file

@ -33,13 +33,25 @@ namespace App\DataTables\Column;
use App\Entity\Base\NamedDBElement;
use App\Entity\Parts\Part;
use App\Services\EntityURLGenerator;
use Omines\DataTablesBundle\Column\AbstractColumn;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
class EntityColumn extends AbstractColumn
{
protected $urlGenerator;
protected $accessor;
public function __construct(EntityURLGenerator $URLGenerator, PropertyAccessorInterface $accessor)
{
$this->urlGenerator = $URLGenerator;
$this->accessor = $accessor;
}
/**
* The normalize function is responsible for converting parsed and processed data to a datatables-appropriate type.
*
@ -61,5 +73,19 @@ class EntityColumn extends AbstractColumn
$resolver->setDefault('field', function (Options $option) {
return $option['property'] . '.name';
});
$resolver->setDefault('render', function (Options $options) {
return function ($value, Part $context) use ($options) {
$entity = $this->accessor->getValue($context, $options['property']);
if ($entity) {
return sprintf(
'<a href="%s">%s</a>',
$this->urlGenerator->listPartsURL($entity),
$value
);
}
};
});
}
}

View file

@ -142,7 +142,7 @@ class PartsDataTable implements DataTableTypeInterface
])
->add('category', EntityColumn::class, [
'label' => $this->translator->trans('part.table.category'),
'property' => 'category'
'property' => 'category',
])
->add('footprint', EntityColumn::class, [
'property' => 'footprint',