• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / vhs / 13566190336

27 Feb 2025 12:18PM UTC coverage: 72.127% (-0.6%) from 72.746%
13566190336

push

github

NamelessCoder
[TER] 7.1.0

5649 of 7832 relevant lines covered (72.13%)

20.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.75
/Classes/ViewHelpers/Media/SpotifyViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Media;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs 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 FluidTYPO3\Vhs\Traits\TagViewHelperCompatibility;
12
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
13

14
/**
15
 * Renders HTML code to embed a Spotify play button.
16
 */
17
class SpotifyViewHelper extends AbstractTagBasedViewHelper
18
{
19
    use TagViewHelperCompatibility;
20

21
    /**
22
     * Play button base url
23
     */
24
    const SPOTIFY_BASEURL = 'https://embed.spotify.com/';
25

26
    /**
27
     * @var string
28
     */
29
    protected $tagName = 'iframe';
30

31
    public function initializeArguments(): void
32
    {
33
        parent::initializeArguments();
7✔
34
        $this->registerUniversalTagAttributes();
7✔
35
        $this->registerArgument(
7✔
36
            'spotifyUri',
7✔
37
            'string',
7✔
38
            'Spotify URI to create the play button for. Right click any song, album or playlist in Spotify and ' .
7✔
39
            'select Copy Spotify URI.',
7✔
40
            true
7✔
41
        );
7✔
42
        $this->registerArgument('width', 'int', 'Width of the play button in pixels. Defaults to 300', false, 300);
7✔
43
        $this->registerArgument('height', 'int', 'Height of the play button in pixels. Defaults to 380', false, 380);
7✔
44
        $this->registerArgument(
7✔
45
            'compact',
7✔
46
            'boolean',
7✔
47
            'Whether to render the compact button with a fixed height of 80px.',
7✔
48
            false,
7✔
49
            false
7✔
50
        );
7✔
51
        $this->registerArgument(
7✔
52
            'theme',
7✔
53
            'string',
7✔
54
            'Theme to use. Can be "black" or "white" and is not available in compact mode. Defaults to "black".',
7✔
55
            false,
7✔
56
            'black'
7✔
57
        );
7✔
58
        $this->registerArgument(
7✔
59
            'view',
7✔
60
            'string',
7✔
61
            'View to use. Can be "list" or "coverart" and is not available in compact mode. Defaults to "list".',
7✔
62
            false,
7✔
63
            'list'
7✔
64
        );
7✔
65
    }
66

67
    /**
68
     * @return string
69
     */
70
    public function render()
71
    {
72
        $spotifyUri = $this->arguments['spotifyUri'];
×
73
        /** @var int $width */
74
        $width = $this->arguments['width'];
×
75
        /** @var int $height */
76
        $height = $this->arguments['height'];
×
77
        /** @var string $theme */
78
        $theme = $this->arguments['theme'];
×
79
        /** @var string $view */
80
        $view = $this->arguments['view'];
×
81

82
        if (!in_array($theme, ['black', 'white'])) {
×
83
            $theme = 'black';
×
84
        }
85

86
        if (!in_array($view, ['coverart', 'list'])) {
×
87
            $view = 'list';
×
88
        }
89

90
        if ($this->arguments['compact']) {
×
91
            $height = 80;
×
92
        }
93

94
        $src = static::SPOTIFY_BASEURL . '?uri=' . $spotifyUri . '&theme=' . $theme . '&view=' . $view;
×
95

96
        $this->tag->forceClosingTag(true);
×
97
        $this->tag->addAttribute('src', $src);
×
98
        $this->tag->addAttribute('width', (string) $width);
×
99
        $this->tag->addAttribute('height', (string) $height);
×
100
        $this->tag->addAttribute('allowtransparancy', 'true');
×
101
        $this->tag->addAttribute('frameborder', '0');
×
102

103
        return $this->tag->render();
×
104
    }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc