1 | <?php namespace Arcanesoft\Core\Helpers\UI; |
||
9 | class Link extends AbstractClickable |
||
10 | { |
||
11 | /* ----------------------------------------------------------------- |
||
12 | | Properties |
||
13 | | ----------------------------------------------------------------- |
||
14 | */ |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $url; |
||
18 | |||
19 | /* ----------------------------------------------------------------- |
||
20 | | Constructor |
||
21 | | ----------------------------------------------------------------- |
||
22 | */ |
||
23 | |||
24 | /** |
||
25 | * LinkElement constructor. |
||
26 | * |
||
27 | * @param string $action |
||
28 | * @param string $url |
||
29 | * @param array $attributes |
||
30 | * @param bool $disabled |
||
31 | */ |
||
32 | 36 | public function __construct($action, $url, array $attributes = [], $disabled = false) |
|
39 | |||
40 | /* ----------------------------------------------------------------- |
||
41 | | Getters & Setters |
||
42 | | ----------------------------------------------------------------- |
||
43 | */ |
||
44 | |||
45 | /** |
||
46 | * Set the link url. |
||
47 | * |
||
48 | * @param string $url |
||
49 | * |
||
50 | * @return \Arcanesoft\Core\Helpers\UI\Link |
||
51 | */ |
||
52 | 36 | public function setUrl($url) |
|
58 | |||
59 | /* ----------------------------------------------------------------- |
||
60 | | Main Methods |
||
61 | | ----------------------------------------------------------------- |
||
62 | */ |
||
63 | |||
64 | /** |
||
65 | * Make link instance. |
||
66 | * |
||
67 | * @param string $action |
||
68 | * @param string $url |
||
69 | * @param array $attributes |
||
70 | * @param bool $disabled |
||
71 | * |
||
72 | * @return self |
||
73 | */ |
||
74 | 36 | public static function make($action, $url, array $attributes = [], $disabled = false) |
|
78 | |||
79 | /** |
||
80 | * Get content as a string of HTML. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 36 | public function toHtml() |
|
88 | |||
89 | /* ----------------------------------------------------------------- |
||
90 | | Other Methods |
||
91 | | ----------------------------------------------------------------- |
||
92 | */ |
||
93 | |||
94 | /** |
||
95 | * Render the attributes. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | 36 | protected function renderAttributes() |
|
100 | { |
||
101 | 36 | $attributes = collect(); |
|
102 | 36 | $attributes->put('href', $this->disabled ? 'javascript:void(0);' : $this->url); |
|
103 | 36 | $attributes->put('class', $this->getStyleClass()); |
|
104 | |||
105 | 36 | if ($this->withTooltip) { |
|
106 | // This is for Bootstrap |
||
107 | 4 | $attributes->put('data-toggle', 'tooltip'); |
|
108 | 4 | $attributes->put('data-original-title', $this->getTitle()); |
|
109 | } |
||
110 | |||
111 | 36 | if ($this->disabled) |
|
112 | 2 | $attributes->put('disabled', 'disabled'); |
|
113 | |||
114 | 36 | return html()->attributes($attributes->merge($this->attributes)->toArray()); |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * Get the value from config. |
||
119 | * |
||
120 | * @param string $key |
||
121 | * @param mixed $default |
||
122 | * |
||
123 | * @return mixed |
||
124 | */ |
||
125 | 36 | protected function getConfig($key, $default = null) |
|
129 | } |
||
130 |