Skip to content

Commit

Permalink
Merge pull request #119 from mecachisenros/dev
Browse files Browse the repository at this point in the history
Improvements and fixes
  • Loading branch information
mecachisenros authored Jul 20, 2019
2 parents 6eaf50f + 4168c1d commit bf7f07b
Show file tree
Hide file tree
Showing 72 changed files with 1,243 additions and 838 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 9 additions & 9 deletions caldera-forms-civicrm.php → cf-civicrm.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
/**
* Plugin Name: Caldera Forms CiviCRM
* Plugin Name: CF CiviCRM
* Description: CiviCRM integration for Caldera Forms.
* Version: 1.0.2
* Version: 1.0.3
* Author: Andrei Mondoc
* Author URI: https://github.com/mecachisenros
* Plugin URI: https://github.com/mecachisenros/caldera-forms-civicrm
* GitHub Plugin URI: mecachisenros/caldera-forms-civicrm
* Text Domain: caldera-forms-civicrm
* Plugin URI: https://github.com/mecachisenros/cf-civicrm
* GitHub Plugin URI: mecachisenros/cf-civicrm
* Text Domain: cf-civicrm
* Domain Path: /languages
*/

Expand All @@ -16,7 +16,7 @@
*
* @since 0.1
*/
define( 'CF_CIVICRM_INTEGRATION_VER', '1.0.2' );
define( 'CF_CIVICRM_INTEGRATION_VER', '1.0.3' );
define( 'CF_CIVICRM_INTEGRATION_URL', plugin_dir_url( __FILE__ ) );
define( 'CF_CIVICRM_INTEGRATION_PATH', plugin_dir_path( __FILE__ ) );

Expand Down Expand Up @@ -291,13 +291,13 @@ private function register_hooks() {

/**
* Cladera Forms version notice.
*
*
* @since 0.4.4
*/
public function caldera_forms_version_notice() {
?>
<div class="notice notice-error">
<p><?php _e( 'Caldera Forms CiviCRM requires Caldera Forms v1.8.1 or higher.', 'caldera-forms-civicrm' ); ?></p>
<p><?php _e( 'Caldera Forms CiviCRM requires Caldera Forms v1.8.1 or higher.', 'cf-civicrm' ); ?></p>
</div>
<?php
}
Expand All @@ -314,7 +314,7 @@ public function enable_translation() {

// load translations if present
load_plugin_textdomain(
'caldera-forms-civicrm', // unique name
'cf-civicrm', // unique name
false, // deprecated argument
dirname( plugin_basename( __FILE__ ) ) . '/languages/' // relative path to translation files
);
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Caldera Forms uses Processors to extend what can be done with forms. By installing and activating the Caldera Forms CiviCRM plugin new processors are added to allow information from forms to be added or updated in CiviCRM.

![Caldera Forms CiviCRM Processors](./images/caldera-forms-civicrm-processors.jpg)
![Caldera Forms CiviCRM Processors](./images/cf-civicrm-processors.jpg)

Select and configure the processors needed for each form to send the wanted information to their CiviCRM contact record.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public function register_hooks() {
public function register_field_type( $field_types ) {

$field_types[$this->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' => [
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

}

}
18 changes: 9 additions & 9 deletions fields/civicrm_contact_reference/config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
$contact_types = civicrm_api3( 'ContactType', 'get', [
'sequential' => 0,
'is_active' => 1,
Expand Down Expand Up @@ -28,7 +28,7 @@
<!-- Contact Type -->
<div class="{{_id}}_contact_type caldera-config-group">
<label for="{{_id}}_contact_type">
<?php esc_html_e( 'Contact Type', 'caldera-forms-civicrm' ); ?>
<?php esc_html_e( 'Contact Type', 'cf-civicrm' ); ?>
</label>
<div class="caldera-config-field">
<select class="block-input field-config" name="{{_name}}[contact_type]">
Expand All @@ -38,7 +38,7 @@
<?php } ?>
</select>
<p class="description" id="{{_id}}_contact_type">
<?php esc_html_e( 'Limit by Contacts Type.', 'caldera-forms-civicrm' ); ?>
<?php esc_html_e( 'Limit by Contacts Type.', 'cf-civicrm' ); ?>
</p>
</div>
</div>
Expand All @@ -47,7 +47,7 @@
<?php if ( $contact_sub_types['count'] ) : ?>
<div class="{{_id}}_contact_sub_type caldera-config-group">
<label for="{{_id}}_contact_sub_type">
<?php esc_html_e( 'Contact Subtype', 'caldera-forms-civicrm' ); ?>
<?php esc_html_e( 'Contact Subtype', 'cf-civicrm' ); ?>
</label>
<div class="caldera-config-field">
<select class="block-input field-config" name="{{_name}}[contact_sub_type]">
Expand All @@ -57,7 +57,7 @@
<?php } ?>
</select>
<p class="description">
<?php esc_html_e( 'Limit by Contact Subtype.', 'caldera-forms-civicrm' ); ?>
<?php esc_html_e( 'Limit by Contact Subtype.', 'cf-civicrm' ); ?>
</p>
</div>
</div>
Expand All @@ -66,25 +66,25 @@
<!-- Groups -->
<div class="caldera-config-group">
<label for="{{_id}}_civicrm_group">
<?php esc_html_e( 'Group', 'caldera-forms-civicrm' ); ?>
<?php esc_html_e( 'Group', 'cf-civicrm' ); ?>
</label>
<div class="caldera-config-field">
<select id="{{_id}}_civicrm_group" class="block-input field-config" name="{{_name}}[civicrm_group]" nonce="<?php echo wp_create_nonce('admin_get_groups'); ?>">
</select>
<p class="description">
<?php esc_html_e( 'Limit to contacts in group.', 'caldera-forms-civicrm' ); ?>
<?php esc_html_e( 'Limit to contacts in group.', 'cf-civicrm' ); ?>
</p>
</div>
</div>

<!-- New organization -->
<div class="{{_id}}_new_organization caldera-config-group">
<label for="{{_id}}_new_organization"><?php esc_html_e( 'New organization', 'caldera-forms-civicrm' ); ?></label>
<label for="{{_id}}_new_organization"><?php esc_html_e( 'New organization', 'cf-civicrm' ); ?></label>
<div class="caldera-config-field">
<input type="checkbox" class="field-config field-checkbox" name="{{_name}}[new_organization]" value="1" {{#if new_organization}}checked="checked"{{/if}}>
</div>
<p class="description">
<?php esc_html_e( 'Enable to allow user to enter a new value (Oraganization).', 'caldera-forms-civicrm' ); ?>
<?php esc_html_e( 'Enable to allow user to enter a new value (Oraganization).', 'cf-civicrm' ); ?>
</p>
</div>

Expand Down
12 changes: 6 additions & 6 deletions fields/civicrm_country/class-civicrm-country.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
],
],
Expand Down Expand Up @@ -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' );
Expand Down
4 changes: 2 additions & 2 deletions fields/civicrm_country/config.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php $countries = caldera_forms_civicrm()->helper->get_countries(); ?>
<div class="caldera-config-group">
<label><?php _e( 'Placeholder', 'caldera-forms-civicrm' ); ?></label>
<label><?php _e( 'Placeholder', 'cf-civicrm' ); ?></label>
<div class="caldera-config-field">
<input type="text" id="{{_id}}_placeholder" class="block-input field-config" name="{{_name}}[placeholder]" value="{{placeholder}}">
</div>
</div>
<div class="caldera-config-group">
<label><?php _e( 'Default', 'caldera-forms-civicrm' ); ?></label>
<label><?php _e( 'Default', 'cf-civicrm' ); ?></label>
<div class="caldera-config-field">
<select id="{{_id}}_default" class="block-input field-config" name="{{_name}}[default]" value="{{default}}">
<option value="" {{#is default value=""}}selected="selected"{{/is}}></option>
Expand Down
2 changes: 1 addition & 1 deletion fields/civicrm_file/advanced_file_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="caldera-config-field">
<label for="{{_id}}_civicrm_file_upload">
<input id="{{_id}}_civicrm_file_upload" type="checkbox" class="field-config" name="{{_name}}[civicrm_file_upload]" {{#if civicrm_file_upload}}checked="checked"{{/if}} value="1">
<?php _e( 'CiviCRM File Upload', 'caldera-forms-civicrm' ); ?></label>
<?php _e( 'CiviCRM File Upload', 'cf-civicrm' ); ?></label>
</div>
</div>
{{#script}}
Expand Down
2 changes: 1 addition & 1 deletion fields/civicrm_file/file_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="caldera-config-field">
<label for="{{_id}}_civicrm_file_upload">
<input id="{{_id}}_civicrm_file_upload" type="checkbox" class="field-config" name="{{_name}}[civicrm_file_upload]" {{#if civicrm_file_upload}}checked="checked"{{/if}} value="1">
<?php _e( 'CiviCRM File Upload', 'caldera-forms-civicrm' ); ?></label>
<?php _e( 'CiviCRM File Upload', 'cf-civicrm' ); ?></label>
</div>
</div>
{{#script}}
Expand Down
8 changes: 4 additions & 4 deletions fields/civicrm_premium/class-civicrm-premium.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
];
Expand Down
Loading

0 comments on commit bf7f07b

Please sign in to comment.