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)); }
/** * Construct fields to select any commit * * @param DNProject $project * @param DataList|null $pipelineCommits Optional list of pipeline-filtered commits to include * @return FormField */ protected function buildCommitSelector($project, $pipelineCommits = null) { // Branches $branches = array(); foreach ($project->DNBranchList() as $branch) { $sha = $branch->SHA(); $name = $branch->Name(); $branchValue = sprintf("%s (%s, %s old)", $name, substr($sha, 0, 8), $branch->LastUpdated()->TimeDiff()); $branches[$sha . '-' . $name] = $branchValue; } // Tags $tags = array(); foreach ($project->DNTagList()->setLimit(null) as $tag) { $sha = $tag->SHA(); $name = $tag->Name(); $tagValue = sprintf("%s (%s, %s old)", $name, substr($sha, 0, 8), $branch->LastUpdated()->TimeDiff()); $tags[$sha . '-' . $tag] = $tagValue; } $tags = array_reverse($tags); // Past deployments $redeploy = array(); foreach ($project->DNEnvironmentList() as $dnEnvironment) { $envName = $dnEnvironment->Name; foreach ($dnEnvironment->DeployHistory() as $deploy) { $sha = $deploy->SHA; if (!isset($redeploy[$envName])) { $redeploy[$envName] = array(); } if (!isset($redeploy[$envName][$sha])) { $pastValue = sprintf("%s (deployed %s)", substr($sha, 0, 8), $deploy->obj('LastEdited')->Ago()); $redeploy[$envName][$sha] = $pastValue; } } } // Merge fields $releaseMethods = array(); if ($pipelineCommits) { $releaseMethods[] = new SelectionGroup_Item('FilteredCommits', $this->buildPipelineField($pipelineCommits), 'Deploy a commit prepared for this pipeline'); } if (!empty($branches)) { $releaseMethods[] = new SelectionGroup_Item('Branch', new DropdownField('Branch', 'Select a branch', $branches), 'Deploy the latest version of a branch'); } if ($tags) { $releaseMethods[] = new SelectionGroup_Item('Tag', new DropdownField('Tag', 'Select a tag', $tags), 'Deploy a tagged release'); } if ($redeploy) { $releaseMethods[] = new SelectionGroup_Item('Redeploy', new GroupedDropdownField('Redeploy', 'Redeploy', $redeploy), 'Redeploy a release that was previously deployed (to any environment)'); } $releaseMethods[] = new SelectionGroup_Item('SHA', new Textfield('SHA', 'Please specify the full SHA'), 'Deploy a specific SHA'); $field = new TabbedSelectionGroup('SelectRelease', $releaseMethods); $field->setValue(reset($releaseMethods)->getValue()); return $field; }
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(); }