Source of file SubscribePage.php
Size: 9,302 Bytes - Last Modified: 2021-12-23T10:36:56+00:00
/var/www/docs.ssmods.com/process/src/src/Pages/SubscribePage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 | <?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 <colin@praxis.net.au> * @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 <colin@praxis.net.au> * @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.'); } } |