-
-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathColumn.php
More file actions
175 lines (157 loc) · 3.74 KB
/
Column.php
File metadata and controls
175 lines (157 loc) · 3.74 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
namespace Statamic\CP;
use Statamic\Support\Str;
use Statamic\Support\Traits\FluentlyGetsAndSets;
class Column
{
use FluentlyGetsAndSets;
public $field;
public $fieldtype;
public $label;
public $numeric = false;
public $listable = true;
public $defaultOrder;
public $defaultVisibility = true;
public $visible = true;
public $sortable = true;
public $required = false;
public $value;
/**
* Make new column instance.
*
* @param null|string $field
* @return static
*/
public static function make($field = null)
{
$column = new static;
return $field
? $column->field($field)
: $column;
}
/**
* Get or set field.
*
* @param null|string $field
* @return mixed
*/
public function field($field = null)
{
return $this
->fluentlyGetOrSet('field')
->afterSetter(function ($field) {
if (is_null($this->label)) {
$this->label(Str::slugToTitle($field), true);
}
})
->value($field);
}
/**
* Get or set the value field.
*
* @param null|string $value
* @return mixed
*/
public function value($value = null)
{
return $this->fluentlyGetOrSet('value')->value($value);
}
/**
* Get or set fieldtype.
*
* @param null|string $fieldtype
* @return mixed
*/
public function fieldtype($fieldtype = null)
{
return $this->fluentlyGetOrSet('fieldtype')->value($fieldtype);
}
/**
* Get or set label.
*
* @param null|string $label
* @return mixed
*/
public function label($label = null)
{
return $this->fluentlyGetOrSet('label')->value($label);
}
/**
* Get or set listable. Setting `false` will override visibility.
*
* @param mixed $listable
*/
public function listable($listable = null)
{
return $this->fluentlyGetOrSet('listable')->value($listable);
}
/**
* Get or set default order, for resetting user preferences, etc.
*
* @param null|int $order
* @return mixed
*/
public function defaultOrder($order = null)
{
return $this->fluentlyGetOrSet('defaultOrder')->value($order);
}
/**
* Get or set default visibility, for resetting user preferences, etc.
*
* @param null|bool $visible
* @return mixed
*/
public function defaultVisibility($visible = null)
{
return $this->fluentlyGetOrSet('defaultVisibility')->value($visible);
}
/**
* Get or set visibility.
*
* @param null|bool $visible
* @return mixed
*/
public function visible($visible = null)
{
return $this->fluentlyGetOrSet('visible')->value($visible);
}
/**
* Get or set sortable.
*
* @param null|bool $sortable
* @return mixed
*/
public function sortable($sortable = null)
{
return $this->fluentlyGetOrSet('sortable')->value($sortable);
}
/**
* Get or set whether the column is numeric.
*
* @param bool $numeric
* @return mixed
*/
public function numeric($numeric = null)
{
return $this->fluentlyGetOrSet('numeric')->value($numeric);
}
/**
* Get or set whether the column is required.
*
* @param null|bool $required
* @return mixed
*/
public function required($required = null)
{
return $this->fluentlyGetOrSet('required')->value($required);
}
/**
* Cast column to array.
*
* return array
*/
public function toArray()
{
return (array) $this;
}
}