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)); }
/** * @return array */ protected function getMethodFormFields() { $default = (string) $this->owner->config()->recommended_findBy_methods_default; $methods = $this->owner->config()->recommended_findBy_methods; $items = []; if (isset($methods[$default])) { $items[] = \SelectionGroup_Item::create($methods[$default], \Injector::inst()->get($default)->getFormFields($this->owner), _t('Product.Recommended_FindBy-' . str_replace(' ', '', $methods[$default]), \Injector::inst()->get($default)->title($this->owner))); unset($methods[$default]); } foreach ($methods as $class => $name) { $method = \Injector::inst()->get($class); $items[] = \SelectionGroup_Item::create($name, $method->getFormFields($this->owner), _t('Product.Recommended_FindBy-' . str_replace(' ', '', $name), $method->title($this->owner))); } return $items; }
public function getCMSFields() { $this->beforeExtending('updateCMSFields', function ($fields) { $fields->removeByName('Automated'); $fields->removeByName('AuthorID'); $fields->removeByName('OrderID'); $fields->removeByName('Changes'); $fields->removeByName('FirstRead'); // Disables the default firing of sent to customer flag $fields->removeByName('SentToCustomer'); // Status Field $allSuggestedStatuses = (array) $this->config()->status_list; $statusesWithIcons = $otherStatuses = []; // Check if readonly $editable = $this->canEdit(); $simplified = !Permission::check('ADMIN') && $this->Automated && !in_array($this->Status, static::$DETAILED_STATUS); $dataFields = $fields->dataFields(); if ($editable) { $fields->removeByName('Status'); foreach ($allSuggestedStatuses as $status => $options) { if (is_array($options) && !empty($options['icon'])) { $statusesWithIcons[$status] = isset($options['title']) ? $options['icon'] . ' ' . $options['title'] : $options['icon'] . ' ' . $status; } else { if (is_array($options) && !empty($options['title'])) { $otherStatuses[$status] = $options['title']; } else { $otherStatuses[$status] = $options; } } } $otherStatuses = array_merge($otherStatuses, $this->get()->exclude('Status', array_merge(array_keys($allSuggestedStatuses)))->sort('Status', 'ASC')->map('Status', 'Status')->toArray()); $statuses = ['Common Statuses' => $statusesWithIcons]; if (!empty($otherStatuses)) { asort($otherStatuses); $statuses['Other Status'] = $otherStatuses; foreach ($statuses['Other Status'] as $status => $title) { $statuses['Other Status'][$status] = FormField::name_to_label($title); } } $fields->insertBefore($statusField = Select2Field::create('Status', 'Status', '', $statuses)->setMinimumSearchLength(0)->setEmptyString('You can select from suggested statuses, or create a new status')->setAttribute('data-format-searching', _t('OrderLog.SEARCHING-Status', 'Loading statuses...')), 'Title'); $statusField->requireSelection = false; if (!Permission::check('ADMIN')) { $statusField->disabledOptions = $this->config()->disallowed_multiple_statuses; } if ($this->exists() && !Permission::check('ADMIN') && ($this->Automated || $this->AuthorID != Member::currentUserID())) { $statusField->setAttribute('disabled', 'disabled'); } elseif ($editable) { $statusField->setDescription(_t('OrderLog.DESC-Status', 'Note: {updated} is a special status. If there are more than {limit} logs for an order, it will automatically delete statuses classed as {updated}, so use with caution.', ['updated' => implode(', ', (array) static::$GENERIC_STATUS), 'limit' => $this->config()->max_records_per_order])); } $statusField->allowHTML = true; $statusField->prefetch = true; } elseif (isset($dataFields['Status'])) { $fields->removeByName('Status'); $fields->insertBefore('Title', $dataFields['Status']); } if (isset($dataFields['Title']) && $editable) { $dataFields['Title']->setDescription(_t('OrderLog.DESC-Title', 'If not set, will automatically use the Status above')); } elseif (!$editable && $this->Title == $this->Status) { $fields->removeByName('Title'); } $lastField = 'Title'; if (!$editable && !$this->Note) { $fields->removeByName('Note'); } elseif ($editable && isset($dataFields['Note']) && $dataFields['Note'] instanceof TextareaField) { $dataFields['Note']->setRows(2); $lastField = 'Note'; } else { $lastField = 'Note'; } $fieldSet = []; foreach (['Public', 'Unread'] as $field) { if (isset($dataFields[$field])) { $fieldSet[$field] = $dataFields[$field]; $fields->removeByName($field); } } if (!empty($fieldSet)) { if (isset($fieldSet['Public'])) { $fieldSet['Public']->setTitle($fieldSet['Public']->Title() . ' (' . _t('OrderLog.DESC-Public', 'If checked, user can view this log on the front-end when checking the status of their orders') . ')'); } if ($this->FirstRead) { $fieldSet['FirstRead'] = DatetimeField::create('FirstRead'); } $fields->insertAfter(FieldGroup::create($fieldSet)->setTitle('Public Visibility')->setName('PublicFields')->addExtraClass('hero-unit stacked-items'), $lastField); $fieldSet = []; $lastField = 'PublicFields'; } foreach (['DispatchTicket', 'DispatchedBy', 'DispatchedOn'] as $field) { if (($simplified || !$editable) && !$this->{$field}) { $fields->removeByName($field); continue; } if (isset($dataFields[$field])) { $fieldSet[$field] = $dataFields[$field]; $fields->removeByName($field); if ($fieldSet[$field] instanceof DateField) { $fieldSet[$field]->setConfig('showcalendar', true); } if ($field == 'DispatchTicket') { $fieldSet[$field]->setTitle(_t('OrderLog.TRACKING_ID', 'Tracking ID')); } elseif ($field == 'DispatchedBy') { $fieldSet[$field]->setTitle(_t('OrderLog.VIA', 'via')); } elseif ($field == 'DispatchedOn') { $fieldSet[$field]->setTitle(_t('OrderLog.ON', 'on')); } } } if (!empty($fieldSet)) { $fields->removeByName('DispatchUri'); $fields->insertAfter($dispatched = CompositeField::create(FieldGroup::create($fieldSet)->setTitle('Dispatched')->setName('DispatchedDetails'))->setName('Dispatched')->addExtraClass('hero-unit'), $lastField); if ($editable || $this->DispatchUri) { $dispatched->push(TextField::create('DispatchUri', _t('OrderLog.DispatchUri', 'Tracking URL'))->setDescription(_t('OrderLog.DESC-DispatchUri', 'If none provided, will attempt to use the URL of the carrier'))); } $fieldSet = []; $lastField = 'Dispatched'; } elseif (($simplified || !$editable) && !$this->DispatchUri) { $fields->removeByName('DispatchUri'); } foreach (['PaymentCode', 'PaymentOK'] as $field) { if (($simplified || !$editable) && !$this->{$field}) { $fields->removeByName($field); continue; } if (isset($dataFields[$field])) { $fieldSet[$field] = $dataFields[$field]; $fields->removeByName($field); if ($field == 'PaymentCode') { $fieldSet[$field]->setTitle(_t('OrderLog.CODE', 'Code')); } } } if (!empty($fieldSet)) { $fields->insertAfter(FieldGroup::create($fieldSet)->setTitle('Payment')->setName('Payment')->addExtraClass('hero-unit'), $lastField); $fieldSet = []; } // Email Fields $fields->removeByName('Send_To'); $fields->removeByName('Send_Subject'); $fields->removeByName('Send_Body'); $fields->removeByName('Send_From'); $fields->removeByName('Send_HideOrder'); $fields->removeByName('Send'); $fields->removeByName('Sent'); if (($simplified || !$editable) && !$this->Sent) { return; } $fields->addFieldsToTab('Root', [Tab::create('Email', _t('OrderLog.EMAIL', 'Email'))]); $emailFields = ['Send_To' => TextField::create('Send_To', _t('OrderLog.Send_To', 'Send to')), 'Send_From' => TextField::create('Send_From', _t('OrderLog.Send_From', 'From')), 'Send_Subject' => TextField::create('Send_Subject', _t('OrderLog.Send_Subject', 'Subject'))->setAttribute('placeholder', _t('Order.RECEIPT_SUBJECT', 'Web Order - {reference}', ['reference' => $this->Order()->Reference])), 'Send_HideOrder' => CheckboxField::create('Send_HideOrder', _t('OrderLog.Send_HideOrder', 'Hide order from email')), 'Send_Body' => HTMLEditorField::create('Send_Body', _t('OrderLog.Send_Body', 'Body'))->setRows(2)->addExtraClass('limited limited-with-source limited-with-links')->setDescription(_t('OrderLog.DESC-Send_Body', 'If no body is provided, will use the log notes (as seen below)')), 'EmailPreview' => DataObjectPreviewField::create(get_class($this) . '_EmailPreview', new Preview($this), new DataObjectPreviewer(new Preview($this)))]; if ($this->Sent || !$editable) { $readOnlyEmailFields = []; unset($emailFields['Send_HideOrder']); foreach ($emailFields as $emailField) { if ($emailField->Name != 'Send_Body' && !$emailField instanceof DataObjectPreviewField) { $readOnlyEmailFields[] = $emailField->performReadonlyTransformation(); } elseif ($emailField instanceof DataObjectPreviewField) { $readOnlyEmailFields[] = $emailField; } } unset($emailFields); $fields->addFieldsToTab('Root.Email', array_merge([ReadonlyField::create('READONLY_Sent', _t('OrderLog.Sent', 'Sent'), $this->obj('Sent')->Nice())], $readOnlyEmailFields)); } else { $fields->addFieldsToTab('Root.Email', [$selectionGroup = TabbedSelectionGroup::create('Send', [SelectionGroup_Item::create(0, CompositeField::create(), _t('OrderLog.Send-NO', 'No')), SelectionGroup_Item::create(1, CompositeField::create($emailFields), _t('OrderLog.Send-YES', 'Yes'))])->addExtraClass('selectionGroup--minor')->showAsDropdown(true)->setTitle(_t('OrderLog.Send', 'Send as an email?'))]); } }); return parent::getCMSFields(); }
/** * Display Logic Form Fields does not place nice for GridFields, so I have made it use SelectionGroup instead * @param \FieldList $fields */ protected function updateFields(\FieldList $fields) { $this->clearFieldList($fields); $types = [\SelectionGroup_Item::create('', \CompositeField::create(), _t('Linkable.TYPENONE', 'None'))->setName('Type_None')]; foreach ((array) $this->owner->config()->types as $type => $label) { $types[$type] = \SelectionGroup_Item::create($type, $this->getFormFieldsForType($type), _t('Linkable.TYPE' . strtoupper($type), $label))->setName('Type_' . $type); } $type = \ClassInfo::exists('TabbedSelectionGroup') ? 'TabbedSelectionGroup' : 'SelectionGroup'; if ($fields->fieldByName('Root')) { $fields->addFieldsToTab('Root.Main', $typeField = \Object::create($type, 'Type', $types)); } else { $fields->push($typeField = \Object::create($type, 'Type', $types)); } if ($type == 'TabbedSelectionGroup') { $typeField->showAsDropdown(true)->setLabelTab(_t('Link.LINK_TO', 'Link to:')); } }
public function getCMSFields() { Requirements::css('silverstripe-video-embed/assests/css/VideoEmbedEditor.css'); Requirements::javascript('silverstripe-video-embed/assests/javascript/urlParser.min.js'); Requirements::javascript(THIRDPARTY_DIR . '/json-js/json2.js'); Requirements::javascript('silverstripe-video-embed/assests/javascript/VideoEmbedEditor.js'); $Fields = parent::getCMSFields(); $Fields->removeByName('Type'); $Fields->removeByName('Code'); $Fields->removeByName('HTML5Video'); $Fields->removeByName('ThumbnailURL'); $Fields->removeByName('ThumbnailFile'); $types = $this->GetVideoTypes(); $typeSelection = array(); foreach ($types as $type) { if (isset($type["label"])) { $typeSelection[$type["label"]] = $type["label"]; } } $Fields->addFieldToTab('Root.Main', new DropdownField("Type", "Type", $typeSelection)); $CodeField = new TextField("Code", "Code"); $CodeField->setDescription(' Copy and paste your Video URL here<br/> eg</br> https://www.youtube.com/watch?v=cRi5Hh7RU34</br> http://vimeo.com/93104916</br> http://www.dailymotion.com/video/x1no7nq_jquery-and-ajax-tutorials-45-ajax-login-example_tech</br> '); $Fields->addFieldToTab('Root.Main', $CodeField); $TitleField = new TextField("Title", "Title"); $Fields->addFieldToTab('Root.Main', $TitleField); $HTML5VideoField = new UploadField('HTML5Video', 'Video file'); //::create("HTML5Video")->setTitle("Album Cover Photo"); $HTML5VideoField->getValidator()->allowedExtensions = array("webm", "ogg", "mp4", "flv"); $HTML5VideoField->setAllowedMaxFileNumber(1); $Fields->addFieldToTab('Root.Main', $HTML5VideoField); $ThumbnailUploadField = new UploadField('ThumbnailFile', ''); $ThumbnailUploadField->getValidator()->allowedExtensions = array('jpg', 'jpeg', 'gif', 'png'); $ThumbnailUploadField->setAllowedMaxFileNumber(1); $thumbnailField = new SelectionGroup('ThumbnailGroup', array(SelectionGroup_Item::create('URL', array(LiteralField::create('ThumbPreview', ' <div class="ss-uploadfield "> <div class="ss-uploadfield-item ss-uploadfield-addfile middleColumn"> <div class="ss-uploadfield-item-preview ss-uploadfield-dropzone ui-corner-all" style="display: block; margin: 0" id="ThumbnailURLHolder"> Enter a URL </div> <img src="" alt="Failed to load preview" style="display:none; width: 60px;" id="ThumbnailURLPreview"/> '), TextField::create('ThumbnailURL', ''), LiteralField::create('ThumbPreview', ' </div> </div>'))), SelectionGroup_Item::create('File', $ThumbnailUploadField))); $thumbnailField->setValue("URL"); if ($this->ThumbnailURL) { $thumbnailField->setValue("URL"); } else { if ($this->ThumbnailFile()->exists()) { $thumbnailField->setValue("File"); } } $fields[] = LiteralField::create("guestLabel", '<div id="Thumbnail" class="field text"> <label class="left" for="Form_ItemEditForm_Value">Thumbnail</label> <div class="middleColumn">'); $fields[] = $thumbnailField; $fields[] = LiteralField::create("guestLabel", ' <input type="text" name="Value" class="text" id="Form_ItemEditForm_Value"> </div> </div>'); $fields[] = new HiddenField("VideoTypesHolder", "VideoTypesHolder", Convert::raw2json($types)); $Fields->addFieldsToTab('Root.Main', $fields); return $Fields; }