mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 19:28:51 +02:00
Added links to category, footprint and manufacturer columns
This commit is contained in:
parent
73f8ee36a5
commit
748905c325
2 changed files with 27 additions and 1 deletions
|
@ -33,13 +33,25 @@ namespace App\DataTables\Column;
|
||||||
|
|
||||||
|
|
||||||
use App\Entity\Base\NamedDBElement;
|
use App\Entity\Base\NamedDBElement;
|
||||||
|
use App\Entity\Parts\Part;
|
||||||
|
use App\Services\EntityURLGenerator;
|
||||||
use Omines\DataTablesBundle\Column\AbstractColumn;
|
use Omines\DataTablesBundle\Column\AbstractColumn;
|
||||||
use Symfony\Component\OptionsResolver\Options;
|
use Symfony\Component\OptionsResolver\Options;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||||
|
|
||||||
class EntityColumn extends AbstractColumn
|
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.
|
* 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) {
|
$resolver->setDefault('field', function (Options $option) {
|
||||||
return $option['property'] . '.name';
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -142,7 +142,7 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
])
|
])
|
||||||
->add('category', EntityColumn::class, [
|
->add('category', EntityColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.category'),
|
'label' => $this->translator->trans('part.table.category'),
|
||||||
'property' => 'category'
|
'property' => 'category',
|
||||||
])
|
])
|
||||||
->add('footprint', EntityColumn::class, [
|
->add('footprint', EntityColumn::class, [
|
||||||
'property' => 'footprint',
|
'property' => 'footprint',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue