forked from tyxla/gravity-forms-section-tabs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-gf-section-tabs-addon.php
More file actions
106 lines (90 loc) · 2.69 KB
/
class-gf-section-tabs-addon.php
File metadata and controls
106 lines (90 loc) · 2.69 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
99
100
101
102
103
104
105
106
<?php
class GFSectionTabsAddon extends GFAddOn {
// addon version
protected $_version = "1.0";
// minimum Gravity Forms version
protected $_min_gravityforms_version = "1.7.9999";
// addon slug
protected $_slug = "gravityforms-section-tabs";
// addon relative path
protected $_path = "gravityforms-section-tabs/gravityforms-section-tabs.php";
// addon absolute path
protected $_full_path = __FILE__;
// addon URL
protected $_url = "https://github.com/tyxla/gravity-forms-section-tabs";
// addon name
protected $_title = "Gravity Forms: Section Tabs";
// addon short name
protected $_short_title = "Section Tabs";
// our constructor - hooks addon-specific functionality
public function __construct() {
parent::__construct();
// add our CSS class to forms with section tabs enabled
add_filter('gform_pre_render', array($this, 'gform_pre_render'), 10, 3);
}
// register the fields within the form settings
public function form_settings_fields($form) {
return array(
array(
"title" => "Section Tabs",
"fields" => array(
// whether to enable the Section Tabs for the particular form
array(
"label" => "Enable Section Tabs",
"type" => "checkbox",
"name" => "enable_section_tabs",
"tooltip" => "If enabled, will turn each section into a tab, containing all fields below it until the next section.",
"choices" => array(
array(
"label" => "Enabled",
"name" => "enable_section_tabs"
)
)
)
)
)
);
}
// enqueue styles
public function styles() {
return array_merge(parent::styles(), array(
// main frontend CSS file
array(
'handle' => 'gravity_forms_section_tabs_main',
'src' => $this->get_base_url() . '/css/main.css',
'version' => $this->_version,
'enqueue' => array(
array('field_types' => array('section'))
)
)
));
}
// enqueue scripts
public function scripts() {
return array_merge(parent::scripts(), array(
// main frontend JS file
array(
'handle' => 'gravity_forms_section_tabs_main',
'src' => $this->get_base_url() . '/js/main.js',
'version' => $this->_version,
'deps' => array('jquery'),
'in_footer' => true,
'enqueue' => array(
array('field_types' => array('section'))
)
)
));
}
// add a specific CSS class to forms with section tabs enabled
public function gform_pre_render($form, $ajax, $field_values = array()) {
if (!empty($form['gravityforms-section-tabs']['enable_section_tabs'])) {
$classname = 'gravity_forms_section_tabs_enabled';
if (empty($form['cssClass'])) {
$form['cssClass'] = $classname;
} else {
$form['cssClass'] .= ' ' . $classname;
}
}
return $form;
}
}