Completed
Push — master ( 305f48...ad447f )
by Fabien
02:33
created

ImageDimensionViewHelper::initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Fab\Media\ViewHelpers;
3
4
/*
5
 * This file is part of the Fab/Media project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10
11
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
12
use Fab\Media\Utility\ImagePresetUtility;
13
14
/**
15
 * View helper which returns default preset values related to an image dimension
16
 */
17
class ImageDimensionViewHelper extends AbstractViewHelper
18
{
19
20
    /**
21
     * @return void
22
     */
23
    public function initializeArguments()
24
    {
25
        $this->registerArgument('preset', 'string', '', true);
26
        $this->registerArgument('dimension', 'string', '', false, 'width');
27
    }
28
29
    /**
30
     * Returns preset values related to an image dimension
31
     *
32
     * @return int
33
     */
34
    public function render()
35
    {
36
        $preset = $this->arguments['preset'];
37
        $dimension = $this->arguments['dimension'];
38
39
        $imageDimension = ImagePresetUtility::getInstance()->preset($preset);
40
        if ($dimension === 'width') {
41
            $result = $imageDimension->getWidth();
42
        } else {
43
            $result = $imageDimension->getHeight();
44
        }
45
        return $result;
46
    }
47
}
48