本文整理汇总了PHP中FieldList::create方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldList::create方法的具体用法?PHP FieldList::create怎么用?PHP FieldList::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FieldList
的用法示例。
在下文中一共展示了FieldList::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCMSFields
public function getCMSFields()
{
$datetimeField = DatetimeField::create("Date")->setTitle($this->fieldLabel("Date"));
$datetimeField->getDateField()->setConfig("dmyfields", true);
// Check if NewsImage should be saved in a seperate folder
if (self::config()->save_image_in_seperate_folder == false) {
$UploadField = UploadField::create("NewsImage")->setTitle($this->fieldLabel("NewsImage"))->setFolderName("news");
} else {
if ($this->ID == "0") {
$UploadField = FieldGroup::create(LiteralField::create("Save", $this->fieldLabel("SaveHelp")))->setTitle($this->fieldLabel("NewsImage"));
} else {
$UploadField = UploadField::create("NewsImage")->setTitle($this->fieldLabel("NewsImage"))->setFolderName("news/" . $this->URLSegment);
}
}
// Create direct link to NewsArticle
if ($this->ID == "0") {
// Little hack to hide $urlsegment when article isn't saved yet.
$urlsegment = LiteralField::create("NoURLSegmentYet", "");
} else {
if ($NewsHolder = $this->NewsHolder()) {
$baseLink = Controller::join_links(Director::absoluteBaseURL(), $NewsHolder->Link(), $this->URLSegment);
}
$urlsegment = Fieldgroup::create(LiteralField::create("URLSegment", "URLSegment")->setContent('<a href="' . $baseLink . '" target="_blank">' . $baseLink . '</a>'))->setTitle("URLSegment");
}
$fields = FieldList::create(new TabSet("Root", new Tab("Main", $urlsegment, TextField::create("Title")->setTitle($this->fieldLabel("Title")), $datetimeField, HTMLEditorField::create("Content")->setTitle($this->fieldLabel("Content")), $UploadField)));
$this->extend("updateCMSFields", $fields);
return $fields;
}
示例2: getCMSFields
/**
* getCMSFields
* Construct the FieldList used in the CMS. To provide a
* smarter UI we don't use the scaffolding provided by
* parent::getCMSFields.
*
* @return FieldList
*/
public function getCMSFields()
{
Requirements::css('torindul-silverstripe-shop/css/LeftAndMain.css');
//Create the FieldList and push the Root TabSet on to it.
$fields = FieldList::create($root = TabSet::create('Root', Tab::create("Main", HeaderField::create("Add/Edit Currency"), CompositeField::create(DropdownField::create("Enabled", "Enable Currency?", array("1" => "Yes", "2" => "No"))->setRightTitle($this->SystemCreated == 1 ? "DISABLED: You can not disable the default currency." : "Select the country this zone applies to.")->setDisabled($this->SystemCreated == 1 ? true : false), TextField::create("Title", "Currency Name")->setRightTitle("i.e. Great British Pound."), TextField::create("Code", "Currency Code")->setRightTitle("i.e. GBP, USD, EUR."), TextField::create("ExchangeRate", "Exchange Rate")->setRightTitle("i.e. Your new currency is USD, a conversion rate of 1.53 may apply against the local currency."), TextField::create("Symbol", "Currency Symbol")->setRightTitle("i.e. £, \$, €."), DropdownField::create("SymbolLocation", "Symbol Location", array("1" => "On the left, i.e. \$1.00", "2" => "On the right, i.e. 1.00\$", "3" => "Display the currency code instead, i.e. 1 USD."))->setRightTitle("Where should the currency symbol be placed?"), TextField::create("DecimalSeperator", "Decimal Separator")->setRightTitle("What decimal separator does this currency use?"), TextField::create("ThousandsSeparator", "Thousands Separator")->setRightTitle("What thousands separator does this currency use?"), NumericField::create("DecimalPlaces", "Decimal Places")->setRightTitle("How many decimal places does this currency use?")))));
return $fields;
}
示例3: getFormFields
public function getFormFields(Order $order)
{
$member = Member::currentUser() ?: $order->Member();
if (!$member || !$member->exists() || !$member->AddressBook()->exists()) {
return parent::getFormFields($order);
}
$options = [];
$default = $this->getDefaultAddress($member);
$params = ['addfielddescriptions' => $this->formfielddescriptions];
$addressFields = $default->getFrontEndFields($params);
if ($this->allowSaveAsNew) {
$addressFields->push(CheckboxField::create('saveAsNew', _t('AlternateAddressBookCheckoutComponent.SAVE_AS_NEW', 'Save as new address')));
}
$options[] = SelectionGroup_Item::create('address-' . $default->ID, HasOneCompositeField::create('address-' . $default->ID, $default, $addressFields), _t('AlternateAddressBookCheckoutComponent.USE_DEFAULT', '{address}', ['address' => $default->Title]));
if ($member->AddressBook()->exclude('ID', $default->ID)->exists()) {
foreach ($member->AddressBook()->exclude('ID', $default->ID) as $address) {
$addressFields = $address->getFrontEndFields($params);
$addressFields->push(CheckboxField::create('saveAsNew', _t('AlternateAddressBookCheckoutComponent.SAVE_AS_NEW', 'Save as new address')));
if ($member->DefaultShippingAddressID != $address->ID) {
$addressFields->push(CheckboxField::create('useAsDefaultShipping', _t('AlternateAddressBookCheckoutComponent.USE_AS_DEFAULT_SHIPPING', 'Use as default shipping address')));
}
if ($member->DefaultBillingAddressID != $address->ID) {
$addressFields->push(CheckboxField::create('useAsDefaultBilling', _t('AlternateAddressBookCheckoutComponent.USE_AS_DEFAULT_BILLING', 'Use as default billing address')));
}
$options[] = SelectionGroup_Item::create('address-' . $address->ID, HasOneCompositeField::create('address-' . $address->ID, $address, $addressFields), _t('AlternateAddressBookCheckoutComponent.SHIP_TO_SELECTED_ADDRESS', '{address}', ['address' => $address->Title]));
}
}
if ($this->allowNew) {
$addressFields = parent::getFormFields($order);
$addressFields->push(CheckboxField::create('useAsDefaultShipping', _t('AlternateAddressBookCheckoutComponent.USE_AS_DEFAULT_SHIPPING', 'Use as default shipping address')));
$addressFields->push(CheckboxField::create('useAsDefaultBilling', _t('AlternateAddressBookCheckoutComponent.USE_AS_DEFAULT_BILLING', 'Use as default billing address')));
$options[] = SelectionGroup_Item::create('new', HasOneCompositeField::create('new', Address::create(), $addressFields), _t('AlternateAddressBookCheckoutComponent.' . $this->addresstype . '_TO_NEW_ADDRESS', 'New ' . ucfirst($this->addresstype) . ' Address'));
}
return FieldList::create(TabbedSelectionGroup::create('Use', $options)->setTitle(_t('ShippingDetails.' . $this->addresstype . '_ADDRESS', ucfirst($this->addresstype) . ' Address'))->setLabelTab(true)->showAsDropdown(true));
}
开发者ID:milkyway-multimedia,项目名称:ss-shop-checkout-extras,代码行数:35,代码来源:AlternateAddressBookCheckoutComponent.php
示例4: AddNewListboxForm
public function AddNewListboxForm()
{
$action = FormAction::create('doSave', 'Save')->setUseButtonTag('true');
if (!$this->isFrontend) {
$action->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept');
}
$model = $this->getModel();
$link = singleton($model);
$fields = $link->getCMSFields();
$title = $this->getDialogTitle() ? $this->getDialogTitle() : 'New Item';
$fields->insertBefore(HeaderField::create('AddNewHeader', $title), $fields->first()->getName());
$actions = FieldList::create($action);
$form = Form::create($this, 'AddNewListboxForm', $fields, $actions);
$fields->push(HiddenField::create('model', 'model', $model));
/*
if($link){
$form->loadDataFrom($link);
$fields->push(HiddenField::create('LinkID', 'LinkID', $link->ID));
}
// Chris Bolt, fixed this
//$this->owner->extend('updateLinkForm', $form);
$this->extend('updateLinkForm', $form);
// End Chris Bolt
*/
return $form;
}
示例5: Form
private function Form()
{
$fields = FieldList::create(TextField::create('Title'), TextField::create('Subtitle'));
$actions = FieldList::create(FormAction::create('submit', 'submit'));
$validator = ZenValidator::create();
return Form::create(Controller::curr(), 'Form', $fields, $actions, $validator);
}
示例6: getCMSFields
public function getCMSFields()
{
$fields = FieldList::create(TextField::create('Title'), HtmlEditorField::create('Description'), $uploader = UploadField::create('Photo'));
$uploader->setFolderName('region-photos');
$uploader->getValidator()->setAllowedExtensions(array('png', 'gif', 'jpeg', 'jpg'));
return $fields;
}
示例7: getCMSFields
/**
* @return FieldList
*/
public function getCMSFields()
{
Requirements::javascript(USERFORMS_DIR . '/javascript/Recipient.js');
// Determine optional field values
$form = $this->getFormParent();
// predefined choices are also candidates
$multiOptionFields = EditableMultipleOptionField::get()->filter('ParentID', $form->ID);
// if they have email fields then we could send from it
$validEmailFromFields = EditableEmailField::get()->filter('ParentID', $form->ID);
// For the subject, only one-line entry boxes make sense
$validSubjectFields = ArrayList::create(EditableTextField::get()->filter('ParentID', $form->ID)->exclude('Rows:GreaterThan', 1)->toArray());
$validSubjectFields->merge($multiOptionFields);
// To address cannot be unbound, so restrict to pre-defined lists
$validEmailToFields = $multiOptionFields;
// Build fieldlist
$fields = FieldList::create(Tabset::create('Root')->addExtraClass('EmailRecipientForm'));
// Configuration fields
$fields->addFieldsToTab('Root.EmailDetails', array(FieldGroup::create(TextField::create('EmailSubject', _t('UserDefinedForm.TYPESUBJECT', 'Type subject'))->setAttribute('style', 'min-width: 400px;'), DropdownField::create('SendEmailSubjectFieldID', _t('UserDefinedForm.SELECTAFIELDTOSETSUBJECT', '.. or select a field to use as the subject'), $validSubjectFields->map('ID', 'Title'))->setEmptyString(''))->setTitle(_t('UserDefinedForm.EMAILSUBJECT', 'Email subject')), FieldGroup::create(TextField::create('EmailAddress', _t('UserDefinedForm.TYPETO', 'Type to address'))->setAttribute('style', 'min-width: 400px;'), DropdownField::create('SendEmailToFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or select a field to use as the to address'), $validEmailToFields->map('ID', 'Title'))->setEmptyString(' '))->setTitle(_t('UserDefinedForm.SENDEMAILTO', 'Send email to'))->setDescription(_t('UserDefinedForm.SENDEMAILTO_DESCRIPTION', 'You may enter multiple email addresses as a comma separated list.')), TextField::create('EmailFrom', _t('UserDefinedForm.FROMADDRESS', 'Send email from'))->setDescription(_t('UserDefinedForm.EmailFromContent', "The from address allows you to set who the email comes from. On most servers this " . "will need to be set to an email address on the same domain name as your site. " . "For example on yoursite.com the from address may need to be something@yoursite.com. " . "You can however, set any email address you wish as the reply to address.")), FieldGroup::create(TextField::create('EmailReplyTo', _t('UserDefinedForm.TYPEREPLY', 'Type reply address'))->setAttribute('style', 'min-width: 400px;'), DropdownField::create('SendEmailFromFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or select a field to use as reply to address'), $validEmailFromFields->map('ID', 'Title'))->setEmptyString(' '))->setTitle(_t('UserDefinedForm.REPLYADDRESS', 'Email for reply to'))->setDescription(_t('UserDefinedForm.REPLYADDRESS_DESCRIPTION', 'The email address which the recipient is able to \'reply\' to.'))));
// Only show the preview link if the recipient has been saved.
if (!empty($this->EmailTemplate)) {
$preview = sprintf('<p><a href="%s" target="_blank" class="ss-ui-button">%s</a></p><em>%s</em>', "admin/pages/edit/EditForm/field/EmailRecipients/item/{$this->ID}/preview", _t('UserDefinedForm.PREVIEW_EMAIL', 'Preview email'), _t('UserDefinedForm.PREVIEW_EMAIL_DESCRIPTION', 'Note: Unsaved changes will not appear in the preview.'));
} else {
$preview = sprintf('<em>%s</em>', _t('UserDefinedForm.PREVIEW_EMAIL_UNAVAILABLE', 'You can preview this email once you have saved the Recipient.'));
}
// Email templates
$fields->addFieldsToTab('Root.EmailContent', array(CheckboxField::create('HideFormData', _t('UserDefinedForm.HIDEFORMDATA', 'Hide form data from email?')), CheckboxField::create('SendPlain', _t('UserDefinedForm.SENDPLAIN', 'Send email as plain text? (HTML will be stripped)')), DropdownField::create('EmailTemplate', _t('UserDefinedForm.EMAILTEMPLATE', 'Email template'), $this->getEmailTemplateDropdownValues())->addExtraClass('toggle-html-only'), HTMLEditorField::create('EmailBodyHtml', _t('UserDefinedForm.EMAILBODYHTML', 'Body'))->addExtraClass('toggle-html-only'), TextareaField::create('EmailBody', _t('UserDefinedForm.EMAILBODY', 'Body'))->addExtraClass('toggle-plain-only'), LiteralField::create('EmailPreview', '<div id="EmailPreview" class="field toggle-html-only">' . $preview . '</div>')));
// Custom rules for sending this field
$grid = new GridField("CustomRules", _t('EditableFormField.CUSTOMRULES', 'Custom Rules'), $this->CustomRules(), $this->getRulesConfig());
$grid->setDescription(_t('UserDefinedForm.RulesDescription', 'Emails will only be sent to the recipient if the custom rules are met. If no rules are defined, this receipient will receive notifications for every submission.'));
$fields->addFieldsToTab('Root.CustomRules', array(new DropdownField('CustomRulesCondition', _t('UserDefinedForm.SENDIF', 'Send condition'), array('Or' => 'Any conditions are true', 'And' => 'All conditions are true')), $grid));
$this->extend('updateCMSFields', $fields);
return $fields;
}
示例8: UpdateForm
public function UpdateForm()
{
$member = singleton('SecurityContext')->getMember();
if (!$member) {
return '';
}
// if there's a member profile page availble, use it
$filter = array();
if (class_exists('Multisites')) {
$filter = array('SiteID' => Multisites::inst()->getCurrentSiteId());
}
// use member profile page if possible
if (class_exists('MemberProfilePage') && ($profilePage = MemberProfilePage::get()->filter($filter)->first())) {
$controller = MemberProfilePage_Controller::create($profilePage);
$form = $controller->ProfileForm();
$form->addExtraClass('ajax-form');
$form->loadDataFrom($member);
return $form;
} else {
$password = new ConfirmedPasswordField('Password', $member->fieldLabel('Password'), null, null, (bool) $this->ID);
$password->setCanBeEmpty(true);
$fields = FieldList::create(TextField::create('FirstName', $member->fieldLabel('FirstName')), TextField::create('Surname', $member->fieldLabel('Surname')), EmailField::create('Email', $member->fieldLabel('Email')), $password);
$actions = FieldList::create($update = FormAction::create('updateprofile', 'Update'));
$form = Form::create($this, 'UpdateForm', $fields, $actions);
$form->loadDataFrom($member);
$this->extend('updateProfileDashletForm', $form);
return $form;
}
return;
}
示例9: getCMSFields
function getCMSFields()
{
$fields = FieldList::create(TabSet::create('Root'));
$fields->addFieldToTab('Root.Main', new TextField('Title'));
$fields->addFieldToTab('Root.Main', new CurrencyField('Price'));
return $fields;
}
示例10: getCMSFields
public function getCMSFields()
{
$fields = FieldList::create(TabSet::create('Root'))->text('Title')->text('Code', 'Code', '', 5)->textarea('Description')->numeric('SessionCount', 'Number of sessions')->numeric('AlternateCount', 'Number of alternates')->checkbox('VotingVisible', "This category is visible to voters")->checkbox('ChairVisible', "This category is visible to track chairs")->hidden('SummitID', 'SummitID');
if ($this->ID > 0) {
//tags
$config = new GridFieldConfig_RelationEditor(100);
$config->removeComponentsByType(new GridFieldDataColumns());
$config->removeComponentsByType(new GridFieldDetailForm());
$completer = $config->getComponentByType('GridFieldAddExistingAutocompleter');
$completer->setResultsFormat('$Tag');
$completer->setSearchFields(array('Tag'));
$completer->setSearchList(Tag::get());
$editconf = new GridFieldDetailForm();
$editconf->setFields(FieldList::create(TextField::create('Tag', 'Tag'), DropdownField::create('ManyMany[Group]', 'Group', array('topics' => 'Topics', 'speaker' => 'Speaker', 'openstack projects mentioned' => 'OpenStack Projects Mentioned'))));
$summaryfieldsconf = new GridFieldDataColumns();
$summaryfieldsconf->setDisplayFields(array('Tag' => 'Tag', 'Group' => 'Group'));
$config->addComponent($editconf);
$config->addComponent($summaryfieldsconf, new GridFieldFilterHeader());
$tags = new GridField('AllowedTags', 'Tags', $this->AllowedTags(), $config);
$fields->addFieldToTab('Root.Main', $tags);
// extra questions for call-for-presentations
$config = new GridFieldConfig_RelationEditor();
$config->removeComponentsByType('GridFieldAddNewButton');
$multi_class_selector = new GridFieldAddNewMultiClass();
$multi_class_selector->setClasses(array('TrackTextBoxQuestionTemplate' => 'TextBox', 'TrackCheckBoxQuestionTemplate' => 'CheckBox', 'TrackCheckBoxListQuestionTemplate' => 'CheckBoxList', 'TrackRadioButtonListQuestionTemplate' => 'RadioButtonList', 'TrackDropDownQuestionTemplate' => 'ComboBox', 'TrackLiteralContentQuestionTemplate' => 'Literal'));
$config->addComponent($multi_class_selector);
$questions = new GridField('ExtraQuestions', 'Track Specific Questions', $this->ExtraQuestions(), $config);
$fields->addFieldToTab('Root.Main', $questions);
}
return $fields;
}
示例11: __construct
public function __construct($controller, $name)
{
$member = Member::currentUser();
$requiredFields = null;
if ($member && $member->exists()) {
$fields = $member->getMemberFormFields();
$fields->removeByName('Password');
$requiredFields = $member->getValidator();
$requiredFields->addRequiredField('Surname');
} else {
$fields = FieldList::create();
}
if (get_class($controller) == 'AccountPage_Controller') {
$actions = FieldList::create(FormAction::create('submit', _t('MemberForm.SAVE', 'Save Changes')));
} else {
$actions = FieldList::create(FormAction::create('submit', _t('MemberForm.SAVE', 'Save Changes')), FormAction::create('proceed', _t('MemberForm.SAVEANDPROCEED', 'Save and proceed to checkout')));
}
parent::__construct($controller, $name, $fields, $actions, $requiredFields);
$this->extend('updateShopAccountForm');
if ($record = $controller->data()) {
$record->extend('updateShopAccountForm', $fields, $actions, $requiredFields);
}
if ($controller->data() && $controller->data()->hasMethod('updateShopAccountForm')) {
// if accessing through the model
Deprecation::notice('2.0', 'Please access updateShopAccountForm through ShopAccountForm instead of AccountPage (this extension point is due to be removed)');
}
if ($member) {
$member->Password = "";
//prevents password field from being populated with encrypted password data
$this->loadDataFrom($member);
}
}
示例12: createActions
public function createActions()
{
$actions = FieldList::create(new FormAction('process', _t('CheckoutPage.PROCEED_TO_PAY', "Proceed to pay")));
$this->extend('updateActions', $actions);
$actions->setForm($this);
return $actions;
}
示例13: __construct
/**
* EmailVerificationLoginForm is the same as MemberLoginForm with the following changes:
* - The code has been cleaned up.
* - A form action for users who have lost their verification email has been added.
*
* We add fields in the constructor so the form is generated when instantiated.
*
* @param Controller $controller The parent controller, necessary to create the appropriate form action tag.
* @param string $name The method on the controller that will return this form object.
* @param FieldList|FormField $fields All of the fields in the form - a {@link FieldList} of {@link FormField} objects.
* @param FieldList|FormAction $actions All of the action buttons in the form - a {@link FieldList} of {@link FormAction} objects
* @param bool $checkCurrentUser If set to TRUE, it will be checked if a the user is currently logged in, and if so, only a logout button will be rendered
*/
function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
{
$email_field_label = singleton('Member')->fieldLabel(Member::config()->unique_identifier_field);
$email_field = TextField::create('Email', $email_field_label, null, null, $this)->setAttribute('autofocus', 'autofocus');
$password_field = PasswordField::create('Password', _t('Member.PASSWORD', 'Password'));
$authentication_method_field = HiddenField::create('AuthenticationMethod', null, $this->authenticator_class, $this);
$remember_me_field = CheckboxField::create('Remember', 'Remember me next time?', true);
if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
$fields = FieldList::create($authentication_method_field);
$actions = FieldList::create(FormAction::create('logout', _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
} else {
if (!$fields) {
$fields = FieldList::create($authentication_method_field, $email_field, $password_field);
if (Security::config()->remember_username) {
$email_field->setValue(Session::get('SessionForms.MemberLoginForm.Email'));
} else {
// Some browsers won't respect this attribute unless it's added to the form
$this->setAttribute('autocomplete', 'off');
$email_field->setAttribute('autocomplete', 'off');
}
}
if (!$actions) {
$actions = FieldList::create(FormAction::create('doLogin', _t('Member.BUTTONLOGIN', "Log in")), new LiteralField('forgotPassword', '<p id="ForgotPassword"><a href="Security/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'), new LiteralField('resendEmail', '<p id="ResendEmail"><a href="Security/verify-email">' . _t('MemberEmailVerification.BUTTONLOSTVERIFICATIONEMAIL', "I've lost my verification email") . '</a></p>'));
}
}
if (isset($_REQUEST['BackURL'])) {
$fields->push(HiddenField::create('BackURL', 'BackURL', $_REQUEST['BackURL']));
}
// Reduce attack surface by enforcing POST requests
$this->setFormMethod('POST', true);
parent::__construct($controller, $name, $fields, $actions);
$this->setValidator(RequiredFields::create('Email', 'Password'));
}
开发者ID:jordanmkoncz,项目名称:silverstripe-memberemailverification,代码行数:46,代码来源:EmailVerificationLoginForm.php
示例14: __construct
/**
* @param Controller $controller
* @param String $name
* @param array $arguments
*/
public function __construct($controller, $name, $arguments = array())
{
/** -----------------------------------------
* Fields
* ----------------------------------------*/
/** @var EmailField $email */
$email = EmailField::create('Email', 'Email Address');
$email->addExtraClass('form-control')->setAttribute('data-parsley-required-message', 'Please enter your <strong>Email</strong>')->setCustomValidationMessage('Please enter your <strong>Email</strong>');
$fields = FieldList::create($email);
/** -----------------------------------------
* Actions
* ----------------------------------------*/
$actions = FieldList::create(FormAction::create('Subscribe')->setTitle('Subscribe')->addExtraClass('btn btn-primary'));
/** -----------------------------------------
* Validation
* ----------------------------------------*/
$required = RequiredFields::create('Email');
/** @var Form $form */
$form = Form::create($this, $name, $fields, $actions, $required);
if ($formData = Session::get('FormInfo.Form_' . $name . '.data')) {
$form->loadDataFrom($formData);
}
parent::__construct($controller, $name, $fields, $actions, $required);
$this->setAttribute('data-parsley-validate', true);
$this->addExtraClass('form');
}
示例15: getFormFields
/**
* Get form fields for manipulating the current order,
* according to the responsibilty of this component.
*
* @param Order $order
* @param Form $form
*
* @return FieldList
*/
public function getFormFields(Order $order, Form $form = null)
{
$gateway = $this->getGateway($order);
if (!$this->isBraintree) {
return parent::getFormFields($order);
}
// Generate the token for the javascript to use
$clientToken = $gateway->clientToken()->send()->getToken();
// Generate the standard set of fields and allow it to be customised
$fields = FieldList::create([BraintreeHostedField::create('number', _t('BraintreePaymentCheckoutComponent.CardNumber', 'Debit/Credit Card Number')), BraintreeHostedField::create('cvv', _t('BraintreePaymentCheckoutComponent.CVV', 'Security Code')), BraintreeHostedField::create('expirationDate', _t('BraintreePaymentCheckoutComponent.ExpirationDate', 'Expiration Date (MM/YYYY)'))]);
if ($this->config()->use_placeholders) {
foreach ($fields as $field) {
if ($field->Title()) {
$field->setAttribute('placeholder', $field->Title())->setTitle(null);
}
}
}
$this->extend('updateFormFields', $fields);
// Generate a basic config and allow it to be customised
$config = ['id' => $form ? $form->getHTMLID() : 'PaymentForm_OrderForm', 'hostedFields' => $this->getFieldConfig($fields)];
$this->extend('updateBraintreeConfig', $config);
$rawConfig = json_encode($config);
$rawConfig = $this->injectCallbacks($rawConfig);
$this->extend('updateRawBraintreeConfig', $rawConfig);
// Finally, add the javascript to the page
Requirements::javascript('https://js.braintreegateway.com/js/braintree-2.20.0.min.js');
Requirements::customScript("braintree.setup('{$clientToken}', 'custom', {$rawConfig});", 'BrainTreeJS');
return $fields;
}