Completed
Push — master ( 6c8e3d...490079 )
by ARCANEDEV
9s
created

Link::getActionTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php namespace Arcanesoft\Core\Helpers\UI;
2
3
/**
4
 * Class     Link
5
 *
6
 * @package  Arcanesoft\Core\Helpers\UI
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
class Link extends AbstractClickable
10
{
11
    /* -----------------------------------------------------------------
12
     |  Properties
13
     | -----------------------------------------------------------------
14
     */
15
    /** @var string */
16
    protected $url;
17
18
    /* -----------------------------------------------------------------
19
     |  Constructor
20
     | -----------------------------------------------------------------
21
     */
22
    /**
23
     * LinkElement constructor.
24
     *
25
     * @param  string  $action
26
     * @param  string  $url
27
     * @param  array   $attributes
28
     * @param  bool    $disabled
29
     */
30 54
    public function __construct($action, $url, array $attributes = [], $disabled = false)
31
    {
32 54
        $this->setAction($action);
33 54
        $this->setUrl($url);
34 54
        $this->setAttributes($attributes);
35 54
        $this->setDisabled($disabled);
36 54
    }
37
38
    /* -----------------------------------------------------------------
39
     |  Getters & Setters
40
     | -----------------------------------------------------------------
41
     */
42
    /**
43
     * Set the link url.
44
     *
45
     * @param  string  $url
46
     *
47
     * @return \Arcanesoft\Core\Helpers\UI\Link
48
     */
49 54
    public function setUrl($url)
50
    {
51 54
        $this->url = $url;
52
53 54
        return $this;
54
    }
55
56
    /* -----------------------------------------------------------------
57
     |  Main Methods
58
     | -----------------------------------------------------------------
59
     */
60
    /**
61
     * Make link instance.
62
     *
63
     * @param  string  $action
64
     * @param  string  $url
65
     * @param  array   $attributes
66
     * @param  bool    $disabled
67
     *
68
     * @return self
69
     */
70 54
    public static function make($action, $url, array $attributes = [], $disabled = false)
71
    {
72 54
        return new static($action, $url, $attributes, $disabled);
73
    }
74
75
    /**
76
     * Get content as a string of HTML.
77
     *
78
     * @return string
79
     */
80 54
    public function toHtml()
81
    {
82 54
        return '<a'.$this->renderAttributes().'>'.$this->renderValue().'</a>';
83
    }
84
85
    /* -----------------------------------------------------------------
86
     |  Other Methods
87
     | -----------------------------------------------------------------
88
     */
89
    /**
90
     * Render the attributes.
91
     *
92
     * @return string
93
     */
94 54
    protected function renderAttributes()
95
    {
96 54
        $attributes = collect();
97 54
        $attributes->put('href',  $this->disabled ? 'javascript:void(0);' : $this->url);
98 54
        $attributes->put('class', $this->getStyleClass());
99
100 54
        if ($this->withTooltip) {
101
            // This is for Bootstrap
102 6
            $attributes->put('data-toggle', 'tooltip');
103 6
            $attributes->put('data-original-title', $this->getTitle());
104 2
        }
105
106 54
        if ($this->disabled)
107 20
            $attributes->put('disabled', 'disabled');
108
109 54
        return html()->attributes($attributes->merge($this->attributes)->toArray());
110
    }
111
112
    /**
113
     * Get the value from config.
114
     *
115
     * @param  string  $key
116
     * @param  mixed   $default
117
     *
118
     * @return mixed
119
     */
120 54
    protected function getConfig($key, $default = null)
121
    {
122 54
        return config("arcanesoft.core.ui.links.{$key}", $default);
123
    }
124
}
125