Separator.php
1.54 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
<?php
namespace AC\Settings\Column;
use AC\Collection;
use AC\Settings;
use AC\View;
class Separator extends Settings\Column
implements Settings\FormatCollection {
/**
* @var string
*/
private $separator;
protected function define_options() {
return [ 'separator' => 'comma' ];
}
public function create_view() {
$element = $this
->create_element( 'select' )
->set_options( [
'' => __( 'Default', 'codepress-admin-columns' ),
'comma' => __( 'Comma Separated', 'codepress-admin-columns' ),
'newline' => __( 'New line', 'codepress-admin-columns' ),
'none' => __( 'None', 'codepress-admin-columns' ),
'white_space' => __( 'Whitespace', 'codepress-admin-columns' ),
] );
$view = new View( [
'label' => __( 'Separator', 'codepress-admin-columns' ),
'tooltip' => __( 'Select a repeater sub field.', 'codepress-admin-columns' ),
'setting' => $element,
] );
return $view;
}
public function get_separator() {
return $this->separator;
}
public function set_separator( $separator ) {
$this->separator = $separator;
return $this;
}
public function format( Collection $collection, $original_value ) {
switch ( $this->separator ) {
case 'comma' :
$separator = ', ';
break;
case 'newline' :
$separator = "<br/>";
break;
case 'none' :
$separator = '';
break;
case 'white_space' :
$separator = ' ';
break;
default :
$separator = $this->column->get_separator();
}
return $collection->filter()->implode( $separator );
}
}