1
|
|
|
<?php namespace Arcanesoft\Core\Helpers\UI\LinkTraits; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Trait ActivateLinks |
5
|
|
|
* |
6
|
|
|
* @package Arcanesoft\Core\Helpers\UI\LinkTraits |
7
|
|
|
* @author ARCANEDEV <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
trait ActivateLinks |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Generate activate icon link. |
13
|
|
|
* |
14
|
|
|
* @param bool $active |
15
|
|
|
* @param string $url |
16
|
|
|
* @param array $attributes |
17
|
|
|
* @param bool $disabled |
18
|
|
|
* |
19
|
|
|
* @return self |
20
|
|
|
*/ |
21
|
18 |
|
public static function activateIcon($active, $url, array $attributes = [], $disabled = false) |
22
|
|
|
{ |
23
|
18 |
|
return self::make($active ? 'enable' : 'disable', $url, $attributes, $disabled) |
24
|
18 |
|
->size('xs') |
25
|
18 |
|
->withTitle(false) |
26
|
18 |
|
->icon(true); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Generate activate icon link for modals (reverse button based on active state). |
31
|
|
|
* |
32
|
|
|
* @param bool $active |
33
|
|
|
* @param string $url |
34
|
|
|
* @param array $attributes |
35
|
|
|
* @param bool $disabled |
36
|
|
|
* |
37
|
|
|
* @return self |
38
|
|
|
*/ |
39
|
3 |
|
public static function activateModalIcon($active, $url, array $attributes = [], $disabled = false) |
40
|
|
|
{ |
41
|
3 |
|
$dataAttribute = 'data-current-status'; |
42
|
|
|
$statuses = [ |
43
|
3 |
|
'enabled' => 'enabled', |
44
|
1 |
|
'disabled' => 'disabled', |
45
|
1 |
|
]; |
46
|
|
|
|
47
|
3 |
|
return static::activateIcon( ! $active, $url, $attributes, $disabled) |
|
|
|
|
48
|
3 |
|
->setAttribute($dataAttribute, $statuses[$active ? 'enabled' : 'disabled']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Generate activate link with icon for modals (reverse button based on active state). |
53
|
|
|
* |
54
|
|
|
* @param bool $active |
55
|
|
|
* @param string $url |
56
|
|
|
* @param array $attributes |
57
|
|
|
* @param bool $disabled |
58
|
|
|
* |
59
|
|
|
* @return self |
60
|
|
|
*/ |
61
|
3 |
|
public static function activateModalWithIcon($active, $url, array $attributes = [], $disabled = false) |
62
|
|
|
{ |
63
|
3 |
|
$dataAttribute = 'data-current-status'; |
64
|
|
|
$statuses = [ |
65
|
3 |
|
'enabled' => 'enabled', |
66
|
1 |
|
'disabled' => 'disabled', |
67
|
1 |
|
]; |
68
|
|
|
|
69
|
3 |
|
return static::activateIcon( ! $active, $url, $attributes, $disabled) |
|
|
|
|
70
|
3 |
|
->setAttribute($dataAttribute, $statuses[$active ? 'enabled' : 'disabled']) |
71
|
3 |
|
->size('sm') |
72
|
3 |
|
->withTitle(true) |
73
|
3 |
|
->tooltip(false); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.