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 / active-campaign / methods / contact-modifier.php

contact-modifier.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at modules/active-campaign/methods/contact-modifier.php

95 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace JFB_Modules\Active_Campaign\Methods;
5
6 use Jet_Form_Builder\Actions\Methods\Abstract_Modifier;
7 use Jet_Form_Builder\Actions\Methods\Object_Properties_Collection;
8 use Jet_Form_Builder\Classes\Arrayable\Collection;
9 use Jet_Form_Builder\Exceptions\Action_Exception;
10
11 // If this file is called directly, abort.
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 class Contact_Modifier extends Abstract_Modifier {
17
18 public $token;
19 public $url;
20
21 protected function get_actions(): Collection {
22 return new Collection(
23 array(
24 new Sync_Contact_Action(),
25 )
26 );
27 }
28
29 protected function get_properties(): Object_Properties_Collection {
30 return new Object_Properties_Collection(
31 array(
32 new Email_Contact_Property(),
33 new First_Name_Contact_Property(),
34 new Last_Name_Contact_Property(),
35 new Phone_Contact_Property(),
36 new List_Contact_Property(),
37 new Tags_Contact_Property(),
38 new Custom_Contact_Property(),
39 )
40 );
41 }
42
43 /**
44 * @throws Action_Exception
45 */
46 public function run() {
47 if ( empty( $this->url ) || empty( $this->token ) ) {
48 throw new Action_Exception( 'invalid_api_key' );
49 }
50
51 parent::run();
52 }
53
54 /**
55 * Convert legacy properties.
56 * Custom properties converting in
57 * \JFB_Modules\Active_Campaign\Methods\Custom_Contact_Property
58 *
59 * @param array $fields_map
60 * @param bool $revert
61 *
62 * @return Abstract_Modifier|Contact_Modifier
63 */
64 public function set_fields_map( array $fields_map, bool $revert = false ): Abstract_Modifier {
65 parent::set_fields_map( $fields_map, $revert );
66
67 $legacy = array(
68 'first_name' => 'firstName',
69 'last_name' => 'lastName',
70 );
71
72 foreach ( $this->fields_map as $field_name => $property ) {
73 if ( ! isset( $legacy[ $property ] ) ) {
74 continue;
75 }
76 $this->fields_map[ $field_name ] = $legacy[ $property ];
77 }
78
79 return $this;
80 }
81
82
83 public function set_api_key( string $token ): self {
84 $this->token = $token;
85
86 return $this;
87 }
88
89 public function set_api_url( string $url ): self {
90 $this->url = $url;
91
92 return $this;
93 }
94 }
95