diff --git a/README.md b/README.md index be7ad42..dd5d715 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,6 @@ To use this plugin, the following is needed: ### Contribute -Please help improve this plugin by using the extension issue queue to report any troubles and to make requests for feature improvements. The issue queue is here: https://github.com/mecachisenros/caldera-forms-civicrm/issues +Please help improve this plugin by using the extension issue queue to report any troubles and to make requests for feature improvements. The issue queue is here: https://github.com/mecachisenros/cf-civicrm/issues Issues submitted to the issue queue will be addressed based on time and interest. If you are a developer contributions are welcome. diff --git a/caldera-forms-civicrm.php b/cf-civicrm.php similarity index 95% rename from caldera-forms-civicrm.php rename to cf-civicrm.php index a617064..72c97a9 100644 --- a/caldera-forms-civicrm.php +++ b/cf-civicrm.php @@ -1,13 +1,13 @@
-

+

key_name] = [ - 'field' => __( 'CiviCRM Contact Reference', 'caldera-forms-civicrm' ), + 'field' => __( 'CiviCRM Contact Reference', 'cf-civicrm' ), 'file' => CF_CIVICRM_INTEGRATION_PATH . 'fields/civicrm_contact_reference/field.php', - 'category' => __( 'CiviCRM', 'caldera-forms-civicrm' ), - 'description' => __( 'CiviCRM Contact Reference field', 'caldera-forms-civicrm' ), + 'category' => __( 'CiviCRM', 'cf-civicrm' ), + 'description' => __( 'CiviCRM Contact Reference field', 'cf-civicrm' ), 'setup' => [ 'template' => CF_CIVICRM_INTEGRATION_PATH . 'fields/civicrm_contact_reference/config.php', 'preview' => CF_CIVICRM_INTEGRATION_PATH . 'fields/civicrm_contact_reference/preview.php', 'default' => [ - 'placeholder' => __( 'Search Contacts', 'caldera-forms-civicrm' ) + 'placeholder' => __( 'Search Contacts', 'cf-civicrm' ) ], ], // 'scripts' => [ @@ -92,7 +92,7 @@ public function register_field_type( $field_types ) { * Filter current_employer mapped field value. * * @since 0.4.4 - * + * * @param string|int $mapped_field The mapped value * @param string $civi_field The field for an entity i.e. 'contact_id', 'current_employer', etc. * @param array $field The field config @@ -103,34 +103,28 @@ public function handle_current_employer_field( $mapped_field, $civi_field, $fiel if ( $field['type'] != 'civicrm_contact_reference' ) return $mapped_field; - if ( $civi_field != 'current_employer' ) return $mapped_field; - - if ( ! is_numeric( $mapped_field ) && isset( $field['config']['new_organization'] ) ) { - $employer = civicrm_api3( 'Contact', 'create', [ - 'contact_type' => 'Organization', - 'organization_name' => $mapped_field, - ] ); - } else { - $employer = civicrm_api3( 'Contact', 'get', [ - 'contact_id' => $mapped_field, - 'return' => 'organization_name' - ] ); + switch ( $civi_field ) { + case 'current_employer': + $org = $this->get_organisation( $mapped_field, $field ); + if ( $org ) return $org; + return ''; + break; + case 'organization_name': + $org = $this->get_organisation( $mapped_field, $field ); + if ( $org ) return $org['organization_name']; + return ''; + break; } - if ( isset( $employer['count'] ) && $employer['count'] ) - return [ - 'organization_name' => $employer['values'][$employer['id']]['organization_name'], - 'employer_id' => $employer['id'] - ]; - return $mapped_field; + } /** * Prerenderd default current_employer. * * @since 0.4.4 - * + * * @param string|int $value The default value * @param string $civi_field The field for an entity i.e. 'contact_id', 'current_employer', etc. * @param array $field The field config @@ -159,13 +153,13 @@ public function pre_render_current_employer_value( $value, $civi_field, $field, * Enqueue scripts * * @since 0.4.4 - * + * * @param array $form Form config * @return array $form Form config */ public function enqueue_scripts( $form ) { $reference = false; - + foreach ( $form['fields'] as $field_id => $field ) { if ( $field['type'] == 'civicrm_contact_reference' ) { $reference = true; @@ -226,4 +220,36 @@ public function field_render_summary( $field_value, $field, $form ){ return $field_value; } + /** + * Gets or creates (if it does not exist) an organisations. + * + * @since 1.0.3 + * @param int|strin $value Contact id o r organisation name + * @param array $field The field config + * @return array|bool The organisation name and contact id or false + */ + public function get_organisation( $value, $field ) { + + if ( ! is_numeric( $value ) && isset( $field['config']['new_organization'] ) ) { + $employer = civicrm_api3( 'Contact', 'create', [ + 'contact_type' => 'Organization', + 'organization_name' => $value, + ] ); + } else { + $employer = civicrm_api3( 'Contact', 'get', [ + 'contact_id' => $value, + 'return' => 'organization_name' + ] ); + } + + if ( isset( $employer['count'] ) && $employer['count'] ) + return [ + 'organization_name' => $employer['values'][$employer['id']]['organization_name'], + 'employer_id' => $employer['id'] + ]; + + return false; + + } + } diff --git a/fields/civicrm_contact_reference/config.php b/fields/civicrm_contact_reference/config.php index b371e30..3c604ef 100644 --- a/fields/civicrm_contact_reference/config.php +++ b/fields/civicrm_contact_reference/config.php @@ -1,4 +1,4 @@ - 0, 'is_active' => 1, @@ -28,7 +28,7 @@

- +

@@ -47,7 +47,7 @@

- +

@@ -66,25 +66,25 @@

- +

- +

- +

diff --git a/fields/civicrm_country/class-civicrm-country.php b/fields/civicrm_country/class-civicrm-country.php index 915c319..dd6cb91 100644 --- a/fields/civicrm_country/class-civicrm-country.php +++ b/fields/civicrm_country/class-civicrm-country.php @@ -66,15 +66,15 @@ public function register_hooks() { public function register_field_type( $field_types ) { $field_types[$this->key_name] = [ - 'field' => __( 'CiviCRM Country', 'caldera-forms-civicrm' ), + 'field' => __( 'CiviCRM Country', 'cf-civicrm' ), 'file' => CF_CIVICRM_INTEGRATION_PATH . 'fields/civicrm_country/field.php', - 'category' => __( 'CiviCRM', 'caldera-forms-civicrm' ), - 'description' => __( 'CiviCRM Country dropdown', 'caldera-forms-civicrm' ), + 'category' => __( 'CiviCRM', 'cf-civicrm' ), + 'description' => __( 'CiviCRM Country dropdown', 'cf-civicrm' ), 'setup' => [ 'template' => CF_CIVICRM_INTEGRATION_PATH . 'fields/civicrm_country/config.php', 'preview' => CF_CIVICRM_INTEGRATION_PATH . 'fields/civicrm_country/preview.php', 'default' => [ - 'placeholder' => __( 'Select a Country', 'caldera-forms-civicrm' ), + 'placeholder' => __( 'Select a Country', 'cf-civicrm' ), 'default' => $this->plugin->helper->get_civicrm_settings( 'defaultContactCountry' ) ], ], @@ -133,12 +133,12 @@ public function field_render_summary( $field_value, $field, $form ){ * Enqueue scripts * * @since 0.4.4 - * + * * @param array $form Form config * @return array $form Form config */ public function enqueue_scripts( $form ) { - + foreach ( $form['fields'] as $field_id => $field ) { if ( $field['type'] == $this->key_name ) { wp_enqueue_style( 'cfc-select2' ); diff --git a/fields/civicrm_country/config.php b/fields/civicrm_country/config.php index ad138ec..8ad5826 100644 --- a/fields/civicrm_country/config.php +++ b/fields/civicrm_country/config.php @@ -1,12 +1,12 @@ helper->get_countries(); ?>
- +
- +
- +
{{#script}} diff --git a/fields/civicrm_file/file_config.php b/fields/civicrm_file/file_config.php index 2c9637b..f9b47f7 100644 --- a/fields/civicrm_file/file_config.php +++ b/fields/civicrm_file/file_config.php @@ -3,7 +3,7 @@
+
{{#script}} diff --git a/fields/civicrm_premium/class-civicrm-premium.php b/fields/civicrm_premium/class-civicrm-premium.php index 353f15b..ab9e9ac 100644 --- a/fields/civicrm_premium/class-civicrm-premium.php +++ b/fields/civicrm_premium/class-civicrm-premium.php @@ -63,10 +63,10 @@ public function register_hooks() { public function register_field_type( $field_types ) { $field_types[$this->key_name] = [ - 'field' => __( 'CiviCRM Premium', 'caldera-forms-civicrm' ), + 'field' => __( 'CiviCRM Premium', 'cf-civicrm' ), 'file' => CF_CIVICRM_INTEGRATION_PATH . 'fields/civicrm_premium/field.php', - 'category' => __( 'CiviCRM', 'caldera-forms-civicrm' ), - 'description' => __( 'CiviCRM Premiums for Order processors', 'caldera-forms-civicrm' ), + 'category' => __( 'CiviCRM', 'cf-civicrm' ), + 'description' => __( 'CiviCRM Premiums for Order processors', 'cf-civicrm' ), 'setup' => [ 'template' => CF_CIVICRM_INTEGRATION_PATH . 'fields/civicrm_premium/config.php', 'preview' => CF_CIVICRM_INTEGRATION_PATH . 'fields/civicrm_premium/preview.php', @@ -125,7 +125,7 @@ public function filter_field_config( $field, $form ) { 'desc' => $premium['description'], 'image' => $premium['image'] ? $premium['image'] : false, 'thumbnail' => $premium['thumbnail'] ? $premium['thumbnail'] : false, - 'min' => sprintf( __( 'Minimum: %s', 'caldera-forms-civicrm' ), $premium['min_contribution'] ), + 'min' => sprintf( __( 'Minimum: %s', 'cf-civicrm' ), $premium['min_contribution'] ), 'min_clean' => $premium['min_contribution'], 'options' => $premium['options'] ? $this->to_array( $premium['options'] ) : false ]; diff --git a/fields/civicrm_premium/config.php b/fields/civicrm_premium/config.php index c333773..95b2e58 100644 --- a/fields/civicrm_premium/config.php +++ b/fields/civicrm_premium/config.php @@ -1,47 +1,47 @@

- +

- +

- +

- +

@@ -67,7 +67,7 @@
@@ -77,13 +77,13 @@
{{{_field slug="calc"}}}

- +

diff --git a/fields/civicrm_premium/field.php b/fields/civicrm_premium/field.php index 2233c27..6d63a49 100644 --- a/fields/civicrm_premium/field.php +++ b/fields/civicrm_premium/field.php @@ -7,33 +7,33 @@
@@ -93,7 +93,7 @@ class="cf-toggle-group-radio "

- +

- +
- +
-
\ No newline at end of file +
diff --git a/fields/discount/field.php b/fields/discount/field.php index ca0930f..fa588f9 100644 --- a/fields/discount/field.php +++ b/fields/discount/field.php @@ -2,14 +2,14 @@ - @@ -31,7 +31,7 @@ class="btn btn-block" form_instance = ''; if ( ! code ) return; - + $.ajax( { url: cfc.url, type: 'post', diff --git a/fields/discount/js/cividiscount.js b/fields/discount/js/cividiscount.js index f23e764..d4d07cd 100644 --- a/fields/discount/js/cividiscount.js +++ b/fields/discount/js/cividiscount.js @@ -9,6 +9,8 @@ jQuery( document ).on( 'cfc.discount.apply', function ( event, data ) { state.mutateState( field_id, option.value ); + // unbind and rebind field + state.unbind( field_id ); state.rebind( field_id ); } diff --git a/fields/hidden/config.php b/fields/hidden/config.php index 53ce438..47f9ef0 100644 --- a/fields/hidden/config.php +++ b/fields/hidden/config.php @@ -2,10 +2,10 @@

- +

-
\ No newline at end of file +
diff --git a/fields/presets/class-civicrm-core-fields-presets.php b/fields/presets/class-civicrm-core-fields-presets.php index f608e52..a2d41f0 100644 --- a/fields/presets/class-civicrm-core-fields-presets.php +++ b/fields/presets/class-civicrm-core-fields-presets.php @@ -81,14 +81,14 @@ public function payment_instrument_options_presets( $presets ) { $result = civicrm_api3( 'Contribution', 'getoptions', [ 'field' => 'payment_instrument_id', ] ); - + $options = []; foreach ( $result['values'] as $id => $method ) { $options[] = $id.'|'.$method; } $presets['payment_instrument_id'] = [ - 'name' => __( 'CiviCRM Payment Methods', 'caldera-forms-civicrm' ), + 'name' => __( 'CiviCRM Payment Methods', 'cf-civicrm' ), 'data' => $options, ]; @@ -105,43 +105,43 @@ public function payment_instrument_options_presets( $presets ) { public function autopulate_core_fields_types() { // Individual Prefix - echo ""; + echo ""; // Individual Suffix - echo ""; + echo ""; // Individual Gender - echo ""; + echo ""; // Communication Style - echo ""; + echo ""; // Do not Email - echo ""; + echo ""; // Do not Phone - echo ""; + echo ""; // Do not Mail - echo ""; + echo ""; // Do not SMS - echo ""; + echo ""; // Do not Trade - echo ""; + echo ""; // Is Opt Out - echo ""; + echo ""; // Country - echo ""; + echo ""; // State/Provine - echo ""; + echo ""; // Address Location Type - echo ""; + echo ""; // Email Location Type - echo ""; + echo ""; // Phone Location Type - echo ""; + echo ""; // Phone Type - echo ""; + echo ""; // Website Type - echo ""; + echo ""; // IM Type - echo ""; + echo ""; // Preferred Language - echo ""; + echo ""; } diff --git a/fields/presets/class-civicrm-custom-fields-presets.php b/fields/presets/class-civicrm-custom-fields-presets.php index 40fdee4..efd9932 100644 --- a/fields/presets/class-civicrm-custom-fields-presets.php +++ b/fields/presets/class-civicrm-custom-fields-presets.php @@ -35,7 +35,7 @@ class CiviCRM_Caldera_Forms_Custom_Fields_Presets { /** * The entites the custom fields extend. * - * @since 1.0 + * @since 1.0 * @access public * @var array The entities */ @@ -93,15 +93,15 @@ public function custom_fields_options_presets( $presets ) { if ( ! in_array( $field['html_type'], $this->allowed_html_types ) ) return; if ( ! in_array( $field['custom_group_id.extends'], $extends ) ) return; - + if ( ! $field['option_group_id'] ) return; - + $custom_options = $this->option_values_get( $field['option_group_id'] ); if ( ! $custom_options ) return; $presets['custom_' . $field['id']] = [ - 'name' => sprintf( __( 'CiviCRM - %1$s - %2$s', 'caldera-forms-civicrm' ), $field['custom_group_id.title'], $field['label'] ), + 'name' => sprintf( __( 'CiviCRM - %1$s - %2$s', 'cf-civicrm' ), $field['custom_group_id.title'], $field['label'] ), 'data' => array_reduce( $custom_options, function( $options, $option ) { $options[] = $option['value'] . '|' . $option['label']; return $options; @@ -130,16 +130,16 @@ public function autopopulate_custom_fields_types() { if ( ! $custom_fields ) return; $extends = $this->entities_extend_get(); - + array_map( function( $field ) use ( $extends ) { if ( ! in_array( $field['html_type'], $this->allowed_html_types ) ) return; if ( ! in_array( $field['custom_group_id.extends'], $extends ) ) return; - + if ( ! $field['option_group_id'] ) return; - echo ""; + echo ""; }, $custom_fields ); @@ -198,7 +198,7 @@ public function autopopulate_custom_fields_values( $field, $form ) { * * @return array|bool $custom_fields The custom fields, or false */ - public function custom_fields_get( ) { + public function custom_fields_get() { // return data if it's already retrieved if ( ! empty( $this->custom_fields ) ) return $this->custom_fields; @@ -213,12 +213,12 @@ public function custom_fields_get( ) { if ( ! is_array( $custom_fields ) && ! $custom_fields['count'] ) return false; - + // get option values // $option_group_ids = array_column( $custom_fields['values'], 'option_group_id' ); $this->custom_fields = $custom_fields['values']; - + return $this->custom_fields; } @@ -234,7 +234,8 @@ public function option_values_get( $option_group_id ) { $option_values = civicrm_api3( 'OptionValue', 'get', [ 'sequential' => 1, - 'option_group_id' => $option_group_id + 'option_group_id' => $option_group_id, + 'options' => ['limit' => 0, 'sort' => "weight ASC"], ] ); if ( $option_values['count'] && ! $option_values['is_error'] ) return $option_values['values']; diff --git a/fields/presets/class-civicrm-price-sets-presets.php b/fields/presets/class-civicrm-price-sets-presets.php index 9124149..68e8058 100644 --- a/fields/presets/class-civicrm-price-sets-presets.php +++ b/fields/presets/class-civicrm-price-sets-presets.php @@ -85,7 +85,7 @@ public function price_field_options_presets( $presets ) { $options[] = $value_id.'|'.$price_field_value['label'].' - '.$price_field_value['amount'].'|'.$price_field_value['amount']; } $price_fields['price_field_'.$price_field_id] = [ - 'name' => sprintf( __( 'CiviCRM Price Set: %1$s - Price Field: %2$s', 'caldera-forms-civicrm' ), $price_set['title'], $price_field['label'] ), + 'name' => sprintf( __( 'CiviCRM Price Set: %1$s - Price Field: %2$s', 'cf-civicrm' ), $price_set['title'], $price_field['label'] ), 'data' => $options, ]; } @@ -106,9 +106,9 @@ public function autopopulate_price_field_types() { if ( $this->price_sets ) { foreach ( $this->price_sets as $price_set_id => $price_set ) { - echo ''; + echo ''; foreach ( $price_set['price_fields'] as $price_field_id => $price_field ) { - echo ""; + echo ""; } echo ''; } @@ -147,7 +147,7 @@ public function autopopulate_price_field_values( $field, $form ) { // populate field options $field['config']['option'] = array_reduce( $price_field['price_field_values'], function( $options, $price_field_value ) use ( $field ) { - $option = [ + $option = [ 'value' => $price_field_value['id'], 'label' => sprintf( '%1$s - %2$s', $price_field_value['label'], $this->plugin->helper->format_money( $price_field_value['amount'] ) ), 'calc_value' => $price_field_value['amount'], diff --git a/form-templates/civicrm-contact-address.php b/form-templates/civicrm-contact-address.php index 8fd292d..9b20b31 100644 --- a/form-templates/civicrm-contact-address.php +++ b/form-templates/civicrm-contact-address.php @@ -6,13 +6,13 @@ */ return array( - 'name' => __( 'CiviCRM Contact and Address', 'caldera-forms-civicrm' ), - 'description' => __( 'CiviCRM contact form with address.', 'caldera-forms-civicrm' ), + 'name' => __( 'CiviCRM Contact and Address', 'cf-civicrm' ), + 'description' => __( 'CiviCRM contact form with address.', 'cf-civicrm' ), 'db_support' => 1, 'pinned' => 0, 'hide_form' => 1, 'check_honey' => 0, - 'success' => __( 'Form has been successfully submitted. Thank you.', 'caldera-forms-civicrm' ), + 'success' => __( 'Form has been successfully submitted. Thank you.', 'cf-civicrm' ), 'avatar_field' => '', 'form_ajax' => 1, 'custom_callback' => '', @@ -39,7 +39,7 @@ array( 'ID' => 'prefix', 'type' => 'dropdown', - 'label' => __( 'Prefix', 'caldera-forms-civicrm' ), + 'label' => __( 'Prefix', 'cf-civicrm' ), 'slug' => 'prefix', 'conditions' => array( @@ -65,7 +65,7 @@ array( 'ID' => 'first_name', 'type' => 'text', - 'label' => __( 'First Name', 'caldera-forms-civicrm' ), + 'label' => __( 'First Name', 'cf-civicrm' ), 'slug' => 'first_name', 'conditions' => array( @@ -86,7 +86,7 @@ array( 'ID' => 'last_name', 'type' => 'text', - 'label' => __( 'Last Name', 'caldera-forms-civicrm' ), + 'label' => __( 'Last Name', 'cf-civicrm' ), 'slug' => 'last_name', 'conditions' => array( @@ -107,7 +107,7 @@ array( 'ID' => 'contact_email', 'type' => 'email', - 'label' => __( 'Email', 'caldera-forms-civicrm' ), + 'label' => __( 'Email', 'cf-civicrm' ), 'slug' => 'contact_email', 'conditions' => array( @@ -126,7 +126,7 @@ array( 'ID' => 'street_address', 'type' => 'text', - 'label' => __( 'Street Address', 'caldera-forms-civicrm' ), + 'label' => __( 'Street Address', 'cf-civicrm' ), 'slug' => 'street_address', 'conditions' => array( @@ -146,7 +146,7 @@ array( 'ID' => 'supplemental_address', 'type' => 'text', - 'label' => __( 'Supplemental Address', 'caldera-forms-civicrm' ), + 'label' => __( 'Supplemental Address', 'cf-civicrm' ), 'slug' => 'supplemental_address', 'conditions' => array( @@ -166,7 +166,7 @@ array( 'ID' => 'city', 'type' => 'text', - 'label' => __( 'City', 'caldera-forms-civicrm' ), + 'label' => __( 'City', 'cf-civicrm' ), 'slug' => 'city', 'conditions' => array( @@ -186,7 +186,7 @@ array( 'ID' => 'state', 'type' => 'civicrm_state', - 'label' => __( 'State', 'caldera-forms-civicrm' ), + 'label' => __( 'State', 'cf-civicrm' ), 'slug' => 'state', 'conditions' => array( @@ -196,7 +196,7 @@ 'config' => array( 'custom_class' => '', - 'placeholder' => __( 'Select a State/Province', 'caldera-forms-civicrm' ), + 'placeholder' => __( 'Select a State/Province', 'cf-civicrm' ), 'default' => '', ), ), @@ -204,7 +204,7 @@ array( 'ID' => 'country', 'type' => 'civicrm_country', - 'label' => __( 'Country', 'caldera-forms-civicrm' ), + 'label' => __( 'Country', 'cf-civicrm' ), 'slug' => 'country', 'conditions' => array( @@ -214,7 +214,7 @@ 'config' => array( 'custom_class' => '', - 'placeholder' => __( 'Select a Country', 'caldera-forms-civicrm' ), + 'placeholder' => __( 'Select a Country', 'cf-civicrm' ), 'default' => 1228, ), ), @@ -222,7 +222,7 @@ array( 'ID' => 'submit', 'type' => 'button', - 'label' => __( 'Submit', 'caldera-forms-civicrm' ), + 'label' => __( 'Submit', 'cf-civicrm' ), 'slug' => 'submit', 'conditions' => array( @@ -245,13 +245,13 @@ 'mailer' => array( 'on_insert' => 1, - 'sender_name' => __( 'CiviCRM Caldera Forms', 'caldera-forms-civicrm' ), + 'sender_name' => __( 'CiviCRM Caldera Forms', 'cf-civicrm' ), 'sender_email' => get_option( 'admin_email' ), 'reply_to' => '', 'email_type' => 'html', 'recipients' => '', 'bcc_to' => '', - 'email_subject' => __( 'CiviCRM Caldera Forms Submission', 'caldera-forms-civicrm' ), + 'email_subject' => __( 'CiviCRM Caldera Forms Submission', 'cf-civicrm' ), 'email_message' => '{summary}', ), 'processors' => diff --git a/form-templates/civicrm-contact-basic.php b/form-templates/civicrm-contact-basic.php index 9cd9807..3fb93ca 100644 --- a/form-templates/civicrm-contact-basic.php +++ b/form-templates/civicrm-contact-basic.php @@ -6,13 +6,13 @@ */ return array( - 'name' => __( 'CiviCRM Contact Form', 'caldera-forms-civicrm' ), - 'description' => __( 'Basic CiviCRM contact form.', 'caldera-forms-civicrm' ), + 'name' => __( 'CiviCRM Contact Form', 'cf-civicrm' ), + 'description' => __( 'Basic CiviCRM contact form.', 'cf-civicrm' ), 'db_support' => 1, 'pinned' => 0, 'hide_form' => 1, 'check_honey' => 0, - 'success' => __( 'Form has been successfully submitted. Thank you.', 'caldera-forms-civicrm' ), + 'success' => __( 'Form has been successfully submitted. Thank you.', 'cf-civicrm' ), 'avatar_field' => '', 'form_ajax' => 1, 'custom_callback' => '', @@ -34,7 +34,7 @@ array( 'ID' => 'prefix', 'type' => 'dropdown', - 'label' => __( 'Prefix', 'caldera-forms-civicrm' ), + 'label' => __( 'Prefix', 'cf-civicrm' ), 'slug' => 'prefix', 'conditions' => array( @@ -60,7 +60,7 @@ array( 'ID' => 'first_name', 'type' => 'text', - 'label' => __( 'First Name', 'caldera-forms-civicrm' ), + 'label' => __( 'First Name', 'cf-civicrm' ), 'slug' => 'first_name', 'conditions' => array( @@ -81,7 +81,7 @@ array( 'ID' => 'last_name', 'type' => 'text', - 'label' => __( 'Last Name', 'caldera-forms-civicrm' ), + 'label' => __( 'Last Name', 'cf-civicrm' ), 'slug' => 'last_name', 'conditions' => array( @@ -102,7 +102,7 @@ array( 'ID' => 'contact_email', 'type' => 'email', - 'label' => __( 'Email', 'caldera-forms-civicrm' ), + 'label' => __( 'Email', 'cf-civicrm' ), 'slug' => 'contact_email', 'conditions' => array( @@ -121,7 +121,7 @@ array( 'ID' => 'submit', 'type' => 'button', - 'label' => __( 'Submit', 'caldera-forms-civicrm' ), + 'label' => __( 'Submit', 'cf-civicrm' ), 'slug' => 'submit', 'conditions' => array( @@ -144,13 +144,13 @@ 'mailer' => array( 'on_insert' => 1, - 'sender_name' => __( 'CiviCRM Caldera Forms', 'caldera-forms-civicrm' ), + 'sender_name' => __( 'CiviCRM Caldera Forms', 'cf-civicrm' ), 'sender_email' => get_option( 'admin_email' ), 'reply_to' => '', 'email_type' => 'html', 'recipients' => '', 'bcc_to' => '', - 'email_subject' => __( 'CiviCRM Caldera Forms Submission', 'caldera-forms-civicrm' ), + 'email_subject' => __( 'CiviCRM Caldera Forms Submission', 'cf-civicrm' ), 'email_message' => '{summary}', ), 'processors' => diff --git a/form-templates/civicrm-organisation-basic.php b/form-templates/civicrm-organisation-basic.php index 6f384ad..4f125ec 100644 --- a/form-templates/civicrm-organisation-basic.php +++ b/form-templates/civicrm-organisation-basic.php @@ -6,13 +6,13 @@ */ return array( - 'name' => __( 'CiviCRM Organisation', 'caldera-forms-civicrm' ), - 'description' => __( 'Basic CiviCRM organisation form.', 'caldera-forms-civicrm' ), + 'name' => __( 'CiviCRM Organisation', 'cf-civicrm' ), + 'description' => __( 'Basic CiviCRM organisation form.', 'cf-civicrm' ), 'db_support' => 1, 'pinned' => 0, 'hide_form' => 1, 'check_honey' => 0, - 'success' => __( 'Form has been successfully submitted. Thank you.', 'caldera-forms-civicrm' ), + 'success' => __( 'Form has been successfully submitted. Thank you.', 'cf-civicrm' ), 'avatar_field' => '', 'form_ajax' => 1, 'custom_callback' => '', @@ -37,7 +37,7 @@ array( 'ID' => 'organisation_name', 'type' => 'text', - 'label' => __( 'Organisation Name', 'caldera-forms-civicrm' ), + 'label' => __( 'Organisation Name', 'cf-civicrm' ), 'slug' => 'organisation_name', 'conditions' => array( @@ -58,7 +58,7 @@ array( 'ID' => 'org_email', 'type' => 'email', - 'label' => __( 'Contact Email', 'caldera-forms-civicrm' ), + 'label' => __( 'Contact Email', 'cf-civicrm' ), 'slug' => 'org_email', 'conditions' => array( @@ -77,7 +77,7 @@ array( 'ID' => 'street_address', 'type' => 'text', - 'label' => __( 'Street Address', 'caldera-forms-civicrm' ), + 'label' => __( 'Street Address', 'cf-civicrm' ), 'slug' => 'street_address', 'conditions' => array( @@ -97,7 +97,7 @@ array( 'ID' => 'supplemental_address', 'type' => 'text', - 'label' => __( 'Supplemental Address', 'caldera-forms-civicrm' ), + 'label' => __( 'Supplemental Address', 'cf-civicrm' ), 'slug' => 'supplemental_address', 'conditions' => array( @@ -117,7 +117,7 @@ array( 'ID' => 'city', 'type' => 'text', - 'label' => __( 'City', 'caldera-forms-civicrm' ), + 'label' => __( 'City', 'cf-civicrm' ), 'slug' => 'city', 'conditions' => array( @@ -138,7 +138,7 @@ array( 'ID' => 'state', 'type' => 'civicrm_state', - 'label' => __( 'State', 'caldera-forms-civicrm' ), + 'label' => __( 'State', 'cf-civicrm' ), 'slug' => 'state', 'conditions' => array( @@ -148,7 +148,7 @@ 'config' => array( 'custom_class' => '', - 'placeholder' => __( 'Select a State/Province', 'caldera-forms-civicrm' ), + 'placeholder' => __( 'Select a State/Province', 'cf-civicrm' ), 'default' => '', ), ), @@ -156,7 +156,7 @@ array( 'ID' => 'country', 'type' => 'civicrm_country', - 'label' => __( 'Country', 'caldera-forms-civicrm' ), + 'label' => __( 'Country', 'cf-civicrm' ), 'slug' => 'country', 'conditions' => array( @@ -167,7 +167,7 @@ 'config' => array( 'custom_class' => '', - 'placeholder' => __( 'Select a Country', 'caldera-forms-civicrm' ), + 'placeholder' => __( 'Select a Country', 'cf-civicrm' ), 'default' => '', ), ), @@ -175,7 +175,7 @@ array( 'ID' => 'submit', 'type' => 'button', - 'label' => __( 'Submit', 'caldera-forms-civicrm' ), + 'label' => __( 'Submit', 'cf-civicrm' ), 'slug' => 'submit', 'conditions' => array( @@ -198,13 +198,13 @@ 'mailer' => array( 'on_insert' => 1, - 'sender_name' => __( 'CiviCRM Caldera Forms', 'caldera-forms-civicrm' ), + 'sender_name' => __( 'CiviCRM Caldera Forms', 'cf-civicrm' ), 'sender_email' => get_option( 'admin_email' ), 'reply_to' => '', 'email_type' => 'html', 'recipients' => '', 'bcc_to' => '', - 'email_subject' => __( 'CiviCRM Caldera Forms Submission', 'caldera-forms-civicrm' ), + 'email_subject' => __( 'CiviCRM Caldera Forms Submission', 'cf-civicrm' ), 'email_message' => '{summary}', ), 'processors' => diff --git a/form-templates/civicrm-organisation-contact.php b/form-templates/civicrm-organisation-contact.php index 2798288..a1c05db 100644 --- a/form-templates/civicrm-organisation-contact.php +++ b/form-templates/civicrm-organisation-contact.php @@ -6,13 +6,13 @@ */ return array( - 'name' => __( 'CiviCRM Organisation and Contact', 'caldera-forms-civicrm' ), - 'description' => __( 'CiviCRM organisation form with primary contact.', 'caldera-forms-civicrm' ), + 'name' => __( 'CiviCRM Organisation and Contact', 'cf-civicrm' ), + 'description' => __( 'CiviCRM organisation form with primary contact.', 'cf-civicrm' ), 'db_support' => 1, 'pinned' => 0, 'hide_form' => 1, 'check_honey' => 0, - 'success' => __( 'Form has been successfully submitted. Thank you.', 'caldera-forms-civicrm' ), + 'success' => __( 'Form has been successfully submitted. Thank you.', 'cf-civicrm' ), 'avatar_field' => '', 'form_ajax' => 1, 'custom_callback' => '', @@ -43,7 +43,7 @@ array( 'ID' => 'about_your_organisation', 'type' => 'html', - 'label' => __( 'About Your Organisation', 'caldera-forms-civicrm' ), + 'label' => __( 'About Your Organisation', 'cf-civicrm' ), 'slug' => 'about_your_organisation', 'conditions' => array( @@ -53,16 +53,16 @@ 'config' => array( 'custom_class' => '', - 'default' => '

' . __( 'About Your Organisation', 'caldera-forms-civicrm' ) . '

+ 'default' => '

' . __( 'About Your Organisation', 'cf-civicrm' ) . '

-

' . __( 'We need to know a few things about your organisation.', 'caldera-forms-civicrm' ) . '

', +

' . __( 'We need to know a few things about your organisation.', 'cf-civicrm' ) . '

', ), ), 'organisation_name' => array( 'ID' => 'organisation_name', 'type' => 'text', - 'label' => __( 'Organisation Name', 'caldera-forms-civicrm' ), + 'label' => __( 'Organisation Name', 'cf-civicrm' ), 'slug' => 'organisation_name', 'conditions' => array( @@ -83,7 +83,7 @@ array( 'ID' => 'org_email', 'type' => 'email', - 'label' => __( 'Organisation Email', 'caldera-forms-civicrm' ), + 'label' => __( 'Organisation Email', 'cf-civicrm' ), 'slug' => 'org_email', 'conditions' => array( @@ -101,7 +101,7 @@ array( 'ID' => 'street_address', 'type' => 'text', - 'label' => __( 'Street Address', 'caldera-forms-civicrm' ), + 'label' => __( 'Street Address', 'cf-civicrm' ), 'slug' => 'street_address', 'conditions' => array( @@ -121,7 +121,7 @@ array( 'ID' => 'supplemental_address', 'type' => 'text', - 'label' => __( 'Supplemental Address', 'caldera-forms-civicrm' ), + 'label' => __( 'Supplemental Address', 'cf-civicrm' ), 'slug' => 'supplemental_address', 'conditions' => array( @@ -141,7 +141,7 @@ array( 'ID' => 'city', 'type' => 'text', - 'label' => __( 'City', 'caldera-forms-civicrm' ), + 'label' => __( 'City', 'cf-civicrm' ), 'slug' => 'city', 'conditions' => array( @@ -162,7 +162,7 @@ array( 'ID' => 'state', 'type' => 'civicrm_state', - 'label' => __( 'State', 'caldera-forms-civicrm' ), + 'label' => __( 'State', 'cf-civicrm' ), 'slug' => 'state', 'conditions' => array( @@ -172,7 +172,7 @@ 'config' => array( 'custom_class' => '', - 'placeholder' => __( 'Select a State/Province', 'caldera-forms-civicrm' ), + 'placeholder' => __( 'Select a State/Province', 'cf-civicrm' ), 'default' => '', ), ), @@ -180,7 +180,7 @@ array( 'ID' => 'country', 'type' => 'civicrm_country', - 'label' => __( 'Country', 'caldera-forms-civicrm' ), + 'label' => __( 'Country', 'cf-civicrm' ), 'slug' => 'country', 'conditions' => array( @@ -191,7 +191,7 @@ 'config' => array( 'custom_class' => '', - 'placeholder' => __( 'Select a Country', 'caldera-forms-civicrm' ), + 'placeholder' => __( 'Select a Country', 'cf-civicrm' ), 'default' => '', ), ), @@ -199,7 +199,7 @@ array( 'ID' => 'organisation_contact', 'type' => 'html', - 'label' => __( 'Organisation Contact', 'caldera-forms-civicrm' ), + 'label' => __( 'Organisation Contact', 'cf-civicrm' ), 'slug' => 'organisation_contact', 'conditions' => array( @@ -211,16 +211,16 @@ 'custom_class' => '', 'default' => '
-

' . __( 'Organisation Contact', 'caldera-forms-civicrm' ) . '

+

' . __( 'Organisation Contact', 'cf-civicrm' ) . '

-

' . __( 'Who is the primary contact at your organisation?', 'caldera-forms-civicrm' ) . '

', +

' . __( 'Who is the primary contact at your organisation?', 'cf-civicrm' ) . '

', ), ), 'prefix' => array( 'ID' => 'prefix', 'type' => 'dropdown', - 'label' => __( 'Prefix', 'caldera-forms-civicrm' ), + 'label' => __( 'Prefix', 'cf-civicrm' ), 'slug' => 'prefix', 'conditions' => array( @@ -246,7 +246,7 @@ array( 'ID' => 'first_name', 'type' => 'text', - 'label' => __( 'First Name', 'caldera-forms-civicrm' ), + 'label' => __( 'First Name', 'cf-civicrm' ), 'slug' => 'first_name', 'conditions' => array( @@ -266,7 +266,7 @@ array( 'ID' => 'last_name', 'type' => 'text', - 'label' => __( 'Last Name', 'caldera-forms-civicrm' ), + 'label' => __( 'Last Name', 'cf-civicrm' ), 'slug' => 'last_name', 'conditions' => array( @@ -286,7 +286,7 @@ array( 'ID' => 'contact_email', 'type' => 'email', - 'label' => __( 'Contact Email', 'caldera-forms-civicrm' ), + 'label' => __( 'Contact Email', 'cf-civicrm' ), 'slug' => 'contact_email', 'conditions' => array( @@ -304,7 +304,7 @@ array( 'ID' => 'submit', 'type' => 'button', - 'label' => __( 'Submit', 'caldera-forms-civicrm' ), + 'label' => __( 'Submit', 'cf-civicrm' ), 'slug' => 'submit', 'conditions' => array( @@ -327,13 +327,13 @@ 'mailer' => array( 'on_insert' => 1, - 'sender_name' => __( 'CiviCRM Caldera Forms', 'caldera-forms-civicrm' ), + 'sender_name' => __( 'CiviCRM Caldera Forms', 'cf-civicrm' ), 'sender_email' => get_option( 'admin_email' ), 'reply_to' => '', 'email_type' => 'html', 'recipients' => '', 'bcc_to' => '', - 'email_subject' => __( 'CiviCRM Caldera Forms Submission', 'caldera-forms-civicrm' ), + 'email_subject' => __( 'CiviCRM Caldera Forms Submission', 'cf-civicrm' ), 'email_message' => '{summary}', ), 'processors' => diff --git a/includes/class-civicrm-caldera-forms-ajax.php b/includes/class-civicrm-caldera-forms-ajax.php index 1a4c2aa..046f6ac 100644 --- a/includes/class-civicrm-caldera-forms-ajax.php +++ b/includes/class-civicrm-caldera-forms-ajax.php @@ -50,28 +50,32 @@ public function register_hooks() { * @since 0.4.2 */ public function get_civicrm_contacts() { - if ( isset( $_POST['search'] ) ) $search_term = $_POST['search']; - if ( isset( $_POST['contact_id'] ) ) $contact_id = $_POST['contact_id']; + $_POST = Caldera_Forms_Sanitize::sanitize( $_POST ); + if ( isset( $_POST['search'] ) ) $search_term = sanitize_text_field( $_POST['search'] ); + if ( isset( $_POST['contact_id'] ) ) $contact_id = intval( $_POST['contact_id'] ); - if ( ! wp_verify_nonce( $_POST['nonce'], 'admin_get_civi_contact' ) ) return; + if ( ! wp_verify_nonce( $_POST['nonce'], 'admin_get_civi_contact' ) ) return; - if ( isset( $contact_id ) ) - $params['contact_id'] = $contact_id; - // sort name - if ( isset( $search_term ) ) - $params['sort_name'] = $search_term; + $params = []; - $result = $this->get_contacts( $params, $with_email = true ); + if ( isset( $contact_id ) ) + $params['contact_id'] = $contact_id; + // sort name + if ( isset( $search_term ) ) + $params['sort_name'] = $search_term; + + $result = $this->get_contacts( $params, $with_email = true ); echo json_encode( $result ); die; } public function civicrm_contact_reference_get() { - if ( isset( $_POST['search'] ) ) $search_term = $_POST['search']; - if ( isset( $_POST['contact_id'] ) ) $contact_id = $_POST['contact_id']; - if ( isset( $_POST['field_id'] ) ) $field_id = $_POST['field_id']; - if ( isset( $_POST['form_id'] ) ) $form_id = $_POST['form_id']; + $_POST = Caldera_Forms_Sanitize::sanitize( $_POST ); + if ( isset( $_POST['search'] ) ) $search_term = sanitize_text_field( $_POST['search'] ); + if ( isset( $_POST['contact_id'] ) ) $contact_id = intval( $_POST['contact_id'] ); + if ( isset( $_POST['field_id'] ) ) $field_id = sanitize_text_field( $_POST['field_id'] ); + if ( isset( $_POST['form_id'] ) ) $form_id = sanitize_text_field( $_POST['form_id'] ); if ( ! wp_verify_nonce( $_POST['nonce'], 'civicrm_contact_reference_get' ) ) return; // form config @@ -79,6 +83,8 @@ public function civicrm_contact_reference_get() { // field config $field = Caldera_Forms_Field_Util::get_field( $field_id, $form ); + $params = []; + // contact_type if ( isset( $field['config']['contact_type'] ) ) $params['contact_type'] = $field['config']['contact_type']; @@ -103,7 +109,7 @@ public function civicrm_contact_reference_get() { } public function get_contacts( $search, $with_email = false ) { - + $params = [ 'sequential' => 1, 'return' => [ 'sort_name', 'email' ], @@ -112,7 +118,7 @@ public function get_contacts( $search, $with_email = false ) { ]; $params = array_merge( $params, $search ); - + $contacts = civicrm_api3( 'Contact', 'get', $params ); foreach ( $contacts['values'] as $key => $contact ) { @@ -124,8 +130,9 @@ public function get_contacts( $search, $with_email = false ) { } public function civicrm_get_groups() { - if ( isset( $_POST['search'] ) ) $search_term = $_POST['search']; - if ( isset( $_POST['group_id'] ) ) $group_id = $_POST['group_id']; + $_POST = Caldera_Forms_Sanitize::sanitize( $_POST ); + if ( isset( $_POST['search'] ) ) $search_term = sanitize_text_field( $_POST['search'] ); + if ( isset( $_POST['group_id'] ) ) $group_id = intval( $_POST['group_id'] ); if ( ! wp_verify_nonce( $_POST['nonce'], 'admin_get_groups' ) ) return; @@ -137,9 +144,9 @@ public function civicrm_get_groups() { if ( isset( $group_id ) ) $params['id'] = $group_id; if ( isset( $search_term ) && ! empty( $search_term ) ) $params['title'] = [ 'LIKE' => '%' . $search_term . '%' ]; - + $groups = civicrm_api3( 'Group', 'get', $params ); - + echo json_encode( $groups['values'] ); die; } @@ -150,7 +157,7 @@ public function flush_price_set_cache() { ob_start(); ?>
- +
plugin->cividiscount->get_by_code( $code ); if ( $discount ) { @@ -184,8 +191,9 @@ public function do_code_cividiscount() { } public function civicrm_get_premiums() { - if ( isset( $_POST['search'] ) ) $search_term = $_POST['search']; - if ( isset( $_POST['premium_id'] ) ) $premium_id = $_POST['premium_id']; + $_POST = Caldera_Forms_Sanitize::sanitize( $_POST ); + if ( isset( $_POST['search'] ) ) $search_term = sanitize_text_field( $_POST['search'] ); + if ( isset( $_POST['premium_id'] ) ) $premium_id = intval( $_POST['premium_id'] ); if ( ! wp_verify_nonce( $_POST['nonce'], 'admin_get_premiums' ) ) return; @@ -196,10 +204,11 @@ public function civicrm_get_premiums() { if ( isset( $premium_id ) ) $params['id'] = $premium_id; if ( isset( $search_term ) && ! empty( $search_term ) ) $params['name'] = [ 'LIKE' => '%' . $search_term . '%' ]; - + $premiums = civicrm_api3( 'Product', 'get', $params ); - + echo json_encode( $premiums['values'] ); die; } + } diff --git a/includes/class-civicrm-caldera-forms-cividiscount.php b/includes/class-civicrm-caldera-forms-cividiscount.php index c99cdb7..fe955c3 100644 --- a/includes/class-civicrm-caldera-forms-cividiscount.php +++ b/includes/class-civicrm-caldera-forms-cividiscount.php @@ -128,7 +128,7 @@ public function get_event_cividiscounts( $event_ids ) { if ( is_array( $this->event_cividiscounts ) && ! empty( $this->event_cividiscounts ) ) return $this->event_cividiscounts; - $event_cividiscounts = $this->get_cividiscounts_by_entity( 'events' ); + $event_cividiscounts = $this->get_cividiscounts_by_entity( 'events' ); if ( ! isset( $event_discounts ) ) return; @@ -154,7 +154,7 @@ public function get_event_cividiscounts( $event_ids ) { /** * Build options ids for price fields. - * + * * @since 1.0 * @param array $form The form config * @return array|boolean $options_ids_refs References to [ => ], or false @@ -254,7 +254,7 @@ public function check_autodiscount( $autodiscount, $contact_id, $processor_id ) break; } } catch ( CiviCRM_API3_Exception $e ) { - + } } } @@ -301,17 +301,17 @@ public function get_by_code( $code ) { */ public function do_discounted_option( $option, $field, $price_field_value, $discount ) { - $label = sprintf( __( '%1$s (Includes automatic discount of: ', 'caldera-forms-civicrm' ), $price_field_value['label'] ); + $label = sprintf( __( '%1$s (Includes automatic discount of: ', 'cf-civicrm' ), $price_field_value['label'] ); // percentage discount if ( $discount['amount_type'] == 1 ) { $discounted_amount = $price_field_value['amount'] - $this->plugin->helper->calculate_percentage( $price_field_value['amount'], $discount['amount'] ); - $label .= $discount['amount'] . __( '%)', 'caldera-forms-civicrm' ); + $label .= $discount['amount'] . __( '%)', 'cf-civicrm' ); } // fixed discount if ( $discount['amount_type'] == 2 ) { $discounted_amount = $price_field_value['amount'] - $discount['amount']; - $label .= $this->plugin->helper->format_money( $discount['amount'] ) . __( ')', 'caldera-forms-civicrm' ); + $label .= $this->plugin->helper->format_money( $discount['amount'] ) . __( ')', 'cf-civicrm' ); } // filtered option $option = [ @@ -417,7 +417,7 @@ public function do_code_event_discount_options( $discount, $form ) { $options = array_reduce( $field['config']['option'], function( $options, $option ) use ( $field_id, $field, $form ) { $field_option_id = $field_id . '_' . $form['form_count'] . '_' . $option['value']; $options[$field_option_id] = $field['config']['option'][$option['value']]; - $options[$field_option_id]['field_id'] = $field_id; + $options[$field_option_id]['field_id'] = $field_id; return $options; }, [] ); @@ -472,7 +472,7 @@ public function do_code_options_discount_options( $discount, $form ) { $options = array_reduce( $field['config']['option'], function( $options, $option ) use ( $ref, $field, $form ) { $field_option_id = $ref['field_id'] . '_' . $form['form_count'] . '_' . $option['value']; $options[$field_option_id] = $field['config']['option'][$option['value']]; - $options[$field_option_id]['field_id'] = $ref['field_id']; + $options[$field_option_id]['field_id'] = $ref['field_id']; return $options; }, [] ); return $discounted_options + $options; diff --git a/includes/class-civicrm-caldera-forms-forms.php b/includes/class-civicrm-caldera-forms-forms.php index 9f8a1f8..484847b 100644 --- a/includes/class-civicrm-caldera-forms-forms.php +++ b/includes/class-civicrm-caldera-forms-forms.php @@ -15,7 +15,7 @@ class CiviCRM_Caldera_Forms_Forms { * @var object $plugin The plugin instance */ public $plugin; - + /** * Transient Id reference. * @@ -46,11 +46,11 @@ public function register_hooks() { add_filter( 'caldera_forms_presave_form', [ $this, 'reorder_contact_processors' ], 20 ); /** - * The transients are set and destroyed twice, - * one for the rendering of the form (autopopulation), + * The transients are set and destroyed twice, + * one for the rendering of the form (autopopulation), * and another one for the form submission. */ - + // form render transient add_filter( 'caldera_forms_render_get_form', [ $this, 'set_form_transient' ], 1 ); add_action( 'caldera_forms_render_end', [ $this, 'delete_form_transient' ], 1 ); @@ -58,11 +58,11 @@ public function register_hooks() { // form submission transient add_filter( 'caldera_forms_submit_get_form', [ $this, 'set_form_transient' ] ); add_action( 'caldera_forms_submit_complete', [ $this, 'delete_form_transient' ] ); - + // add CiviCRM panel - if ( in_array( 'CiviContribute', $this->plugin->processors->enabled_components ) ) + if ( in_array( 'CiviContribute', $this->plugin->processors->enabled_components ) ) add_filter( 'caldera_forms_get_panel_extensions', [ $this, 'add_civicrm_tab' ], 10 ); - + // use label in summary add_filter( 'caldera_forms_magic_summary_should_use_label', [ $this, 'summary_use_label' ], 10, 3 ); // exclude hidden fields from summary @@ -78,7 +78,7 @@ public function register_hooks() { /** * Set form transient. - * + * * @since 0.4.4 * @access public * @param array $form The form config @@ -92,13 +92,13 @@ public function set_form_transient( $form ) { if ( Caldera_Forms::get_processor_by_type( 'civicrm_contact', $form ) ) // set transient structure $this->set_transient_structure( $form ); - + return $form; } /** * Delete form transient. - * + * * @access public * @since 0.4.4 */ @@ -110,7 +110,7 @@ public function delete_form_transient() { * Transient structure. * * @since 0.4.4 - * + * * @param array $form Form config * @return array $form Form config */ @@ -207,7 +207,7 @@ public function render_notices_field( $form ) { ], 'caption' => '', 'config' => [ - 'custom_calss' => '', + 'custom_class' => '', 'default' => $html ] ]; @@ -238,14 +238,14 @@ public function render_notices_field( $form ) { * Add CiviCRM panel. * * @since 0.4.4 - * + * * @param array $panels Panels * @return array $panels Panels */ public function add_civicrm_tab( $panels ) { $panels['form_layout']['tabs'][ 'civicrm' ] = [ - 'name' => __( 'CiviCRM', 'caldera-forms-civicrm' ), - 'label' => __( 'Caldera Forms CiviCRM', 'caldera-forms-civicrm' ), + 'name' => __( 'CiviCRM', 'cf-civicrm' ), + 'label' => __( 'Caldera Forms CiviCRM', 'cf-civicrm' ), 'location' => 'lower', 'actions' => [], 'side_panel' => null, @@ -264,7 +264,7 @@ public function add_civicrm_tab( $panels ) { * @return boolean $use */ public function summary_use_label( $use, $field, $form ) { - + if ( Caldera_Forms::get_processor_by_type( 'civicrm_contact', $form ) ) return true; @@ -280,7 +280,7 @@ public function summary_use_label( $use, $field, $form ) { * @param array $form Form config */ public function exclude_hidden_fields_in_summary( $fields, $form ) { - + if ( Caldera_Forms::get_processor_by_type( 'civicrm_contact', $form ) ) return array_filter( $fields, function( $field ) { return $field['type'] !== 'hidden'; @@ -320,7 +320,7 @@ public function reorder_contact_processors( $form ) { * Rebuild calculation field formular. * * When fields are removed/hidden through 'caldera_forms_render_get_field' and - * 'caldera_forms_render_setup_field' filters, if the removed field is part of the + * 'caldera_forms_render_setup_field' filters, if the removed field is part of the * Calculation field formula, it breaks. The formula becomes ( 10+fld_123456 ). * * This method filters the calculation field to check for @@ -374,4 +374,4 @@ public function rebuild_calculation_field_formula( $field, $form ) { return $field; } -} \ No newline at end of file +} diff --git a/includes/class-civicrm-caldera-forms-helper.php b/includes/class-civicrm-caldera-forms-helper.php index 4f980ac..6d09e8c 100644 --- a/includes/class-civicrm-caldera-forms-helper.php +++ b/includes/class-civicrm-caldera-forms-helper.php @@ -91,16 +91,16 @@ public function contact_link_field() { ob_start(); ?> 1, @@ -383,17 +383,17 @@ public function map_fields_to_processor( $config, $form, &$form_values, $process $mapped_field = Caldera_Forms_Magic_Doer::do_bracket_magic( $field_id, $form, NULL, NULL, NULL ); } elseif ( strpos( $field_id, '%' ) !== false && substr_count( $field_id, '%' ) > 2 ) { - + // multiple fields mapped // explode and remove empty indexes $field_slugs = array_filter( explode( '%', $field_id ) ); - + $mapped_fields = []; foreach ( $field_slugs as $k => $slug ) { $field = Caldera_Forms::get_field_by_slug( $slug, $form ); $mapped_fields[] = Caldera_Forms::get_field_data( $field['ID'], $form ); } - + $mapped_fields = array_filter( $mapped_fields ); // expect one value, return first value $mapped_field = reset( $mapped_fields ); @@ -408,17 +408,17 @@ public function map_fields_to_processor( $config, $form, &$form_values, $process // Get field data $mapped_field = Caldera_Forms::get_field_data( $mapped_field['ID'], $form ); - + // if not a magic tag nor field id, must be a fixed value // $mapped_field = $mapped_field ? $mapped_field : $field_id; } - + /** * Filter mapped field value, fires for every processor field. * * @since 0.4.4 - * + * * @param string|int $mapped_field The mapped value * @param string $civi_field The field for an entity i.e. 'contact_id', 'current_employer', etc. * @param array $field The field config @@ -468,11 +468,17 @@ public function map_fields_to_prerender( $config, &$form, $ignore_fields, $entit $value = ! empty( $entity[$civi_field] ) ? $entity[$civi_field] : ''; + // If the CF field is a date picker, convert the date value to the date picker's format. + if ( $field['type'] == 'date_picker' && ! empty( $value ) ) { + $format = $this->translate_date_picker_format( $field['config']['format'] ); + $value = date_create( $value )->format( $format ); + } + /** * Filter prerenderd value (default value), fires for every processor field. * * @since 0.4.4 - * + * * @param string|int $value The default value * @param string $civi_field The field for an entity i.e. 'contact_id', 'current_employer', etc. * @param array $field The field config @@ -491,6 +497,31 @@ public function map_fields_to_prerender( $config, &$form, $ignore_fields, $entit return $form; } + /** + * Translate Caldera Forms date picker formats to PHP date formats. + * + * @since 1.0.2 + * + * @param string $date_picker_format The Caldera Forms date picker format + */ + public function translate_date_picker_format( $date_picker_format ){ + // Translate each token used in the CF date picker format to the corresponding PHP format character. + $token_map = [ + 'yyyy' => 'Y', + 'yy' => 'y', + 'MM' => 'F', + 'M' => 'M', + 'mm' => 'm', + 'm' => 'n', + 'DD' => 'l', + 'D' => 'D', + 'dd' => 'd', + 'd' => 'j', + ]; + + return strtr( $date_picker_format, $token_map ); + } + /** * Get CiviCRM enabled extensions. * @@ -631,7 +662,7 @@ public function get_tax_rates() { 'financial_account_id.is_tax' => 1, 'options' => [ 'limit' => 0 ] ] ); - + if ( $tax_financial_accounts['count'] ) { // buils tax rates $this->tax_rates = array_reduce( $tax_financial_accounts['values'], function( $tax_rates, $financial_account ) { @@ -640,7 +671,7 @@ public function get_tax_rates() { }, [] ); return $this->tax_rates; - + } return false; @@ -660,7 +691,7 @@ public function calculate_percentage( $amount, $percentage ) { /** * Format tax label as per CiviCRM. - * + * * @param string $label The label * @param string $amount The amount * @param string $tax_amount The tax amount @@ -693,7 +724,7 @@ public function format_tax_label( $label, $amount, $tax_amount, $currency = fals * @return string $formated_amount The formated amount */ public function format_money( $amount, $currency = false ) { - return CRM_Utils_Money::format( $amount, $currency ); + return CRM_Utils_Money::format( $amount, $currency ); } /** @@ -703,7 +734,7 @@ public function format_money( $amount, $currency = false ) { * @return array $price_sets The active price sets with their corresponding price fields and price filed values */ public function get_price_sets() { - + // get tax settings $tax_settings = $this->get_tax_settings(); // get tax rates @@ -782,7 +813,7 @@ public function get_price_sets() { public function cached_price_sets() { $price_sets = get_transient( 'cfc_civicrm_price_sets' ); if ( $price_sets ) return $price_sets; - + // set transient only if we have price sets if ( $this->get_price_sets() ) { if ( set_transient( 'cfc_civicrm_price_sets', $this->get_price_sets(), DAY_IN_SECONDS ) ) @@ -790,14 +821,14 @@ public function cached_price_sets() { } return false; - + } /** * Get Price Field Value by id. * * @since 0.4.4 - * + * * @param int $id Price Field Value id * @return array $price_field_value The Price Field Value */ @@ -835,7 +866,7 @@ public function get_price_field_value( $id ) { * @since 1.0 * @param int $id The entity id * @param string $column_name The column name, price_set|price_field|price_field_value - * @return array $column The requested entity or false + * @return array $column The requested entity or false */ public function get_price_set_column_by_id( $id, $column_name ) { @@ -875,7 +906,7 @@ public function get_price_set_column_by_id( $id, $column_name ) { * Get membership types assocaited to an Organizaion. * * @since 0.4.4 - * + * * @param int $cid Organization contact id * @return array|boolean The membership types for that organization or false */ @@ -910,7 +941,7 @@ public function get_organization_membership_types( $cid ) { public function get_membership( $cid = false, $membership_type = false, $sort = 'DESC', $skip_status = false ) { if ( ! $cid ) return false; - + $params = [ 'sequential' => 1, 'contact_id' => $cid, @@ -958,9 +989,9 @@ public function civi_contact_dedupe( $contact, $contact_type, $dedupe_rule_id ) * * Checks for a valid checksum, and if the user is logged in, * logged in user data has precedence over checksum. - * + * * @since 0.4.4 - * @return array|boolean $contact The Contact data, false otherwise + * @return array|boolean $contact The Contact data, false otherwise */ public function current_contact_data_get() { @@ -1013,7 +1044,7 @@ public function get_current_contact() { * @since 1.0 * @return array $custom_fields The array of custom fields - e.g. ['custom_x' => 'Label of custom_x'] */ - public static function get_participant_custom_fields() { + public function get_participant_custom_fields() { try { $custom_groups = civicrm_api3( 'CustomGroup', 'get', [ @@ -1033,7 +1064,7 @@ public static function get_participant_custom_fields() { $custom_fields['custom_' . $custom_field['id']] = [ 'label' => $custom_field['label'], 'extends_entity_column_id' => $custom_group['extends_entity_column_id'], - 'extends_entity_column_value' => $custom_group['extends_entity_column_value'] + 'extends_entity_column_value' => $custom_group['extends_entity_column_value'] ]; } } @@ -1044,7 +1075,7 @@ public static function get_participant_custom_fields() { /** * Get processor by type. - * + * * @since 1.0 * @param string $processor_type The processor type * @param array $form Form config @@ -1076,7 +1107,7 @@ public function get_processor_from_magic( $magic_tag, $form = false ) { if ( strpos( $magic_tag, '{' ) === false ) return false; - if ( strpos( $magic_tag, 'processor_id' ) === false ) return false; + if ( strpos( $magic_tag, 'processor_id' ) === false ) return false; // clean up magic tag $magic_tag = str_replace( [ '{', '}' ], '', $magic_tag ); @@ -1085,6 +1116,10 @@ public function get_processor_from_magic( $magic_tag, $form = false ) { if( ! $form ) global $form; + // handle cf select field ({{{_field}}}) magic tags + // values which render as fp_123456:processor_id + if ( false !== strpos( $parts[0], 'fp_' ) ) return $form['processors'][$parts[0]]; + // if form has more than one processor of same type // the magic tag has the format of processor_type:processor_id: // otherwise the format is processor_type:processor_id @@ -1096,4 +1131,39 @@ public function get_processor_from_magic( $magic_tag, $form = false ) { } + /** + * Get Case custom fields. + * + * @since 1.0.3 + * @return array $custom_fields The array of custom fields + */ + public function get_case_custom_fields() { + + try { + $custom_groups = civicrm_api3( 'CustomGroup', 'get', [ + 'sequential' => 1, + 'is_active' => 1, + 'extends' => 'Case', + 'api.CustomField.get' => [ 'is_active' => 1, 'options' => [ 'limit' => 0 ] ], + 'options' => [ 'limit' => 0 ], + ] ); + } catch ( CiviCRM_API3_Exception $e ) { + return [ 'note' => $e->getMessage(), 'type' => 'error' ]; + } + + $custom_fields = []; + foreach ( $custom_groups['values'] as $key => $custom_group ) { + foreach ( $custom_group['api.CustomField.get']['values'] as $k => $custom_field ) { + $custom_fields['custom_' . $custom_field['id']] = [ + 'label' => $custom_group['title'] . ' - ' . $custom_field['label'], + 'extends_entity_column_id' => $custom_group['extends_entity_column_id'], + 'extends_entity_column_value' => $custom_group['extends_entity_column_value'] + ]; + } + } + + return $custom_fields; + + } + } diff --git a/includes/class-civicrm-caldera-forms-templates.php b/includes/class-civicrm-caldera-forms-templates.php index bf81349..30f71d7 100644 --- a/includes/class-civicrm-caldera-forms-templates.php +++ b/includes/class-civicrm-caldera-forms-templates.php @@ -43,25 +43,25 @@ public function register_templates( $templates ) { // add basic contact template $templates['civicrm_contact_basic'] = [ - 'name' => esc_html__( 'CiviCRM Contact Form', 'caldera-forms-civicrm' ), + 'name' => esc_html__( 'CiviCRM Contact Form', 'cf-civicrm' ), 'template' => include CF_CIVICRM_INTEGRATION_PATH . 'form-templates/civicrm-contact-basic.php' ]; // add contact with address template $templates['civicrm_contact_address'] = [ - 'name' => esc_html__( 'CiviCRM Contact and Address', 'caldera-forms-civicrm' ), + 'name' => esc_html__( 'CiviCRM Contact and Address', 'cf-civicrm' ), 'template' => include CF_CIVICRM_INTEGRATION_PATH . 'form-templates/civicrm-contact-address.php' ]; // add organisation template $templates['civicrm_org_basic'] = [ - 'name' => esc_html__( 'CiviCRM Organisation', 'caldera-forms-civicrm' ), + 'name' => esc_html__( 'CiviCRM Organisation', 'cf-civicrm' ), 'template' => include CF_CIVICRM_INTEGRATION_PATH . 'form-templates/civicrm-organisation-basic.php' ]; // add organisation with primary contact template $templates['civicrm_org_contact'] = [ - 'name' => esc_html__( 'CiviCRM Organisation and Contact', 'caldera-forms-civicrm' ), + 'name' => esc_html__( 'CiviCRM Organisation and Contact', 'cf-civicrm' ), 'template' => include CF_CIVICRM_INTEGRATION_PATH . 'form-templates/civicrm-organisation-contact.php' ]; diff --git a/languages/caldera-forms-civicrm.pot b/languages/caldera-forms-civicrm.pot index 3f9d530..feb6279 100644 --- a/languages/caldera-forms-civicrm.pot +++ b/languages/caldera-forms-civicrm.pot @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: Caldera Forms CiviCRM 0.2\n" -"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/caldera-forms-civicrm\n" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cf-civicrm\n" "POT-Creation-Date: 2016-09-15 17:36:02+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -288,7 +288,7 @@ msgid "Caldera Forms CiviCRM" msgstr "" #. Plugin URI of the plugin/theme -msgid "https://github.com/mecachisenros/caldera-forms-civicrm" +msgid "https://github.com/mecachisenros/cf-civicrm" msgstr "" #. Description of the plugin/theme diff --git a/mkdocs.yaml b/mkdocs.yaml index a9a97b0..ceca4c2 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -1,5 +1,5 @@ site_name: Caldera Forms CiviCRM -repo_url: https://github.com/mecachisenros/caldera-forms-civicrm +repo_url: https://github.com/mecachisenros/cf-civicrm theme: material markdown_extensions: pages: diff --git a/processors/activity/activity_config.php b/processors/activity/activity_config.php index 0b026c7..d446ce5 100644 --- a/processors/activity/activity_config.php +++ b/processors/activity/activity_config.php @@ -31,21 +31,21 @@ ?> -

+

- +
helper->contact_link_field(); ?> -

+


-

+

- +
$value ) { ?> @@ -69,7 +69,7 @@
- +
@@ -107,7 +107,7 @@
- +
@@ -115,7 +115,7 @@
- +
@@ -139,7 +139,7 @@ } ] .map( function( obj ){ - return { + return { selector: pid_prefix + obj.field, value: obj.value } diff --git a/processors/activity/class-activity-processor.php b/processors/activity/class-activity-processor.php index c561a85..084c77b 100644 --- a/processors/activity/class-activity-processor.php +++ b/processors/activity/class-activity-processor.php @@ -15,10 +15,10 @@ class CiviCRM_Caldera_Forms_Activity_Processor { * @var object $plugin The plugin instance */ public $plugin; - + /** * Contact link. - * + * * @since 0.4.4 * @access protected * @var string $contact_link The contact link @@ -59,8 +59,8 @@ public function __construct( $plugin ) { public function register_processor( $processors ) { $processors[$this->key_name] = [ - 'name' => __( 'CiviCRM Activity', 'caldera-forms-civicrm' ), - 'description' => __( 'Add CiviCRM activity to contact', 'caldera-forms-civicrm' ), + 'name' => __( 'CiviCRM Activity', 'cf-civicrm' ), + 'description' => __( 'Add CiviCRM activity to contact', 'cf-civicrm' ), 'author' => 'Andrei Mondoc', 'template' => CF_CIVICRM_INTEGRATION_PATH . 'processors/activity/activity_config.php', 'processor' => [ $this, 'processor' ], @@ -86,7 +86,7 @@ public function processor( $config, $form, $proccesid ) { // cfc transient object $transient = $this->plugin->transient->get(); $this->contact_link = 'cid_' . $config['contact_link']; - + // Get form values $form_values = $this->plugin->helper->map_fields_to_processor( $config, $form, $form_values ); @@ -105,6 +105,14 @@ public function processor( $config, $form, $proccesid ) { // Concatenate DATE + TIME // $form_values['activity_date_time'] = $form_values['activity_date_time']; + // error message when case_id magic tag hasn't been evaluated + if ( isset( $form_values['case_id'] ) && ! is_numeric( $form_values['case_id'] ) ) { + $notice = __( 'Activity not created due to invalid case_id.', 'cf-civicrm' ); + $transdata['error'] = TRUE; + $transdata['note'] = $notice; + return; + } + try { $activity = civicrm_api3( 'Activity', 'create', $form_values ); } catch ( CiviCRM_API3_Exception $e ) { @@ -119,7 +127,7 @@ public function processor( $config, $form, $proccesid ) { * @since 0.4.2 */ if ( ! empty( $config['file_id'] ) ) - $this->plugin->helper->handle_file_attachments_core( + $this->plugin->helper->handle_file_attachments_core( 'civicrm_activity', $activity['id'], $config['file_id'], diff --git a/processors/address/address_config.php b/processors/address/address_config.php index 2631918..b8f0aa6 100644 --- a/processors/address/address_config.php +++ b/processors/address/address_config.php @@ -15,25 +15,25 @@
- +

-

+


-

+

- +
+
+ +
-

+


-

+

- +
$value ) { ?> @@ -70,12 +72,12 @@
-

+

$value ) { if( $key != 'creator_id' ){ ?>
- +
@@ -84,15 +86,47 @@
- +
+ +

+helper->get_case_custom_fields() as $key => $custom_field ) { ?> +
+ +
+ +
+
+ + diff --git a/processors/case/class-case-processor.php b/processors/case/class-case-processor.php index 798ef2e..d557cb3 100644 --- a/processors/case/class-case-processor.php +++ b/processors/case/class-case-processor.php @@ -15,10 +15,10 @@ class CiviCRM_Caldera_Forms_Case_Processor { * @var object $plugin The plugin instance */ public $plugin; - + /** * Contact link. - * + * * @since 0.4.4 * @access protected * @var string $contact_link The contact link @@ -43,6 +43,8 @@ public function __construct( $plugin ) { $this->plugin = $plugin; // register this processor add_filter( 'caldera_forms_get_form_processors', [ $this, 'register_processor' ] ); + // register case custom fields for autopopulate/presets + add_filter( 'cfc_custom_fields_extends_entities', [ $this, 'custom_fields_extend_case' ] ); } @@ -59,10 +61,11 @@ public function __construct( $plugin ) { public function register_processor( $processors ) { $processors[$this->key_name] = [ - 'name' => __( 'CiviCRM Case', 'caldera-forms-civicrm' ), - 'description' => __( 'Add/Open CiviCRM Case (CiviCase) to contact', 'caldera-forms-civicrm' ), + 'name' => __( 'CiviCRM Case', 'cf-civicrm' ), + 'description' => __( 'Add/Open CiviCRM Case (CiviCase) to contact', 'cf-civicrm' ), 'author' => 'Andrei Mondoc', 'template' => CF_CIVICRM_INTEGRATION_PATH . 'processors/case/case_config.php', + 'pre_processor' => [ $this, 'pre_processor' ], 'processor' => [ $this, 'processor' ], 'magic_tags' => [ 'case_id' ], ]; @@ -71,6 +74,45 @@ public function register_processor( $processors ) { } + /** + * Form pre processor callback. + * + * @since 1.0.3 + * + * @param array $config Processor configuration + * @param array $form Form configuration + * @param string $processid The process id + */ + public function pre_processor( $config, $form, $processid ) { + + // Get form values + $form_values = $this->plugin->helper->map_fields_to_processor( $config, $form, $form_values ); + + /** + * Filter to abort case processing. + * + * To abort a case from being processed return true or, + * to abort the form from processing return an array like: + * [ 'note' => 'Some message', 'type' => 'success|error|info|warning|danger' ] + * The form processing will stop displaying 'Some message' + * + * @since 1.0.3 + * @param bool|array $return Whether to abort the processing of a participant + * @param array $form_values The submitted form values + * @param array $config The processor config + * @param array $form The form config + * @param string $processid The process id + */ + $return = apply_filters( 'cfc_case_pre_processor_return', false, $form_values, $config, $form, $processid ); + + if ( ! $return ) { + // continue, processing happens in 'processor' callback + } else { + return $return; + } + + } + /** * Form processor callback. * @@ -88,11 +130,12 @@ public function processor( $config, $form, $processid ) { // Get form values $form_values = $this->plugin->helper->map_fields_to_processor( $config, $form, $form_values ); - if ( $config['dismiss_case'] ) { + if ( isset( $config['dismiss_case'] ) ) { $existing_cases = civicrm_api3( 'Case', 'get', [ 'sequential' => 1, 'contact_id' => $transient->contacts->{$this->contact_link}, 'case_type_id' => $config['case_type_id'], + 'is_deleted' => 0, 'options' => [ 'limit' => 0 ], ] ); } @@ -100,7 +143,7 @@ public function processor( $config, $form, $processid ) { $form_values['contact_id'] = $transient->contacts->{$this->contact_link}; // Contact ID set in Contact Processor $form_values['case_type_id'] = $config['case_type_id']; // Case Type ID $form_values['case_status_id'] = $config['case_status_id']; // Case Status ID - + if ( ! empty( $config['creator_id'] ) ) $form_values['creator_id'] = strpos( $config['creator_id'], 'contact_' ) !== false ? $transient->contacts->{'cid_' . str_replace( 'contact_', '', $config['creator_id'] )} : $config['creator_id']; // Case Manager @@ -112,11 +155,40 @@ public function processor( $config, $form, $processid ) { } else { try { $create_case = civicrm_api3( 'Case', 'create', $form_values ); + + /** + * Broadcast case cretion + * + * @since 1.0.3 + * @param array $result The api result + * @param array $params The api parameters + * @param array $config The processor config + * @param array $form The form config + */ + do_action( 'cfc_case_processor_case_create', $create_case, $form_values, $config, $form ); + return [ 'case_id' => $create_case['id'] ]; - } catch ( CiviCRM_API3_Exception $e ) { + } catch ( CiviCRM_API3_Exception $e ) { + global $transdata; + $error = $e->getMessage() . '

' . $e->getTraceAsString() . '
'; + $transdata['error'] = true; + $transdata['note'] = $error; + return; } } } + + /** + * Add Case to extend custom fields autopopulation/presets. + * + * @since 1.0.3 + * @param array $extends The entites array + * @return array $extends The filtered entities array + */ + public function custom_fields_extend_case( $extends ) { + $extends[] = 'Case'; + return $extends; + } } diff --git a/processors/contact/class-contact-processor.php b/processors/contact/class-contact-processor.php index dde0513..8e85452 100644 --- a/processors/contact/class-contact-processor.php +++ b/processors/contact/class-contact-processor.php @@ -15,10 +15,10 @@ class CiviCRM_Caldera_Forms_Contact_Processor { * @var object $plugin The plugin instance */ public $plugin; - + /** * Contact link. - * + * * @since 0.4.4 * @access protected * @var string $contact_link The contact link @@ -79,8 +79,8 @@ public function __construct( $plugin ) { public function register_processor( $processors ) { $processors[$this->key_name] = [ - 'name' => __( 'CiviCRM Contact', 'caldera-forms-civicrm' ), - 'description' => __( 'Create CiviCRM contact', 'caldera-forms-civicrm' ), + 'name' => __( 'CiviCRM Contact', 'cf-civicrm' ), + 'description' => __( 'Create CiviCRM contact', 'cf-civicrm' ), 'author' => 'Andrei Mondoc', 'template' => CF_CIVICRM_INTEGRATION_PATH . 'processors/contact/contact_config.php', 'pre_processor' => [ $this, 'pre_processor' ], @@ -152,7 +152,7 @@ public function pre_processor( $config, $form, $processid ) { $first_contact_processor = array_reverse( $form['processors'] ); $first_contact_processor = array_pop( $first_contact_processor ); - if ( is_array( $first_contact_processor ) && $first_contact_processor['ID'] == $config['processor_id'] ) { + if ( is_array( $first_contact_processor ) && $first_contact_processor['ID'] == $config['processor_id'] && isset( $config['auto_pop'] ) ) { // logged in contact $contact = $this->plugin->helper->get_current_contact(); // if not logged in, do dedupe @@ -190,14 +190,14 @@ public function pre_processor( $config, $form, $processid ) { try { $file = civicrm_api3( 'File', 'getsingle', [ 'id' => $form_values['civicrm_contact']['image_URL'] ] ); } catch ( CiviCRM_API3_Exception $e ) { - + } if ( is_array( $file ) && ! $file['is_error'] ) $form_values['civicrm_contact']['image_URL'] = CRM_Utils_System::url( 'civicrm/contact/imagefile', ['photo' => $file['uri']], true ); } - // contact reference field for organization maps to an array [ 'organization_name' => , 'employer_id' => ] + // contact reference field for organization maps to an array [ 'organization_name' => , 'employer_id' => ] if ( ! empty( $form_values['civicrm_contact']['current_employer'] ) && is_array( $form_values['civicrm_contact']['current_employer'] ) ) { $org = $form_values['civicrm_contact']['current_employer']; $form_values['civicrm_contact']['current_employer'] = $org['organization_name']; @@ -273,10 +273,10 @@ public function pre_processor( $config, $form, $processid ) { if ( $field_type['data_type'] == 'File' ) { foreach ( $file_fields[$cf_field['ID']]['files'] as $file_id => $file ) { - $this->plugin->helper->create_civicrm_entity_file( - $field_type['custom_group_id.table_name'], - $transient->contacts->{$this->contact_link}, - $file_id + $this->plugin->helper->create_civicrm_entity_file( + $field_type['custom_group_id.table_name'], + $transient->contacts->{$this->contact_link}, + $file_id ); } } @@ -310,7 +310,7 @@ public function pre_processor( $config, $form, $processid ) { * @param array $form_values The field values beeing submitted */ public function process_address( $config, $form, $transient, &$form_values ){ - + if ( ! empty( $transient->contacts->{$this->contact_link} ) ) { try { @@ -384,7 +384,7 @@ public function process_phone( $config, $form, $transient, &$form_values ){ // Get form values $form_values = $this->plugin->helper->map_fields_to_processor( $config, $form, $form_values, 'civicrm_phone' ); - + if( ! empty( $form_values['civicrm_phone'] ) ) { $form_values['civicrm_phone']['contact_id'] = $transient->contacts->{$this->contact_link}; // Contact ID set in Contact Processor $form_values['civicrm_phone']['location_type_id'] = $config['civicrm_phone']['location_type_id']; @@ -684,7 +684,7 @@ public function pre_render( $form ) { if ( isset( $pr_id['config']['auto_pop'] ) && $pr_id['config']['auto_pop'] == 1 && $civicrm_contact_pr[0]['ID'] == $pr_id['ID'] ) // get contact data $contact = $this->plugin->helper->current_contact_data_get(); - + // Map CiviCRM contact data to form defaults if ( isset( $contact ) && is_array( $contact ) ) { // contact link reference diff --git a/processors/contact/contact_config.php b/processors/contact/contact_config.php index 46118d3..6c73d08 100644 --- a/processors/contact/contact_config.php +++ b/processors/contact/contact_config.php @@ -1,47 +1,47 @@
- +
- +
- +
- +
- +
- +
- +
- +
- +
@@ -71,20 +71,20 @@ ?> -

+


-

+

- +
@@ -110,7 +110,7 @@
- +
+

-

+

- +
@@ -266,7 +266,7 @@
- +
@@ -492,14 +492,14 @@ $tagResult = $result = civicrm_api3( 'Tag', 'get', [ 'sequential' => 1, 'used_for' => 'civicrm_contact', - 'options' => [ 'limit' => 0 ], + 'options' => [ 'limit' => 0 ], ] ); ?>
- +