{"id":2717,"date":"2020-08-18T11:08:58","date_gmt":"2020-08-18T11:08:58","guid":{"rendered":"https:\/\/fluentforms.com\/?post_type=docs&#038;p=2717"},"modified":"2023-07-25T06:13:33","modified_gmt":"2023-07-25T06:13:33","password":"","slug":"integrationmanager-class","status":"publish","type":"docs","link":"https:\/\/fluentforms.com\/docs\/integrationmanager-class\/","title":{"rendered":"Integration Manager Class"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"0-toc-title\">Introduction<\/h2>\n\n\n\n<p>The Fluent Forms Integration Manager Class provides developers with a very easy &amp; simple solution to add new integration in a time-effective way. Follow this documentation to create your own Integration.<\/p>\n\n\n\n<p>You just need to provide your Integration settings data structure and the fields will be automatically generated for you. Please check this <a href=\"https:\/\/fluentforms.com\/docs\/integration-feed-fields-api\/\">Integration Feed &#8211; Fields API<\/a> for the available input component that you can use for your integration settings.<\/p>\n\n\n\n<p>You can extend this class to create your own Integration. Include the class using the following namespace.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">use \\FluentForm\\App\\Services\\Integrations\\IntegrationManager;<\/code><\/pre>\n\n\n\n<p> This class file location: \/plugins\/fluentform\/app\/Services\/Integrations\/IntegrationManager.php.<\/p>\n\n\n\n<p>Please checkout the <a href=\"https:\/\/github.com\/fluentform\/fluentform\/blob\/master\/app\/Services\/Integrations\/BaseIntegration.php\" target=\"_blank\" rel=\"noopener\">github<\/a> file to get more information.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Methods<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">__construct()<\/h3>\n\n\n\n<p>This is the construct method of this class. This method needs to override. You have to pass a Application object and a few other required parameters. To pass Application object you can include it using the following namespace<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">use \\FluentForm\\Framework\\Foundation\\Application;<\/pre>\n\n\n\n<p>Here is an example of how you can override. You can use the following filter <em>fluentform_notifying_async_<\/em>{{integrationKey}} when developing the integration it will make debugging easier.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">public function __construct(Application $application)\n{\n    parent::__construct(\n        $application,\n        'MyAwesomeIntegration',                           \/\/ title\n        'myIntegrationKey',                               \/\/ integration key\n        'my_integration_details',                         \/\/ option key\n        'my_integration_feed',                            \/\/ settings key\n        11                                                \/\/ priority \n    );\n\n    $this->description = '';                              \/\/ Integration details\n \n    $this->logo = '\/my-integration-image-file-path.png';  \/\/ Integration Logo\n    $this->registerAdminHooks();                          \/\/ Internal Functions\n    \n\/\/  add_filter('fluentform\/notifying_async_{integrationKey}', '__return_false');\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">getGlobalFields()<\/h3>\n\n\n\n<p>This method will need to return the settings data format for the integration API connection. You have to keep the structure as same as the example.  This setting will store the API key &amp; additional required data to connect with your Integration API.<\/p>\n\n\n\n<p>Here is an <strong>example<\/strong> of the data format.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[\n    'logo'             =&gt; $this-&gt;logo,                                         \/\/ Logo Path which was set in constructor\n    'menu_title'       =&gt; __('Integration Settings', 'fluentform'),            \/\/ Integration Settins Title\n    'menu_description' =&gt; __('Description', 'fluentform'),                     \/\/ Integration Settins Details\n    'valid_message'    =&gt; __('Your API Key is valid', 'fluentform'),           \/\/ Valid API Message \n    'invalid_message'  =&gt; __('Your API Key is not valid', 'fluentform'),       \/\/ Invalid API Message\n    'save_button_text' =&gt; __('Save Settings', 'fluentform'),                   \/\/ Settings Save Button tTxt\n    'fields'           =&gt; [\n        'apiKey' =&gt; [\n            'type'       =&gt; 'text',                                            \/\/ API key type\n            'label_tips' =&gt; __(\"Enter your Integration API Key\", 'fluentform'),\/\/ Additional help text\n            'label'      =&gt; __('Integration API Key', 'fluentform'),           \/\/ Input Label\n        ]\n    ],\n    'hide_on_valid'    =&gt; true,                                                \/\/ Settings Input will be hidden on valid \n    'discard_settings' =&gt; [\n        'section_description' =&gt; 'Your AwesomeIntegration is Activated',       \/\/ Discard Settings Page Description\n        'button_text'         =&gt; 'Disconnect AwesomeIntegration',              \/\/ Discard Button Text\n        'data'                =&gt; [\n            'apiKey' =&gt; ''                                                     \/\/ Set API key to empty on discard\n        ],\n        'show_verify'         =&gt; true                                          \/\/ Show verification Option\n    ]\n];<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">getGlobalSettings()<\/h3>\n\n\n\n<p>In this method, you will need to get your settings data using your option key and your default settings for the Settings. You will get one parameter here<strong> $settings<\/strong>.<\/p>\n\n\n\n<p>Here is an <strong>example<\/strong> of the method:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\"> public function getGlobalSettings($settings)\n    {\n        $globalSettings = get_option($this-&gt;optionKey);\n        if (!$globalSettings) {\n            $globalSettings = [];\n        }\n        $defaults = [\n            'apiKey' =&gt; '',\n            'status' =&gt; ''\n        ];\n\n        return wp_parse_args($globalSettings, $defaults);\n    }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">saveGlobalSettings()<\/h3>\n\n\n\n<p>Here you will get the settings data after user submission and you can use the data to connect with your API or do your required task. Then save the data or return the error using your own validation.<\/p>\n\n\n\n<p>For <strong>example<\/strong> :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">public function saveGlobalSettings($settings)\n    {\n        if (!$settings['apiKey']) {\n            $mySettings = [\n                'apiKey' =&gt; '',\n                'status' =&gt; false\n            ];\n            \n            update_option($this-&gt;optionKey, $mySettings, 'no');\n            wp_send_json_success([\n                'message' =&gt; __('Your settings has been updated and disconnected', 'fluentform'),\n                'status'  =&gt; false\n            ], 200);\n        }\n\n        \/\/ Verify API key\n        try {\n             \n        \/\/ Connect with your api using the apiKey\n        \/\/ Your code\n            \n        } catch (\\Exception $exception) {\n            wp_send_json_error([\n                'message' =&gt; $exception-&gt;getMessage()\n            ], 400);\n        }\n\n        \/\/ API key is verified now\n        $settings = [\n            'apiKey' =&gt; sanitize_text_field($settings['apiKey']),\n            'status' =&gt; true\n        ];\n\n        \/\/ Update options with the key\n        update_option($this-&gt;optionKey, $settings, 'no`');\n\n        wp_send_json_success([\n            'message' =&gt; __('Your MyAwesomeIntegration api key has been verfied and successfully set', 'fluentform'),\n            'status'  =&gt; true\n        ], 200);\n    }<\/code><\/pre>\n\n\n\n<p>After you have successfully completed this step along with the previous methods, your integration will appear int the fluent form modules list.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-24-1024x373.png\" alt=\"\" class=\"wp-image-2753\" width=\"869\" height=\"316\" srcset=\"https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-24-1024x373.png 1024w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-24-300x109.png 300w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-24-768x280.png 768w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-24-1536x560.png 1536w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-24-2048x746.png 2048w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-24-150x55.png 150w\" sizes=\"auto, (max-width: 869px) 100vw, 869px\" \/><\/figure>\n\n\n\n<p>After you enable your new integration, you can go to the integration settings page where settings will be displayed according to your global field settings from getGlobalFields.<\/p>\n\n\n\n<p>After the integration is up and running the integration needs to be pushed in the form feed, so a user can use this in his form. The following method will achieve this.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">pushIntegration()<\/h3>\n\n\n\n<p>Adding your integration into the form feeds. Here you will get  two parameters <strong>$integrations, $formId<\/strong>, <\/p>\n\n\n\n<p>Here is the screenshot when the integration is pushed :<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-25-1024x238.png\" alt=\"\" class=\"wp-image-2757\" width=\"870\" height=\"201\" srcset=\"https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-25-1024x238.png 1024w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-25-300x70.png 300w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-25-768x178.png 768w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-25-1536x356.png 1536w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-25-2048x475.png 2048w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-25-150x35.png 150w\" sizes=\"auto, (max-width: 870px) 100vw, 870px\" \/><\/figure>\n\n\n\n<p>If the integration is configured it will push the integration into the form feed or else it will show a message to configure the API. The isConfigured() method, to check if the integration is configured is built in, you just need to call it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">public function pushIntegration($integrations, $formId)\n{\n    $integrations[$this-&gt;integrationKey] = [\n        'title'                 =&gt; $this-&gt;title . ' Integration',\n        'logo'                  =&gt; $this-&gt;logo,\n        'is_active'             =&gt; $this-&gt;isConfigured(),\n        'configure_title'       =&gt; 'Configuration required!',\n        'global_configure_url'  =&gt; admin_url('admin.php?page=fluent_forms_settings#{your settings page url}'),\n        'configure_message'     =&gt; 'MyAwesomeIntegration is not configured yet! Please configure your API first',\n        'configure_button_text' =&gt; 'Set MyAwesomeIntegration API'\n    ];\n    return $integrations;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">getIntegrationDefaults()<\/h3>\n\n\n\n<p>This method will return your Integration feed setting&#8217;s default data format.  You will get two parameters here <strong>$settings, $formId<\/strong>. Here is an example of this method. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[\n    'name'                   =&gt; '',\n    'id'                     =&gt; '',\n    'fieldEmailAddress'      =&gt; '',\n    'custom_field_mappings'  =&gt; (object)[],\n    'default_fields'         =&gt; (object)[],\n    'conditionals'           =&gt; [\n                   'conditions' =&gt; [],\n                   'status'     =&gt; false,\n                   'type'       =&gt; 'all'\n    ],\n    'enabled' =&gt; true\n];<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">getSettingsFields()<\/h3>\n\n\n\n<p>This&nbsp;method&nbsp;will&nbsp;render&nbsp;input&nbsp;fields&nbsp;for&nbsp;the&nbsp;integration&nbsp;feed&nbsp;settings&nbsp;page,&nbsp;based&nbsp;on&nbsp;the&nbsp;returned&nbsp;input&nbsp;data&nbsp;format. You will get two parameters here <strong>$settings, $formId<\/strong>.<\/p>\n\n\n\n<p> You can use the prebuilt input component to create your settings page, here is a documentation <a href=\"https:\/\/fluentforms.com\/docs\/integration-feed-fields-api\/\">link<\/a> where you can find the details list of these input components.<\/p>\n\n\n\n<p>Required properties for the fields:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>key: Settings Unique Key<\/li>\n\n\n\n<li>label: Settings Input Label <\/li>\n\n\n\n<li>component: Pass the prebuild input component.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[\n    'fields' =&gt; [\n        [\n            'key'           =&gt; 'name',\n            'label'         =&gt; 'Name',\n            'required'      =&gt; true,\n            'placeholder'   =&gt; 'Your Feed Name',\n            'component'     =&gt; 'text'\n        ],\n\n        [\n            'key'            =&gt; 'additional_fields',\n            'label'          =&gt; 'Integration Fields',\n            'sub_title'      =&gt; 'Please specify the data ',\n            'required'       =&gt; true,\n            'component'      =&gt; 'map_fields',\n            'primary_fileds' =&gt; [\n                [\n                    'key'           =&gt; 'fieldEmailAddress',\n                    'label'         =&gt; 'Email Address',\n                    'required'      =&gt; true,\n                    'input_options' =&gt; 'emails'\n                ]\n            ],\n            'default_fields' =&gt; [\n                [\n                    'name'     =&gt; 'first_name',\n                    'label'    =&gt; esc_html__('First Name', 'fluentformpro'),\n                    'required' =&gt; false\n                ],\n                [\n                    'name'     =&gt; 'last_name',\n                    'label'    =&gt; esc_html__('Last Name', 'fluentformpro'),\n                    'required' =&gt; false\n                ],\n\n            ]\n        ],\n        [\n            'key'        =&gt; 'conditionals',\n            'label'      =&gt; 'Conditional Logics',\n            'tips'       =&gt; 'Push data to your Integration conditionally based on your submission values',\n            'component'  =&gt; 'conditional_block'\n        ],\n        [\n            'key'            =&gt; 'enabled',\n            'label'          =&gt; 'Status',\n            'component'      =&gt; 'checkbox-single',\n            'checkbox_label' =&gt; 'Enable This feed'\n        ]\n    ],\n    'integration_title' =&gt; $this-&gt;title\n];<\/code><\/pre>\n\n\n\n<p>All your input fields will be generated dynamically based on your provided data. You can later fetch this data using your input keys and use it as you need in your integration after form submission. Here is an output screenshot of the above data format.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-26-1024x547.png\" alt=\"\" class=\"wp-image-2762\" width=\"869\" height=\"463\" srcset=\"https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-26-1024x547.png 1024w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-26-300x160.png 300w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-26-768x410.png 768w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-26-1536x820.png 1536w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-26-150x80.png 150w, https:\/\/fluentforms.com\/wp-content\/uploads\/2020\/08\/image-26.png 2016w\" sizes=\"auto, (max-width: 869px) 100vw, 869px\" \/><\/figure>\n\n\n\n<p>In the default settings getIntegrationDefaults() we gave a value &#8216;enabled&#8217; as true, that is why you can see that the field with this key &#8216;checkbox-single&#8217; is checked which means it is true. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">getMergeFields()<\/h3>\n\n\n\n<p>In this method, you will get three parameters <strong>$list, $listId, and $formId<\/strong>.<\/p>\n\n\n\n<p>This method is called after every select option change. When you have fields depending on one another, you need to modify subfields based on a primary field you can use this method and return modified data based on one primary field. <\/p>\n\n\n\n<p>For reference check the Mailchimp integration<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/fluentform\/fluentform\/blob\/master\/app\/Services\/Integrations\/MailChimp\/MailChimpIntegration.php\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/fluentform\/fluentform\/blob\/master\/app\/Services\/Integrations\/MailChimp\/MailChimpIntegration.php<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">notify()<\/h3>\n\n\n\n<p>This method will be called upon form submission, you will get four parameters <strong>$feed, $formData, $entry, <a href=\"https:\/\/fluentforms.com\/docs\/form-object\/\">$form<\/a><\/strong>. This is the most important method, here you will your necessary task upon form submission <\/p>\n\n\n\n<p>Here is a filter that you can use to validate your settings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Further read<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">fluentform\/save_integration_value_{integrationKey}<\/h3>\n\n\n\n<p>Filter hook for validating integration settings.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">add_filter('fluentform\/save_integration_value_{integrationKey} 'yourValidationMethodBeforeSave'), 10, 2);<\/pre>\n\n\n\n<p>Example of  a validation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\"> public function yourValidationMethodBeforeSave($settings, $integrationId)\n    {   \n        try {\n            $error =\"\";                                   \/\/ check your conditions\n            if( $error){\n                throw new \\Exception('Error message ');   \/\/ throw error\n            }\n           \n\n\n        } catch (\\Exception $e) {\n            wp_send_json_error([\n                'message' =&gt; $e-&gt;getMessage(),\n                'status' =&gt; false\n            ], 400);\n        }\n\n        return $settings;\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The Fluent Forms Integration Manager Class provides developers with a very easy &amp; simple solution to add new integration in a time-effective way. Follow this documentation to create your own Integration. You just need to provide your Integration settings data structure and the fields will be automatically generated for you. Please check this Integration&#8230;<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"doc_category":[22],"doc_tag":[],"knowledge_base":[264],"class_list":["post-2717","docs","type-docs","status-publish","hentry","doc_category-reference-api-classes","knowledge_base-developer-documentation"],"acf":[],"year_month":"2026-06","word_count":1419,"total_views":"889","reactions":{"happy":"2","normal":"0","sad":"2"},"author_info":{"display_name":"Alex Sanchez","author_link":"https:\/\/fluentforms.com\/author\/alexwpmanageninja-com\/"},"doc_category_info":[{"term_name":"Reference API Classes","term_url":"https:\/\/fluentforms.com\/docs\/developer-documentation\/reference-api-classes\/"}],"doc_tag_info":[],"taxonomy_info":{"doc_category":[{"value":22,"label":"Reference API Classes"}],"knowledge_base":[{"value":264,"label":"Developer Documentation"}]},"featured_image_src_large":false,"comment_info":0,"knowledge_base_info":[{"term_name":"Developer Documentation","term_url":"https:\/\/fluentforms.com\/docs\/developer-documentation\/","term_slug":"developer-documentation"}],"knowledge_base_slug":["developer-documentation"],"_links":{"self":[{"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/docs\/2717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/comments?post=2717"}],"version-history":[{"count":0,"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/docs\/2717\/revisions"}],"wp:attachment":[{"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/media?parent=2717"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/doc_category?post=2717"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/doc_tag?post=2717"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/fluentforms.com\/wp-json\/wp\/v2\/knowledge_base?post=2717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}