PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / modules / actions-v2 / insert-term / insert-term-action.php

insert-term-action.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at modules/actions-v2/insert-term/insert-term-action.php

118 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace JFB_Modules\Actions_V2\Insert_Term;
4
5 use Jet_Form_Builder\Actions\Action_Handler;
6 use JFB_Modules\Actions_V2\Insert_Term\Properties\Abstract_Term_Modifier;
7 use JFB_Modules\Actions_V2\Insert_Term\Properties\Term_Modifier;
8 use Jet_Form_Builder\Actions\Types\Base;
9 use Jet_Form_Builder\Classes\Arrayable\Array_Tools;
10 use Jet_Form_Builder\Classes\Tools;
11
12 // If this file is called directly, abort.
13 if ( ! defined( 'WPINC' ) ) {
14 die;
15 }
16
17 /**
18 * Define Base_Type class
19 */
20 class Insert_Term_Action extends Base {
21
22 public function get_name() {
23 return __( 'Insert/Update Term', 'jet-form-builder' );
24 }
25
26 public function get_id() {
27 return 'insert_term';
28 }
29
30 public function action_attributes() {
31 return array(
32 'taxonomy' => array(
33 'default' => '',
34 ),
35 'fields_map' => array(
36 'default' => array(),
37 ),
38 'default_meta' => array(
39 'default' => array(),
40 ),
41 );
42 }
43
44 /**
45 * @param array $request
46 * @param Action_Handler $handler
47 *
48 * @return void
49 */
50 public function do_action( array $request, Action_Handler $handler ) {
51 $modifiers = array_reverse( $this->get_modifiers() );
52
53 /** @var Abstract_Term_Modifier $modifier */
54 foreach ( $modifiers as $modifier ) {
55 if ( ! $modifier->is_supported( $this ) ) {
56 continue;
57 }
58
59 $modifier->before_run( $this );
60 $modifier->run();
61 break;
62 }
63 }
64
65 public function get_taxonomy(): string {
66 return $this->settings['taxonomy'] ?? '';
67 }
68
69 public static function get_context_term_key( $term_id ) {
70 return "term-id-{$term_id}";
71 }
72
73 public function editor_labels() {
74 return array(
75 'taxonomy' => __( 'Taxonomy:', 'jet-form-builder' ),
76 'fields_map' => __( 'Fields Map:', 'jet-form-builder' ),
77 );
78 }
79
80 /**
81 * Regsiter custom action data for the editor
82 *
83 * @return [type] [description]
84 */
85 public function action_data() {
86 $properties = array();
87 $modifiers = $this->get_modifiers();
88
89 foreach ( $modifiers as $modifier ) {
90 $properties[ $modifier->get_id() ] = Tools::with_placeholder(
91 Array_Tools::to_array( $modifier->properties->all() )
92 );
93 }
94
95 return array(
96 'taxonomies' => Tools::get_taxonomies_for_modify(),
97 'properties' => $properties,
98 );
99 }
100
101 /**
102 * Just add a new element to the end.
103 * When the action is executed, this array is flipped,
104 * which puts the \Jet_Form_Builder\Actions\Methods\Post_Modifier at the end.
105 *
106 * @return Abstract_Post_Modifier[]
107 * @since 2.1.4
108 */
109 public function get_modifiers(): array {
110 return apply_filters(
111 'jet-form-builder/action/insert-term/modifiers',
112 array(
113 new Term_Modifier(),
114 )
115 );
116 }
117 }
118