/**
  * Get the CMS view of the instance. This is used to display the log of
  * this workflow, and options to reassign if the workflow hasn't been
  * finished yet
  *
  * @return \FieldList
  */
 public function getCMSFields()
 {
     $fields = new FieldList();
     if (Permission::check('REASSIGN_ACTIVE_WORKFLOWS')) {
         if ($this->WorkflowStatus == 'Paused' || $this->WorkflowStatus == 'Active') {
             $cmsUsers = Member::mapInCMSGroups();
             $fields->push(new HiddenField('DirectUpdate', '', 1));
             $fields->push(new HeaderField('InstanceReassignHeader', _t('WorkflowInstance.REASSIGN_HEADER', 'Reassign workflow')));
             $fields->push(new CheckboxSetField('Users', _t('WorkflowDefinition.USERS', 'Users'), $cmsUsers));
             $fields->push(new TreeMultiselectField('Groups', _t('WorkflowDefinition.GROUPS', 'Groups'), 'Group'));
         }
     }
     if ($this->canEdit()) {
         $action = $this->CurrentAction();
         if ($action->exists()) {
             $actionFields = $this->getWorkflowFields();
             $fields->merge($actionFields);
             $transitions = $action->getValidTransitions();
             if ($transitions) {
                 $fields->replaceField('TransitionID', DropdownField::create("TransitionID", "Next action", $transitions->map()));
             }
         }
     }
     $items = WorkflowActionInstance::get()->filter(array('Finished' => 1, 'WorkflowID' => $this->ID));
     $grid = new GridField('Actions', _t('WorkflowInstance.ActionLogTitle', 'Log'), $items);
     $fields->push($grid);
     return $fields;
 }
 public function __construct($controller, $name = "VariationForm")
 {
     parent::__construct($controller, $name);
     $product = $controller->data();
     $farray = array();
     $requiredfields = array();
     $attributes = $product->VariationAttributeTypes();
     foreach ($attributes as $attribute) {
         $farray[] = $attribute->getDropDownField("Choose {$attribute->Label} ...", $product->possibleValuesForAttributeType($attribute));
         $requiredfields[] = "ProductAttributes[{$attribute->ID}]";
     }
     $fields = new FieldList($farray);
     if (self::$include_json) {
         $vararray = array();
         if ($vars = $product->Variations()) {
             foreach ($vars as $var) {
                 $vararray[$var->ID] = $var->AttributeValues()->map('ID', 'ID');
             }
         }
         $fields->push(new HiddenField('VariationOptions', 'VariationOptions', json_encode($vararray)));
     }
     $fields->merge($this->Fields());
     $this->setFields($fields);
     $requiredfields[] = 'Quantity';
     $this->setValidator(new VariationFormValidator($requiredfields));
     $this->extend('updateVariationForm');
 }
 public function getFields()
 {
     $fields = new FieldList();
     foreach ($this->fieldgroups as $group) {
         if (method_exists($this, "get" . $group . "Fields")) {
             $fields->merge($this->{"get" . $group . "Fields"}());
         }
     }
     return $fields;
 }
Example #4
0
 /**
  * Get combined form fields
  * @return FieldList namespaced fields
  */
 public function getFormFields()
 {
     $fields = new FieldList();
     foreach ($this->getComponents() as $component) {
         if ($cfields = $component->getFormFields($this->order)) {
             $fields->merge($cfields);
         } else {
             user_error("getFields on  " . get_class($component) . " must return a FieldList");
         }
     }
     return $fields;
 }
 public static function factory($controller, CheckfrontAPIPackageResponse $packageResponse, array $info, array $data)
 {
     list($packageID, $startDate, $endDate, $linkType, $userType, $paymentType) = $info;
     // now build the form
     $fields = new FieldList();
     // add a hidden accessKey field if set
     $accessKey = isset($data[CheckfrontForm::AccessKeyFieldName]) ? $data[CheckfrontForm::AccessKeyFieldName] : null;
     $fields->push(new HiddenField(CheckfrontForm::AccessKeyFieldName, '', $accessKey));
     if ($userType === CheckfrontModule::UserTypeOrganiser) {
         // if organiser then add hidden start and end date fields for the actual booking
         $fields->merge(array(new HiddenField(CheckfrontForm::StartDateFieldName, '', $startDate), new HiddenField(CheckfrontForm::EndDateFieldName, '', $endDate)));
     } else {
         // if not organiser then let user specify their start and end dates
         $fields->merge(array(CheckfrontForm::make_date_field(CheckfrontForm::StartDateFieldName, 'Start Date', $startDate, $startDate, $endDate), CheckfrontForm::make_date_field(CheckfrontForm::EndDateFieldName, 'End Date', $endDate, $startDate, $endDate)));
     }
     // add the package items to the field list which will make the form as fields
     /** @var CheckfrontModel $item */
     foreach ($packageResponse->getPackageItems() as $item) {
         if ($controller->shouldShowItem($item, $userType, $linkType)) {
             $fields->merge($item->fieldsForForm('form'));
         }
     }
     $fields->merge(new FieldList(array(new HiddenField(CheckfrontAccessKeyForm::AccessKeyFieldName, '', $accessKey))));
     $actions = new FieldList();
     $required = array();
     // add the standard 'booking' fields (name etc)
     if ($response = CheckfrontModule::api()->fetchBookingForm()) {
         if ($response->isValid()) {
             // now add the booking fields to the fieldlist for the form
             $bookingFields = $response->getFormFields($required);
             $fields->merge($bookingFields);
         }
         $actions->push(new FormAction(static::SubmitButtonName, _t(__CLASS__ . ".SubmitButtonText")));
     }
     $validator = new RequiredFields($required);
     $form = new CheckfrontPackageBookingForm($controller, static::FormName, $fields, $actions, $validator);
     return $form;
 }
Example #6
0
    /**
     * Create the mailchimp subscription 
     * 
     * @param Controller $controller
     * @param string $name
     */
    public function __construct($controller, $name, $extendedFields = null, $listCode = null)
    {
        $fields = new FieldList(TextField::create('Name', 'Name')->setAttribute('required', 'required')->setAttribute('placeholder', 'Enter your name'), EmailField::create('Email', 'Email')->setAttribute('required', 'required')->setAttribute('placeholder', 'Enter your email address'));
        if ($extendedFields) {
            $fields->merge($extendedFields);
        }
        $this->extend('updateFields', $fields);
        $formAction = FormAction::create('subscribe')->setTitle('Subscribe');
        $formAction->useButtonTag = true;
        $actions = new FieldList($formAction);
        $validator = new RequiredFields('Email');
        parent::__construct($controller, $name, $fields, $actions, $validator);
        Requirements::css('mailchimp/css/mailchimp.css');
        Requirements::javascript('mailchimp/javascript/jquery.mailchimp.js');
        Requirements::customScript(<<<JS
\t\t\t(function(\$) {
\t\t\t    \$(document).ready(function(){
\t\t\t        \$('form#newsletter').mailchimp();
\t\t\t    });
\t\t\t})(jQuery);\t\t\t
JS
);
    }
 /**
  *
  * @param Controller
  * @param String
  */
 function __construct(Controller $controller, $name)
 {
     //set basics
     $requiredFields = array();
     //requirements
     Requirements::javascript('ecommerce/javascript/EcomOrderFormAddress.js');
     // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         Requirements::javascript('ecommerce/javascript/EcomOrderFormShipping.js');
         // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     }
     //  ________________ 1) Order + Member + Address fields
     //find member
     $this->order = ShoppingCart::current_order();
     $this->orderMember = $this->order->CreateOrReturnExistingMember(false);
     $this->loggedInMember = Member::currentUser();
     //strange security situation...
     if ($this->orderMember->exists() && $this->loggedInMember) {
         if ($this->orderMember->ID != $this->loggedInMember->ID) {
             if (!$this->loggedInMember->IsShopAdmin()) {
                 $this->loggedInMember->logOut();
             }
         }
     }
     $addressFieldsBilling = new FieldList();
     //member fields
     if ($this->orderMember) {
         $memberFields = $this->orderMember->getEcommerceFields();
         $requiredFields = array_merge($requiredFields, $this->orderMember->getEcommerceRequiredFields());
         $addressFieldsBilling->merge($memberFields);
     }
     //billing address field
     $billingAddress = $this->order->CreateOrReturnExistingAddress("BillingAddress");
     $billingAddressFields = $billingAddress->getFields($this->orderMember);
     $requiredFields = array_merge($requiredFields, $billingAddress->getRequiredFields());
     $addressFieldsBilling->merge($billingAddressFields);
     //shipping address field
     $addressFieldsShipping = null;
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         $addressFieldsShipping = new FieldList();
         //add the important CHECKBOX
         $useShippingAddressField = new FieldList(new CheckboxField("UseShippingAddress", _t("OrderForm.USESHIPPINGADDRESS", "Use an alternative shipping address")));
         $addressFieldsShipping->merge($useShippingAddressField);
         //now we can add the shipping fields
         $shippingAddress = $this->order->CreateOrReturnExistingAddress("ShippingAddress");
         $shippingAddressFields = $shippingAddress->getFields($this->orderMember);
         //we have left this out for now as it was giving a lot of grief...
         //$requiredFields = array_merge($requiredFields, $shippingAddress->getRequiredFields());
         //finalise left fields
         $addressFieldsShipping->merge($shippingAddressFields);
     }
     $leftFields = new CompositeField($addressFieldsBilling);
     $leftFields->addExtraClass('leftOrderBilling');
     $allLeftFields = new CompositeField($leftFields);
     $allLeftFields->addExtraClass('leftOrder');
     if ($addressFieldsShipping) {
         $leftFieldsShipping = new CompositeField($addressFieldsShipping);
         $leftFieldsShipping->addExtraClass('leftOrderShipping');
         $allLeftFields->push($leftFieldsShipping);
     }
     //  ________________  2) Log in / vs Create Account fields - RIGHT-HAND-SIDE fields
     $rightFields = new CompositeField();
     $rightFields->addExtraClass('rightOrder');
     //to do: simplify
     if (EcommerceConfig::get("EcommerceRole", "allow_customers_to_setup_accounts")) {
         if ($this->orderDoesNotHaveFullyOperationalMember()) {
             //general header
             if (!$this->loggedInMember) {
                 $rightFields->push(new LiteralField('MemberInfo', '<p class="message good">' . _t('OrderForm.MEMBERINFO', 'If you already have an account then please') . " <a href=\"Security/login/?BackURL=/" . urlencode(implode("/", $controller->getURLParams())) . "\">" . _t('OrderForm.LOGIN', 'log in') . '</a>.</p>'));
             }
         } else {
             if ($this->loggedInMember) {
                 $rightFields->push(new LiteralField('LoginNote', "<p class=\"message good\">" . _t("Account.LOGGEDIN", "You are logged in as ") . Convert::raw2xml($this->loggedInMember->FirstName) . ' ' . Convert::raw2xml($this->loggedInMember->Surname) . ' (' . Convert::raw2xml($this->loggedInMember->Email) . ').' . ' <a href="/Security/logout/">' . _t("Account.LOGOUTNOW", "Log out?") . '</a>' . '</p>'));
             }
         }
         if ($this->orderMember->exists()) {
             if ($this->loggedInMember) {
                 if ($this->loggedInMember->ID != $this->orderMember->ID) {
                     $rightFields->push(new LiteralField('OrderAddedTo', "<p class=\"message good\">" . _t("Account.ORDERADDEDTO", "Order will be added to ") . Convert::raw2xml($this->orderMember->FirstName) . ' ' . Convert::raw2xml($this->orderMember->Surname) . ' (' . Convert::raw2xml($this->orderMember->Email) . ').</p>'));
                 }
             }
         }
     }
     //  ________________  5) Put all the fields in one FieldList
     $fields = new FieldList($rightFields, $allLeftFields);
     //  ________________  6) Actions and required fields creation + Final Form construction
     $nextButton = new FormAction('saveAddress', _t('OrderForm.NEXT', 'Next'));
     $nextButton->addExtraClass("next");
     $actions = new FieldList($nextButton);
     $validator = OrderFormAddress_Validator::create($requiredFields);
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $this->setAttribute("autocomplete", "off");
     //extensions need to be set after __construct
     //extension point
     $this->extend('updateFields', $fields);
     $this->setFields($fields);
     $this->extend('updateActions', $actions);
     $this->setActions($actions);
     $this->extend('updateValidator', $validator);
     $this->setValidator($validator);
     //this needs to come after the extension calls
     foreach ($validator->getRequired() as $requiredField) {
         $field = $fields->dataFieldByName($requiredField);
         if ($field) {
             $field->addExtraClass("required");
         }
     }
     //  ________________  7)  Load saved data
     //we do this first so that Billing and Shipping Address can override this...
     if ($this->orderMember) {
         $this->loadDataFrom($this->orderMember);
     }
     if ($this->order) {
         $this->loadDataFrom($this->order);
         if ($billingAddress) {
             $this->loadDataFrom($billingAddress);
         }
         if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
             if ($shippingAddress) {
                 $this->loadDataFrom($shippingAddress);
             }
         }
     }
     //allow updating via decoration
     $oldData = Session::get("FormInfo.{$this->FormName()}.data");
     if ($oldData && (is_array($oldData) || is_object($oldData))) {
         $this->loadDataFrom($oldData);
     }
     $this->extend('updateOrderFormAddress', $this);
 }
 function Form()
 {
     if (isset($_REQUEST["BackURL"])) {
         Session::set('BackURL', $_REQUEST["BackURL"]);
     }
     $member = Member::currentUser();
     $fields = new FieldList();
     $passwordField = null;
     if ($member) {
         $name = $member->getName();
         //if($member && $member->Password != '') {$passwordField->setCanBeEmpty(true);}
         $action = new FormAction("submit", "Update your details");
         $action->addExtraClass("updateButton");
         $actions = new FieldList($action);
     } else {
         $passwordField = new ConfirmedPasswordField("Password", "Password");
         $action = new FormAction("submit", "Register");
         $action->addExtraClass("registerButton");
         $actions = new FieldList($action);
         $member = new Member();
     }
     $memberFormFields = $member->getMemberFormFields();
     if ($memberFormFields) {
         if (is_array(self::$fields_to_remove) && count(self::$fields_to_remove)) {
             foreach (self::$fields_to_remove as $fieldName) {
                 $memberFormFields->removeByName($fieldName);
             }
         }
         $fields->merge($memberFormFields);
     }
     if ($passwordField) {
         $fields->push($passwordField);
     }
     foreach (self::$required_fields as $fieldName) {
         $fields->fieldByName($fieldName)->addExtraClass("RequiredField");
     }
     $requiredFields = new RequiredFields(self::$required_fields);
     $form = new Form($this, "Form", $fields, $actions, $requiredFields);
     // Load any data avaliable into the form.
     if ($member) {
         $member->Password = null;
         $form->loadDataFrom($member);
     }
     $data = Session::get("FormInfo.Form_Form.data");
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     if (!isset($_REQUEST["Password"])) {
         $form->fields()->fieldByName("Password")->SetValue("");
     }
     return $form;
 }
 public function updateFrontEndFields(FieldList $fields)
 {
     if (!$fields->dataFieldByName("Address")) {
         $fields->merge($this->getAddressFields());
     }
 }
 /**
  * Primary method for generating the form fields used.
  * Includes an extension to allow custom extensions.
  *
  * @return FieldList
  */
 protected function getPaymentFields()
 {
     $fields = new FieldList();
     $fields->merge($this->getCreditCardFields());
     // Allow easy customisatin of the payment fields
     $this->extend('updatePaymentFields', $fields);
     return $fields;
 }
 public function StartForm()
 {
     $databaseTemplates = $this->getDatabaseTemplates();
     $fields = new FieldList(new CheckboxField('createDatabase', 'Create temporary database?', 1));
     if ($databaseTemplates) {
         $fields->push($dropdown = new DropdownField('importDatabasePath', false));
         $dropdown->setSource($databaseTemplates)->setEmptyString('Empty database');
     }
     $fields->push(new CheckboxField('requireDefaultRecords', 'Create default data?'));
     if (Director::isDev()) {
         $fields->push(CheckboxField::create('globalTestSession', 'Use global test session?')->setDescription('Caution: Will apply to all users across browsers'));
     }
     $fields->merge($this->getBaseFields());
     $form = new Form($this, 'StartForm', $fields, new FieldList(new FormAction('start', 'Start Session')));
     $this->extend('updateStartForm', $form);
     return $form;
 }
Example #12
0
 public function updateEditForm(FieldList $fields)
 {
     $fields->removeByName('StreakConfig');
     $fields->merge($this->getConfigFields());
 }