-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
075ab99
commit ff3e90d
Showing
14 changed files
with
1,091 additions
and
3 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,297 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of SilverWare. | ||
* | ||
* PHP version >=5.6.0 | ||
* | ||
* For full copyright and license information, please view the | ||
* LICENSE.md file that was distributed with this source code. | ||
* | ||
* @package SilverWare\MailChimp\Pages | ||
* @author Colin Tucker <[email protected]> | ||
* @copyright 2018 Praxis Interactive | ||
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @link https://github.com/praxisnetau/silverware-mailchimp | ||
*/ | ||
|
||
namespace SilverWare\MailChimp\Pages; | ||
|
||
use SilverStripe\Forms\CheckboxField; | ||
use SilverStripe\Forms\FieldGroup; | ||
use SilverStripe\Forms\TextField; | ||
use SilverWare\Forms\FieldSection; | ||
use SilverWare\MailChimp\Forms\MailChimpListField; | ||
use Page; | ||
|
||
/** | ||
* An extension of the page class for a MailChimp subscribe page. | ||
* | ||
* @package SilverWare\MailChimp\Pages | ||
* @author Colin Tucker <[email protected]> | ||
* @copyright 2018 Praxis Interactive | ||
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @link https://github.com/praxisnetau/silverware-ma | ||
*/ | ||
class SubscribePage extends Page | ||
{ | ||
/** | ||
* Human-readable singular name. | ||
* | ||
* @var string | ||
* @config | ||
*/ | ||
private static $singular_name = 'Subscribe Page'; | ||
|
||
/** | ||
* Human-readable plural name. | ||
* | ||
* @var string | ||
* @config | ||
*/ | ||
private static $plural_name = 'Subscribe Pages'; | ||
|
||
/** | ||
* Description of this object. | ||
* | ||
* @var string | ||
* @config | ||
*/ | ||
private static $description = 'Allows a user to subscribe to a MailChimp mailing list'; | ||
|
||
/** | ||
* Icon file for this object. | ||
* | ||
* @var string | ||
* @config | ||
*/ | ||
private static $icon = 'silverware/mailchimp: admin/client/dist/images/icons/SubscribePage.png'; | ||
|
||
/** | ||
* Defines the table name to use for this object. | ||
* | ||
* @var string | ||
* @config | ||
*/ | ||
private static $table_name = 'SilverWare_MailChimp_SubscribePage'; | ||
|
||
/** | ||
* Maps field names to field types for this object. | ||
* | ||
* @var array | ||
* @config | ||
*/ | ||
private static $db = [ | ||
'ListID' => 'Varchar(32)', | ||
'ShowFirstName' => 'Boolean', | ||
'ShowLastName' => 'Boolean', | ||
'RequireFirstName' => 'Boolean', | ||
'RequireLastName' => 'Boolean', | ||
'OnErrorMessage' => 'Varchar(255)', | ||
'OnSubscribeMessage' => 'Varchar(255)', | ||
'OnAlreadySubscribedMessage' => 'Varchar(255)' | ||
]; | ||
|
||
/** | ||
* Defines the default values for the fields of this object. | ||
* | ||
* @var array | ||
* @config | ||
*/ | ||
private static $defaults = [ | ||
'ShowFirstName' => 1, | ||
'RequireFirstName' => 1 | ||
]; | ||
|
||
/** | ||
* Answers a list of field objects for the CMS interface. | ||
* | ||
* @return FieldList | ||
*/ | ||
public function getCMSFields() | ||
{ | ||
// Obtain Field Objects (from parent): | ||
|
||
$fields = parent::getCMSFields(); | ||
|
||
// Add Status Message (if exists): | ||
|
||
$fields->addStatusMessage($this->getSiteConfig()->getMailChimpStatusMessage()); | ||
|
||
// Define Placeholder: | ||
|
||
$placeholder = _t(__CLASS__ . '.DROPDOWNSELECT', 'Select'); | ||
|
||
// Create Main Fields: | ||
|
||
$fields->addFieldToTab( | ||
'Root.Main', | ||
MailChimpListField::create( | ||
'ListID', | ||
$this->fieldLabel('ListID') | ||
)->setEmptyString(' ')->setAttribute('data-placeholder', $placeholder), | ||
'Content' | ||
); | ||
|
||
// Create Options Fields: | ||
|
||
$fields->addFieldsToTab( | ||
'Root.Options', | ||
[ | ||
FieldSection::create( | ||
'FieldOptions', | ||
$this->fieldLabel('Fields'), | ||
[ | ||
FieldGroup::create( | ||
$this->fieldLabel('ShowFields'), | ||
[ | ||
CheckboxField::create( | ||
'ShowFirstName', | ||
$this->fieldLabel('FirstName') | ||
), | ||
CheckboxField::create( | ||
'ShowLastName', | ||
$this->fieldLabel('LastName') | ||
) | ||
] | ||
), | ||
FieldGroup::create( | ||
$this->fieldLabel('RequireFields'), | ||
[ | ||
CheckboxField::create( | ||
'RequireFirstName', | ||
$this->fieldLabel('FirstName') | ||
), | ||
CheckboxField::create( | ||
'RequireLastName', | ||
$this->fieldLabel('LastName') | ||
) | ||
] | ||
) | ||
] | ||
), | ||
FieldSection::create( | ||
'MessageOptions', | ||
$this->fieldLabel('Messages'), | ||
[ | ||
TextField::create( | ||
'OnSubscribeMessage', | ||
$this->fieldLabel('OnSubscribeMessage') | ||
)->setRightTitle( | ||
_t( | ||
__CLASS__ . '.ONSUBSCRIBEMESSAGERIGHTTITLE', | ||
'Shown to the user after subscribing.' | ||
) | ||
), | ||
TextField::create( | ||
'OnAlreadySubscribedMessage', | ||
$this->fieldLabel('OnAlreadySubscribedMessage') | ||
)->setRightTitle( | ||
_t( | ||
__CLASS__ . '.ONALREADYSUBSCRIBEDMESSAGERIGHTTITLE', | ||
'Shown to the user if they have already subscribed.' | ||
) | ||
), | ||
TextField::create( | ||
'OnErrorMessage', | ||
$this->fieldLabel('OnErrorMessage') | ||
)->setRightTitle( | ||
_t( | ||
__CLASS__ . '.ONERRORMESSAGERIGHTTITLE', | ||
'Shown to the user when an error occurs.' | ||
) | ||
) | ||
] | ||
) | ||
] | ||
); | ||
|
||
// Answer Field Objects: | ||
|
||
return $fields; | ||
} | ||
|
||
/** | ||
* Answers the labels for the fields of the receiver. | ||
* | ||
* @param boolean $includerelations Include labels for relations. | ||
* | ||
* @return array | ||
*/ | ||
public function fieldLabels($includerelations = true) | ||
{ | ||
// Obtain Field Labels (from parent): | ||
|
||
$labels = parent::fieldLabels($includerelations); | ||
|
||
// Define Field Labels: | ||
|
||
$labels['ListID'] = _t(__CLASS__ . '.MAILINGLIST', 'Mailing List'); | ||
$labels['Fields'] = _t(__CLASS__ . '.FIELDS', 'Fields'); | ||
$labels['Messages'] = _t(__CLASS__ . '.MESSAGES', 'Messages'); | ||
$labels['LastName'] = _t(__CLASS__ . '.REQUIRELASTNAME', 'Last name'); | ||
$labels['FirstName'] = _t(__CLASS__ . '.REQUIREFIRSTNAME', 'First name'); | ||
$labels['ShowFields'] = _t(__CLASS__ . '.SHOWFIELDS', 'Show fields'); | ||
$labels['RequireFields'] = _t(__CLASS__ . '.REQUIREFIELDS', 'Require fields'); | ||
|
||
// Define Message Field Labels: | ||
|
||
$labels['OnErrorMessage'] = _t( | ||
__CLASS__ . '.ONERRORMESSAGE', | ||
'On Error message' | ||
); | ||
|
||
$labels['OnSubscribeMessage'] = _t( | ||
__CLASS__ . '.ONSUBSCRIBEMESSAGE', | ||
'On Subscribe message' | ||
); | ||
|
||
$labels['OnAlreadySubscribedMessage'] = _t( | ||
__CLASS__ . '.ONALREADYSUBSCRIBEDMESSAGE', | ||
'On Already Subscribed message' | ||
); | ||
|
||
// Answer Field Labels: | ||
|
||
return $labels; | ||
} | ||
|
||
/** | ||
* Populates the default values for the fields of the receiver. | ||
* | ||
* @return void | ||
*/ | ||
public function populateDefaults() | ||
{ | ||
// Populate Defaults (from parent): | ||
|
||
parent::populateDefaults(); | ||
|
||
// Populate Defaults: | ||
|
||
$this->OnErrorMessage = _t( | ||
__CLASS__ . '.DEFAULTONERRORMESSAGE', | ||
'Sorry, an error has occurred. Please try again later.' | ||
); | ||
|
||
$this->OnSubscribeMessage = _t( | ||
__CLASS__ . '.DEFAULTONSUBSCRIBEMESSAGE', | ||
'Thank you for subscribing to our mailing list.' | ||
); | ||
|
||
$this->OnAlreadySubscribedMessage = _t( | ||
__CLASS__ . '.DEFAULTONALREADYSUBSCRIBEDMESSAGE', | ||
'You have already subscribed to our mailing list.' | ||
); | ||
} | ||
|
||
/** | ||
* Answers a message string to be shown when no list is available. | ||
* | ||
* @return string | ||
*/ | ||
public function getNoListMessage() | ||
{ | ||
return _t(__CLASS__ . '.NOLISTAVAILABLE', 'No list available.'); | ||
} | ||
} |
Oops, something went wrong.