Completed
Pull Request — master (#1446)
by Zack
22:43 queued 19:57
created

GravityView_Default_Template_Table::add_hooks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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() ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() {
0 ignored issues
show
Bug introduced by
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
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