Completed
Branch master (b7ffcb)
by Tomas Norre
17:57
created

ButtonUtility::getLinkButton()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 6
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace AOE\Crawler\Utility;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2017 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use TYPO3\CMS\Backend\Template\ModuleTemplate;
29
use TYPO3\CMS\Core\Imaging\Icon;
30
use TYPO3\CMS\Core\Imaging\IconFactory;
31
use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33
/**
34
 * Class ButtonUtility
35
 *
36
 * For button icons available see
37
 * https://github.com/TYPO3/TYPO3.Icons
38
 *
39
 * @package AOE\Crawler\Utility
40
 *
41
 * @codeCoverageIgnore
42
 */
43
class ButtonUtility
44
{
45
    /**
46
     * @param string $icon
47
     * @param string $title
48
     * @param string $onClick
49
     * @param string $iconSize
50
     * @param string $href
51
     * @param array $attributes
52
     *
53
     * @return $this
54
     */
55
    public static function getLinkButton($icon = '', $title = '', $onClick = '', $iconSize = Icon::SIZE_SMALL, $href = '#', $attributes = [])
56
    {
57
        /** @var IconFactory $iconFactory */
58
        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
59
60
        /** @var ModuleTemplate $moduleTemplate */
61
        $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
62
        $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
63
        $button = $buttonBar->makeLinkButton()
64
            ->setHref($href)
65
            ->setDataAttributes($attributes)
66
            ->setIcon($iconFactory->getIcon($icon, $iconSize))
67
            ->setTitle($title)
68
            ->setOnClick($onClick)
69
            ->setShowLabelText(true);
70
71
        return $button;
72
    }
73
}
74