2017 © Pedro Peláez
 

silverstripe-module silverstripe-campaignmonitor

Simple implementation of the campaign monitor API within Silverstripe

image

tractorcow/silverstripe-campaignmonitor

Simple implementation of the campaign monitor API within Silverstripe

  • Monday, November 20, 2017
  • by tractorcow
  • Repository
  • 1 Watchers
  • 6 Stars
  • 12,118 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 2 Versions
  • 10 % Grown

The README.md

Campaign monitor wrapper module for Silverstripe

Simple implementation of the campaign monitor API within Silverstripe, (*1)

Credits and Authors

License

  • TODO

Requirements

  • SilverStripe ^4
  • PHP ^7.1
  • Campaign Monitor PHP library 6.0.0

Installation instructions

composer require tractorcow/silverstripe-campaignmonitor

Examples

Using the API to set a destination list (SiteConfig extension)

Given a hard coded API key, allow the user to select a client from their account, and subsequently a list., (*2)


function updateCMSFields(FieldList $fields) { // Load base object $resources = CMResources::create("my api key"); // Get clients under our account $clients = $resources->Clients()->map(); $fields->addFieldToTab( 'Root.CampaignMonitor', DropdownField::create('Client', 'Client', $clients) ); // check if client is available to select if($this->owner->Client && ($client = $resources->getClient($this->owner->Client))) { $lists = $client->Lists()->map(); $fields->addFieldToTab( 'Root.CampaignMonitor', DropdownField::create('DefaultList', 'Default List', $lists) ); } }

Saving a subscriber

Handling subscription details from a form submission, (*3)


public function subscribe($data, $form) { $listID = SiteConfig::current_site_config()->DefaultList; $resources = CMResources::create("my api key"); if($resources && $listID && $list = $resources->getList($listID)) { $this->addUserToList($data, $list); Director::redirect($this->Link('thanks')); } // Error handling here } protected function addUserToList($data, $list) { if(empty($list)) return; // Create subscriber $fields = [ 'EmailAddress' => $data['Email'], 'Name' => $data['FirstName'], 'CustomFields' => [ 'LastName' => $data['LastName'], 'Company' => $data['Company'], 'Phone' => $data['Phone'], 'Mobile' => $data['Mobile'] ], 'Resubscribe' => true, 'RestartSubscriptionBasedAutoresponders' => true ]; $subscriber = CMSubscriber::create(null, $fields, $list); $subscriber->Save(); }

The Versions

20/11 2017

dev-master

9999999-dev

Simple implementation of the campaign monitor API within Silverstripe

  Sources   Download

The Requires

 

silverstripe campaign monitor

15/03 2015

3.0.x-dev

3.0.9999999.9999999-dev

Simple implementation of the campaign monitor API within Silverstripe

  Sources   Download

The Requires

 

silverstripe campaign monitor