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

heimrichhannot / contao-utils-bundle / 11854178157

15 Nov 2024 10:01AM UTC coverage: 23.081% (-0.2%) from 23.297%
11854178157

push

github

koertho
add backend wizard ui with popup wizard method

0 of 53 new or added lines in 2 files covered. (0.0%)

1320 of 5719 relevant lines covered (23.08%)

1.54 hits per line

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

0.0
/src/Util/BackendUiUtil.php
1
<?php
2

3
namespace HeimrichHannot\UtilsBundle\Util;
4

5
use Contao\CoreBundle\Framework\ContaoFramework;
6
use Contao\Image;
7
use Contao\StringUtil;
8
use HeimrichHannot\UtilsBundle\Util\Html\HtmlUtil;
9
use HeimrichHannot\UtilsBundle\Util\Routing\RoutingUtil;
10
use HeimrichHannot\UtilsBundle\Util\Ui\PopupWizardLinkOptions;
11

12
class BackendUiUtil
13
{
14
    private RoutingUtil $routingUtil;
15
    private ContaoFramework $framework;
16
    private HtmlUtil $htmlUtil;
17

18
    public function __construct(
19
        RoutingUtil     $routingUtil,
20
        ContaoFramework $framework,
21
        HtmlUtil        $htmlUtil
22
    )
23
    {
NEW
24
        $this->routingUtil = $routingUtil;
×
NEW
25
        $this->framework = $framework;
×
NEW
26
        $this->htmlUtil = $htmlUtil;
×
27
    }
28

29
    /**
30
     * Create a popup wizard link or url.
31
     */
32
    public function popupWizardLink(array $parameter, PopupWizardLinkOptions $config): string
33
    {
NEW
34
        $parameter['popup'] = 1;
×
NEW
35
        $parameter['nb'] = 1;
×
36

NEW
37
        $url = $this->routingUtil->generateBackendRoute($parameter, true, true, $config->route);
×
NEW
38
        if ($config->urlOnly) {
×
NEW
39
            return $url;
×
40
        }
41

NEW
42
        $attributes = $config->attributes;
×
NEW
43
        if (empty($config->title)) {
×
NEW
44
            $title = $GLOBALS['TL_LANG']['tl_content']['edit'][0];
×
45
        } else {
NEW
46
            $title = StringUtil::specialchars($config->title);
×
47
        }
48

NEW
49
        if (!isset($attributes['title'])) {
×
NEW
50
            $attributes['title'] = $title;
×
51
        }
52

NEW
53
        if (!isset($attributes['style'])) {
×
NEW
54
            $attributes['style'] = $config->style;
×
55
        }
56

57
        // onclick
NEW
58
        if (empty($attributes['onclick'])) {
×
NEW
59
            if (empty($config->popupTitle)) {
×
NEW
60
                $popupTitle = $title;
×
61
            } else {
NEW
62
                $popupTitle = $config->popupTitle;
×
63
            }
64

NEW
65
            $attributes['onclick'] = sprintf(
×
NEW
66
                'Backend.openModalIframe({\'width\':%s,\'title\':\'%s'.'\',\'url\':this.href});return false',
×
NEW
67
                $config->width,
×
NEW
68
                $popupTitle
×
NEW
69
            );
×
70
        }
71

72
        // link text and icon
NEW
73
        $linkText = '';
×
74

NEW
75
        if (!empty($config->icon)) {
×
76
            /** @var Image $image */
NEW
77
            $image = $this->framework->getAdapter(Image::class);
×
NEW
78
            $linkText .= $image->getHtml('alias.svg', $title, 'style="vertical-align:top"');
×
79
        }
80

NEW
81
        if (!empty($config->linkText)) {
×
NEW
82
            $linkText = trim($linkText . ' '.$config->linkText);
×
83
        }
84

85
        // remove href from attributes if set
NEW
86
        unset($attributes['href']);
×
87

NEW
88
        return sprintf(
×
NEW
89
            '<a href="%s" %s>%s</a>',
×
NEW
90
            $url,
×
NEW
91
            $this->htmlUtil->generateAttributeString($attributes),
×
NEW
92
            $linkText
×
NEW
93
        );
×
94
    }
95
}
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

© 2025 Coveralls, Inc