PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.15
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.15
6.2.15 6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 All 197 releases
fluentform / app / Services / FormBuilder / BaseFieldManager.php

BaseFieldManager.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.15, at app/Services/FormBuilder/BaseFieldManager.php

135 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\FormBuilder;
4
5 defined('ABSPATH') or die;
6
7 use FluentForm\App\Services\FormBuilder\Components\BaseComponent;
8
9 abstract class BaseFieldManager extends BaseComponent
10 {
11 protected $key = '';
12 protected $title = '';
13 protected $tags = [];
14 protected $position = 'advanced';
15
16 public function __construct($key, $title, $tags = [], $position = 'advanced')
17 {
18 parent::__construct();
19 $this->key = $key;
20 $this->position = $position;
21 $this->title = $title;
22 $this->tags = $tags;
23 $this->register();
24 }
25
26 public function register()
27 {
28 add_filter('fluentform/editor_components', [$this, 'pushComponent']);
29 add_filter('fluentform/editor_element_settings_placement', [$this, 'pushEditorElementPositions']);
30 add_filter('fluentform/editor_element_search_tags', [$this, 'pushTags'], 10, 2);
31 add_action('fluentform/render_item_' . $this->key, [$this, 'render'], 10, 2);
32 /*
33 * This is internal use.
34 * Push field type to the fluentform field types to be available in FormFieldParser.
35 */
36 add_filter('fluentform/form_input_types', [$this, 'pushFormInputType']);
37
38 add_filter('fluentform/editor_element_customization_settings', function ($settings) {
39 if ($customSettings = $this->getEditorCustomizationSettings()) {
40 $settings = array_merge($settings, $customSettings);
41 }
42
43 return $settings;
44 });
45
46 add_filter('fluentform/supported_conditional_fields', [$this, 'pushConditionalSupport']);
47 }
48
49 public function pushConditionalSupport($conditonalItems)
50 {
51 $conditonalItems[] = $this->key;
52 return $conditonalItems;
53 }
54
55 public function pushFormInputType($types)
56 {
57 $types[] = $this->key;
58 return $types;
59 }
60
61 public function pushComponent($components)
62 {
63 $component = $this->getComponent();
64
65 if ($component) {
66 $components[$this->position][] = $component;
67 }
68
69 return $components;
70 }
71
72 public function pushEditorElementPositions($placement_settings)
73 {
74 $placement_settings[$this->key] = [
75 'general' => $this->getGeneralEditorElements(),
76 'advanced' => $this->getAdvancedEditorElements(),
77 'generalExtras' => $this->generalEditorElement(),
78 'advancedExtras' => $this->advancedEditorElement(),
79 ];
80
81 return $placement_settings;
82 }
83
84 public function generalEditorElement()
85 {
86 return [];
87 }
88
89 public function advancedEditorElement()
90 {
91 return [];
92 }
93
94 public function getGeneralEditorElements()
95 {
96 return [
97 'label',
98 'admin_field_label',
99 'placeholder',
100 'label_placement',
101 'validation_rules',
102 ];
103 }
104
105 public function getAdvancedEditorElements()
106 {
107 return [
108 'name',
109 'help_message',
110 'container_class',
111 'class',
112 // Only surfaces on fields whose component declares attributes.autocomplete.
113 'autocomplete',
114 'conditional_logics',
115 ];
116 }
117
118 public function getEditorCustomizationSettings()
119 {
120 return [];
121 }
122
123 public function pushTags($tags, $form)
124 {
125 if ($this->tags) {
126 $tags[$this->key] = $this->tags;
127 }
128 return $tags;
129 }
130
131 abstract public function getComponent();
132
133 abstract public function render($element, $form);
134 }
135