Skip to content

Commit

Permalink
Move form settings to form editing view, don't store in config (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Aug 23, 2024
1 parent 96601d7 commit 71ed94f
Show file tree
Hide file tree
Showing 23 changed files with 572 additions and 297 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ composer.lock
mix-manifest.json
package-lock.json
yarn.lock
.idea/*
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,24 @@ php artisan vendor:publish --tag="campaign-monitor-config"

## Usage

Create your Statamic [forms](https://statamic.dev/forms#content) as usual. Don't forget to add the consent field to your blueprint.
Create your Statamic [forms](https://statamic.dev/forms#content) as usual. When editing the form you'll see a "Campaign Monitor Integration" section where you can configure if and how that form integrates with Campaign Monitor.

Don't forget to add the consent field to your blueprint.

You can also manage if new users are added a list using the dedicated settings view in the control panel.

*Configuration in the Control Panel:*

![control panel](https://raw.githubusercontent.com/statamic-rad-pack/campaign-monitor/main/images/config.png)


### Data storage

Any user related settings are stored by default in `resources/campaign_monitor.yaml`.

If you want to change this or use a different data store, you can bind `\StatamicRadPack\Mailchimp\UserConfig::class` in your app service provider. You should modify the `getSavedSettings`, `save`, and `exists` methods according to your requirements.


## Testing

Run the tests with:
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
"require": {
"php": "^8.1",
"bashy/laravel-campaignmonitor": "^6.0",
"edalzell/forma": "^3.0",
"laravel/framework": "^10.25.0 || ^11.0",
"pixelfear/composer-dist-plugin": "^0.1",
"statamic/cms": "^4.0 || ^5.0"
"statamic/cms": "^5.18",
"stillat/proteus": "^4.0"
},
"require-dev": {
"jasonmccreary/laravel-test-assertions": "^2.0",
"laravel/pint": "^1.17",
"mockery/mockery": "^1.3.1",
"orchestra/testbench": "^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^9.0 || ^10.0"
Expand Down Expand Up @@ -54,6 +55,5 @@
"description": "Campaign Monitor addon",
"name": "Campaign Monitor"
}
},
"minimum-stability": "alpha"
}
}
79 changes: 1 addition & 78 deletions config/campaign-monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,6 @@
return [

'api_key' => env('CAMPAIGNMONITOR_API_KEY'),

'client_id' => env('CAMPAIGNMONITOR_CLIENT_ID'),

/*
* Set to `true` to add new user registrations to a Campaign Monitor list
*/
'add_new_users' => false,

'users' => [
/*
* A Campaign Monitor List ID.
*
*/
'list_id' => null,

/*
* Set to `true` to require consent before subscribing someone
* Default: `true`
*/
'check_consent' => true,

/*
* Field name used to check for consent.
* Default: 'consent'
*/
'consent_field' => 'consent',

/*
* Set to `true` to require consent before SMS subscribing someone
* Default: `true`
*/
'check_consent_sms' => true,

/*
* Field name used to check for consent.
* Default: 'consent_sms'
*/
'consent_field_sms' => 'consent_sms',

/*
* Store information about your contacts with custom fields.
*/
'custom_fields' => [
// [
// /*
// * The Campaign Monitor key
// */
// 'key'=> null,

// /*
// * Blueprint field name to use for the merge field
// */
// 'field_name' => null,
// ],
],

/*
* Field that contains the mobile number
* Default: 'mobile'
*/
'mobile_field' => 'mobile',

/*
* Field that contains the name
* Default: 'name'
*/
'name_field' => 'name',

/*
* Field that contains the primary email address
* Default: 'email'
*/
'primary_email_field' => 'email',
],

/*
* The form submissions to add to your Campaign Monitor lists
*/
'forms' => [],
'client_id' => env('CAMPAIGNMONITOR_CLIENT_ID'),
];
Binary file modified images/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 7 additions & 136 deletions resources/blueprints/config.yaml
Original file line number Diff line number Diff line change
@@ -1,133 +1,4 @@
tabs:
forms:
display: 'Forms'
sections:
-
fields:
-
handle: forms
field:
fields:
-
handle: form
field:
display: Form
type: form
max_items: 1
mode: select
width: 33
-
handle: list_id
field:
display: 'List ID'
type: campaign_monitor_list
mode: select
max_items: 1
width: 33
-
handle: name_field
field:
display: 'Name Field'
type: campaign_monitor_form_fields
max_items: 1
default: name
width: 33
-
handle: primary_email_field
field:
display: 'Email Field'
type: campaign_monitor_form_fields
max_items: 1
default: email
width: 33
-
handle: check_consent
field:
display: 'Check Consent?'
type: toggle
width: 33
default: false
-
handle: consent_field
field:
display: 'Consent Field'
type: campaign_monitor_form_fields
default: consnet
width: 33
if:
check_consent: true
-
handle: spacer_field
field:
display: 'Consent Field'
type: spacer
width: 33
if:
check_consent: false
-
handle: mobile_field
field:
display: 'Mobile Number Field'
type: campaign_monitor_form_fields
default: mobile
width: 33
-
handle: check_consent_sms
field:
display: 'Check Consent to SMS?'
type: toggle
width: 33
default: false
-
handle: consent_field_sms
field:
display: 'SMS Consent Field'
type: campaign_monitor_form_fields
default: consent_sms
width: 33
if:
check_consent_sms: true
-
handle: spacer_field_sms
field:
display: 'Consent Field'
type: spacer
width: 33
if:
check_consent_sms: false
-
handle: custom_fields
field:
fields:
-
handle: field_name
field:
input_type: text
display: Form Field
type: campaign_monitor_form_fields
icon: text
listable: hidden
-
handle: key
field:
input_type: text
display: 'Custom Field'
type: campaign_monitor_custom_fields
max_items: 1
icon: text
listable: hidden
mode: table
reorderable: true
display: 'Custom Fields'
type: grid
icon: grid
add_row: 'Add Custom Field'
listable: hidden
display: ' '
type: grid
mode: stacked
add_row: 'Add Form'
instructions: 'Add the forms you want to process Campaign Monitor submissions for.'
users:
display: 'Users'
sections:
Expand Down Expand Up @@ -155,7 +26,7 @@ tabs:
handle: name_field
field:
display: 'Name Field'
type: campaign_monitor_form_fields
type: campaign_monitor_user_fields
max_items: 1
default: name
width: 33
Expand All @@ -169,7 +40,7 @@ tabs:
handle: primary_email_field
field:
display: 'Email Field'
type: campaign_monitor_form_fields
type: campaign_monitor_user_fields
max_items: 1
default: email
width: 33
Expand All @@ -184,7 +55,7 @@ tabs:
handle: consent_field
field:
display: 'Consent Field'
type: campaign_monitor_form_fields
type: campaign_monitor_user_fields
default: consnet
width: 33
if:
Expand All @@ -201,7 +72,7 @@ tabs:
handle: mobile_field
field:
display: 'Mobile Number Field'
type: campaign_monitor_form_fields
type: campaign_monitor_user_fields
default: mobile
width: 33
-
Expand All @@ -215,7 +86,7 @@ tabs:
handle: consent_field_sms
field:
display: 'SMS Consent Field'
type: campaign_monitor_form_fields
type: campaign_monitor_user_fields
default: consent_sms
width: 33
if:
Expand All @@ -237,7 +108,7 @@ tabs:
field:
input_type: text
display: Form Field
type: campaign_monitor_form_fields
type: campaign_monitor_user_fields
icon: text
listable: hidden
-
Expand All @@ -257,12 +128,12 @@ tabs:
add_row: 'Add Custom Field'
listable: hidden
display: ' '
instructions: 'Add the forms you want to process Campaign Monitor submissions for.'
type: grid
mode: stacked
max_rows: 1
min_rows: 1
reorderable: false
fullscreen: false
if:
add_new_users: 'equals true'
credentials:
Expand Down
10 changes: 8 additions & 2 deletions resources/js/components/fieldtypes/CustomFieldsFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export default {
computed: {
key() {
let matches = this.namePrefix.match(/([a-z]*?)\[(.*?)\]/);
let matches = this.namePrefix.match(/([a-z_]*?)\[(.*?)\]/);
if (matches[1] == 'campaign_monitor') { // form page
return 'campaign_monitor.settings.list_id.0';
}
return matches[0].replace('[', '.').replace(']', '.') + 'list_id.0';
},
Expand All @@ -62,7 +67,8 @@ export default {
.get(cp_url(`/campaign-monitor/custom-fields/${this.list}`))
.then(response => {
this.fields = response.data;
});
})
.catch(() => { this.fields = []; });
}
}
};
Expand Down
13 changes: 3 additions & 10 deletions resources/js/components/fieldtypes/FormFieldsFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,8 @@ export default {
computed: {
form() {
let key = 'forms.' + this.row + '.form.0' ;
return data_get(this.$store.state.publish[this.storeName].values, key)
return StatamicConfig.urlPath.split('/')[1] ?? '';
},
row() {
let matches = this.namePrefix.match(/\[(.*?)\]/);
return matches[1];
}
},
mounted() {
Expand All @@ -66,7 +58,8 @@ export default {
.get(cp_url(`/campaign-monitor/form-fields/${this.form}`))
.then(response => {
this.fields = response.data;
});
})
.catch(() => { this.fields = []; });
}
}
};
Expand Down
Loading

0 comments on commit 71ed94f

Please sign in to comment.