|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* GravityView_Default_Template_Table class. |
|
5
|
|
|
* Defines Table(default) template |
|
6
|
|
|
*/ |
|
7
|
|
|
class GravityView_Default_Template_Table extends GravityView_Template { |
|
8
|
|
|
|
|
9
|
|
|
function __construct( $id = 'default_table', $settings = array(), $field_options = array(), $areas = array() ) { |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @filter `gravityview/template/table/use-legacy-style` Should GravityView use the legacy Table layout stylesheet (from before Version 2.1)? |
|
13
|
|
|
* @since 2.1.1 |
|
14
|
|
|
* @param bool $use_legacy_table_style If true, loads `table-view-legacy.css`. If false, loads `table-view.css`. Default: `false` |
|
15
|
|
|
*/ |
|
16
|
|
|
$use_legacy_table_style = apply_filters( 'gravityview/template/table/use-legacy-style', false ); |
|
17
|
|
|
|
|
18
|
|
|
$css_filename = 'table-view.css'; |
|
19
|
|
|
|
|
20
|
|
|
if ( $use_legacy_table_style ) { |
|
21
|
|
|
$css_filename = 'table-view-legacy.css'; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
$table_settings = array( |
|
25
|
|
|
'slug' => 'table', |
|
26
|
|
|
'type' => 'custom', |
|
27
|
|
|
'label' => __( 'Table', 'gravityview' ), |
|
28
|
|
|
'description' => __( 'Display items in a table view.', 'gravityview' ), |
|
29
|
|
|
'logo' => plugins_url( 'includes/presets/default-table/logo-default-table.png', GRAVITYVIEW_FILE ), |
|
30
|
|
|
'css_source' => gravityview_css_url( $css_filename, GRAVITYVIEW_DIR . 'templates/css/' ), |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
$settings = wp_parse_args( $settings, $table_settings ); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @see GravityView_Admin_Views::get_default_field_options() for Generic Field Options |
|
37
|
|
|
* @var array |
|
38
|
|
|
*/ |
|
39
|
|
|
$field_options = array( |
|
40
|
|
|
'show_as_link' => array( |
|
41
|
|
|
'type' => 'checkbox', |
|
42
|
|
|
'label' => __( 'Link to single entry', 'gravityview' ), |
|
43
|
|
|
'value' => false, |
|
44
|
|
|
'context' => 'directory' |
|
45
|
|
|
), |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
$areas = array( |
|
49
|
|
|
array( |
|
50
|
|
|
'1-1' => array( |
|
51
|
|
|
array( |
|
52
|
|
|
'areaid' => 'table-columns', |
|
53
|
|
|
'title' => __( 'Visible Table Columns', 'gravityview' ), |
|
54
|
|
|
'subtitle' => __( 'Each field will be displayed as a column in the table.', 'gravityview' ), |
|
55
|
|
|
) |
|
56
|
|
|
) |
|
57
|
|
|
) |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
$this->add_hooks(); |
|
61
|
|
|
|
|
62
|
|
|
parent::__construct( $id, $settings, $field_options, $areas ); |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Adds hooks specific to this template |
|
68
|
|
|
* |
|
69
|
|
|
* @since 2.8.1 |
|
70
|
|
|
*/ |
|
71
|
|
|
private function add_hooks() { |
|
|
|
|
|
|
72
|
|
|
add_filter( 'gravityview/admin/add_button_label', array( $this, 'maybe_modify_button_label' ), 10, 2 ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Changes the button label to reflect that fields = rows |
|
77
|
|
|
* |
|
78
|
|
|
* @internal |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $label Text for button: "Add Widget" or "Add Field" |
|
81
|
|
|
* @param array $atts { |
|
82
|
|
|
* @type string $type 'widget' or 'field' |
|
83
|
|
|
* @type string $template_id The current slug of the selected View template |
|
84
|
|
|
* @type string $zone Where is this button being shown? Either 'single', 'directory', 'edit', 'header', 'footer' |
|
85
|
|
|
* } |
|
86
|
|
|
* |
|
87
|
|
|
* @return string|void |
|
88
|
|
|
*/ |
|
89
|
|
|
public function maybe_modify_button_label( $label = '', $atts = array() ) { |
|
90
|
|
|
|
|
91
|
|
|
if( $this->template_id !== \GV\Utils::get( $atts, 'template_id' ) ) { |
|
92
|
|
|
return $label; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if( 'field' !== \GV\Utils::get( $atts, 'type' ) ) { |
|
96
|
|
|
return $label; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if( 'edit' === \GV\Utils::get( $atts, 'zone' ) ) { |
|
100
|
|
|
return $label; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return __( 'Add Table Column', 'gravityview' ); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
new GravityView_Default_Template_Table; |
|
108
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.