AttachmentDisplay.php
1.46 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
<?php
namespace AC\Settings\Column;
use AC\Settings;
use AC\View;
class AttachmentDisplay extends Settings\Column
implements Settings\FormatValue {
private $attachment_display;
protected function define_options() {
return [
'attachment_display' => 'thumbnail',
];
}
public function get_dependent_settings() {
$settings = [];
switch ( $this->get_attachment_display() ) {
case 'thumbnail' :
$settings[] = new Settings\Column\Images( $this->column );
break;
}
return $settings;
}
public function create_view() {
$setting = $this->create_element( 'select' )
->set_attribute( 'data-refresh', 'column' )
->set_options( [
'thumbnail' => __( 'Thumbnails', 'codepress-admin-columns' ),
'count' => __( 'Count', 'codepress-admin-columns' ),
] );
return new View( [
'label' => __( 'Display', 'codepress-admin-columns' ),
'setting' => $setting,
] );
}
/**
* @return int
*/
public function get_attachment_display() {
return $this->attachment_display;
}
/**
* @param int $attachment_display
*
* @return bool
*/
public function set_attachment_display( $attachment_display ) {
$this->attachment_display = $attachment_display;
return true;
}
public function format( $value, $original_value ) {
switch ( $this->get_attachment_display() ) {
case 'count':
$value = count( $value );
break;
}
return $value;
}
}