Field.php
2.01 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
<?php
namespace ACA\Pods\Setting;
use AC;
use AC\View;
use ACA\Pods\Column;
/**
* @property Column $column
*/
class Field extends AC\Settings\Column {
/**
* @var string
*/
private $pods_field;
protected function define_options() {
return [ 'pods_field' ];
}
public function get_dependent_settings() {
return $this->column->get_field()->get_dependent_settings();
}
public function create_view() {
$setting = $this->create_element( 'select' );
$no_result = sprintf( __( 'No %s fields available.', 'codepress-admin-columns' ), __( 'Pods', 'pods' ) );
$no_result .= ' ' . sprintf( __( 'Create your first %s field.', 'codepress-admin-columns' ), ac_helper()->html->link( $this->get_link_create_pod_field(), __( 'Pods', 'pods' ) ) );
$setting
->set_no_result( $no_result )
->set_attribute( 'data-refresh', 'column' )
->set_attribute( 'data-label', 'update' )
->set_options( $this->get_field_types() );
$view = new View();
$view->set( 'label', __( 'Field', 'codepress-admin-columns' ) )
->set( 'setting', $setting );
return $view;
}
private function get_link_create_pod_field() {
return add_query_arg( [ 'page' => 'pods-add-new' ], admin_url( 'admin.php' ) );
}
/**
* @return string
*/
public function get_pods_field() {
if ( null === $this->pods_field ) {
$this->set_pods_field( $this->get_first_pods_field() );
}
return $this->pods_field;
}
/**
* @return bool|mixed
*/
public function get_first_pods_field() {
$fields = $this->get_field_types();
reset( $fields );
return key( $fields );
}
/**
* @param string $field
*
* @return $this
*/
public function set_pods_field( $field ) {
$this->pods_field = $field;
return $this;
}
private function get_field_types() {
$options = [];
$fields = $this->column->get_pod_fields();
if ( $fields ) {
foreach ( $fields as $field ) {
$options[ $field['name'] ] = $field['label'] ?: __( 'empty label', 'codepress-admin-columns' );
}
}
natcasesort( $options );
return $options;
}
}