Completed
Push — master ( 2055e6...14d075 )
by Paweł
17s queued 10s
created

AttachmentAdmin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configureDatagridFilters() 0 6 1
A configureListFields() 0 5 1
A configureFormFields() 0 12 2
1
<?php
2
3
namespace App\Admin;
4
5
use Sonata\AdminBundle\Admin\AbstractAdmin;
6
use Sonata\AdminBundle\Datagrid\ListMapper;
7
use Sonata\AdminBundle\Datagrid\DatagridMapper;
8
use Sonata\AdminBundle\Form\FormMapper;
9
use Symfony\Component\Form\Extension\Core\Type\FileType;
10
11
final class AttachmentAdmin extends AbstractAdmin
12
{
13
    protected function configureFormFields(FormMapper $formMapper)
14
    {
15
        $container = $this->getConfigurationPool()->getContainer();
16
        $formMapper->add('name');
17
        $fileFieldOptions = ['required' => false];
18
        if (null !== $this->getSubject()->getFileName()) {
19
            $filePath = $container->get('vich_uploader.templating.helper.uploader_helper')->asset($this->getSubject(), 'file');
20
21
            $fileFieldOptions['help'] = 'Current file: '.$filePath;
22
        }
23
        $formMapper->add('file', FileType::class, $fileFieldOptions);
24
        $formMapper->add('lesson');
25
    }
26
27
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
28
    {
29
        $datagridMapper->add('name');
30
        $datagridMapper->add('lesson.title');
31
        $datagridMapper->add('lesson.module.course');
32
        $datagridMapper->add('fileName');
33
    }
34
35
    protected function configureListFields(ListMapper $listMapper)
36
    {
37
        $listMapper->addIdentifier('name');
38
        $listMapper->add('lesson.title');
39
        $listMapper->add('fileName', 'string', ['template' => 'admin/attachment/download.html.twig']);
40
    }
41
}
42