summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/web/src/Widget/ContinueWith.php
blob: 1479e9af6f678e398a26a4776fe38b2792b08938 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php

namespace ipl\Web\Widget;

use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlElement;
use ipl\Stdlib\Filter;
use ipl\Web\Common\BaseTarget;
use ipl\Web\Filter\QueryString;
use ipl\Web\Url;

class ContinueWith extends BaseHtmlElement
{
    use BaseTarget;

    protected $tag = 'span';

    protected $defaultAttributes = ['class' => 'continue-with'];

    /** @var Url */
    protected $url;

    /** @var Filter\Rule|callable */
    protected $filter;

    /** @var string */
    protected $title;

    public function __construct(Url $url, $filter)
    {
        $this->url = $url;
        $this->filter = $filter;
    }

    /**
     * Set title for the anchor
     *
     * @param string $title
     *
     * @return $this
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    public function assemble()
    {
        $filter = $this->filter;
        if (is_callable($filter)) {
            $filter = $filter(); /** @var Filter\Rule $filter */
        }

        if ($filter instanceof Filter\Chain && $filter->isEmpty()) {
            $this->addHtml(new HtmlElement(
                'span',
                Attributes::create(['class' => ['control-button', 'disabled']]),
                new Icon('share')
            ));
        } else {
            $this->addHtml(new ActionLink(
                null,
                $this->url->setFilter($filter),
                'share',
                ['class' => 'control-button', 'title' => $this->title]
            ));
        }
    }
}