Completed
Push — master ( 603670...576387 )
by Adam
06:48
created

File::getTypeIcons()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Component\Form\Elements\Upload;
14
15
use Symfony\Component\OptionsResolver\OptionsResolver;
16
use WellCommerce\Component\Form\Elements\AbstractField;
17
use WellCommerce\Component\Form\Elements\Attribute;
18
use WellCommerce\Component\Form\Elements\AttributeCollection;
19
use WellCommerce\Component\Form\Elements\ElementInterface;
20
21
/**
22
 * Class File
23
 *
24
 * @author  Adam Piotrowski <[email protected]>
25
 */
26
class File extends AbstractField implements ElementInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function configureOptions(OptionsResolver $resolver)
32
    {
33
        parent::configureOptions($resolver);
34
        
35
        $resolver->setRequired([
36
            'load_route',
37
            'upload_route',
38
            'session_name',
39
            'session_id',
40
        ]);
41
        
42
        $resolver->setDefaults([
43
            'load_route'             => 'admin.media.grid',
44
            'upload_route'           => 'admin.media.add',
45
            'repeat_min'             => 0,
46
            'repeat_max'             => ElementInterface::INFINITE,
47
            'limit'                  => 1000,
48
            'file_types_description' => 'file_types_description',
49
            'file_types'             => ['jpg', 'jpeg', 'png', 'gif'],
50
        ]);
51
        
52
        $resolver->setAllowedTypes('session_id', 'string');
53
        $resolver->setAllowedTypes('session_name', 'string');
54
        $resolver->setAllowedTypes('file_types_description', 'string');
55
        $resolver->setAllowedTypes('file_types', 'array');
56
    }
57
    
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function prepareAttributesCollection(AttributeCollection $collection)
62
    {
63
        parent::prepareAttributesCollection($collection);
64
        
65
        $collection->add(new Attribute('sSessionName', $this->getOption('session_name')));
66
        $collection->add(new Attribute('sSessionId', $this->getOption('session_id')));
67
        $collection->add(new Attribute('iLimit', $this->getOption('limit'), Attribute::TYPE_INTEGER));
68
        $collection->add(new Attribute('asFileTypes', $this->getOption('file_types'), Attribute::TYPE_ARRAY));
69
        $collection->add(new Attribute('sFileTypesDescription', $this->getOption('file_types_description')));
70
        $collection->add(new Attribute('sLoadRoute', $this->getOption('load_route')));
71
        $collection->add(new Attribute('sUploadRoute', $this->getOption('upload_route')));
72
        $collection->add(new Attribute('oRepeat', $this->prepareRepetitions(), Attribute::TYPE_ARRAY));
73
    }
74
    
75
    protected function getTypeIcons(): array
76
    {
77
        return [
78
            'cdup'      => 'images/icons/filetypes/cdup.png',
79
            'unknown'   => 'images/icons/filetypes/unknown.png',
80
            'directory' => 'images/icons/filetypes/directory.png',
81
            'gif'       => 'images/icons/filetypes/image.png',
82
            'png'       => 'images/icons/filetypes/image.png',
83
            'jpg'       => 'images/icons/filetypes/image.png',
84
            'bmp'       => 'images/icons/filetypes/image.png',
85
            'txt'       => 'images/icons/filetypes/text.png',
86
            'doc'       => 'images/icons/filetypes/text.png',
87
            'rtf'       => 'images/icons/filetypes/text.png',
88
            'odt'       => 'images/icons/filetypes/text.png',
89
            'htm'       => 'images/icons/filetypes/document.png',
90
            'html'      => 'images/icons/filetypes/document.png',
91
            'php'       => 'images/icons/filetypes/document.png',
92
        ];
93
    }
94
}
95