public function getFormFields(Order $order) { if (Member::currentUser() || $order->Member()->exists()) { return FieldList::create(); } $content = $this->content ?: _t('LoginCheckoutComponent.ALREADY_HAVE_AN_ACCOUNT?', 'Already have an account? <a class="checkout--login-link" href="{{ link }}">Sign in here</a>'); $link = $this->link ?: singleton('Security')->Link('login'); return FieldList::create(FormMessageField::create('LoginMessage', str_replace('{{ link }}', $link, $content), $this->type)); }
public function allowLinkToActAsMenu($fields, $form = null, $relation = 'MenuLinks', $parent = null, $controller = null, $item = null) { if (!$this->owner->config()->always_use_selection_group) { $this->updateFields($fields); } if (!$item) { $item = $this->owner; } $fields->removeByName($relation); if (!($typeField = $fields->fieldByName('Root.Main.Type')) || !$typeField instanceof \TabbedSelectionGroup) { $fields->addFieldsToTab('Root.Main', [$fieldsForForm[] = \HeaderField::create('HEADING-LINK_TO', _t('Link.LINK_TO', 'Link to:'), 3), $fieldsForForm[] = \FormMessageField::create('MSG-LINK_TO', _t('Link.MSG-LINK_TO', 'When as user clicks on this link in the menu, where does it go?'), 'info')->cms()], 'Type'); } if ($item->exists()) { $fieldsForForm[] = $links = \GridField::create($relation, _t('Link.LINKS', 'Links'), $item->{$relation}(), $config = \GridFieldConfig_RecordEditor::create()->addComponent(new \GridFieldDeleteAction(true), 'GridFieldDeleteAction')->addComponent(new \GridFieldTitleHeader())->removeComponentsByType('GridFieldFilterHeader')->removeComponentsByType('GridFieldSortableHeader')->removeComponentsByType('GridFieldPageCount')->removeComponentsByType('GridFieldPaginator')->removeComponentsByType('GridFieldDataColumns')->removeComponentsByType('GridFieldAddNewButton')->addComponent($ec = new \GridFieldEditableColumns(), 'GridFieldEditButton')->addComponent(new \Milkyway\SS\GridFieldUtils\EditableRow(), 'GridFieldEditableColumns')->addComponents(new \GridFieldOrderableRows(), new \GridFieldAddExistingSearchButton('buttons-before-right'), new MinorActionsHolder(), $addNewExtended = new AddNewInlineExtended('actions-buttons-before-left'))); $addNewExtended->openToggleByDefault = true; $model = singleton($item->{$relation}()->dataClass()); $ec->setDisplayFields($model->EditableColumnsForMenuLinks($links)); foreach ($model->hasOne() as $hasOneName => $hasOneClass) { $config->addComponent((new AddExistingPicker('actions-buttons-before-left'))->setTitle(_t('LinkableMenus.LINK_TO_HAS_ONE', 'Link to a {item}', ['item' => singleton($hasOneClass)->i18n_singular_name()]))->setSearchList(DataList::create($hasOneClass))->setUrlSegment('add-a-' . strtolower($hasOneName))->setAddHandler(function ($request, $grid, $button, $acquireItems) use($model, $hasOneClass, $hasOneName) { $items = $acquireItems($request); if (!$items) { return; } foreach ($items as $item) { $link = $model->create(); $link->Type = $hasOneName; $link->{$hasOneName . 'ID'} = $item->ID; $link->write(); $grid->getList()->add($link); } })->setUndoHandler(function ($request, $grid, $button, $acquireItems) use($model, $hasOneName) { $items = $acquireItems($request); if (!$items) { return; } foreach ($items as $item) { if ($link = $grid->getList()->sort('Created DESC')->filter($hasOneName . 'ID', $item->ID)->first()) { $link->delete(); } } })); } if ($item && ($item instanceof \LinkableMenu || $item->Type == 'SiteTree')) { if ($item->Type == 'SiteTree') { $config->addComponent(new CopyChildrenFromCurrentPage('actions-buttons-before-left')); } $config->addComponents((new AddExistingPicker('actions-buttons-before-left'))->setTitle(_t('LinkableMenus.COPY_CHILDREN_FROM', 'Copy children from other {item}', ['item' => singleton('SiteTree')->i18n_singular_name()]))->setSearchList(DataList::create('SiteTree'))->setUrlSegment('copy-links-from-sitetree')->setAddHandler(function ($request, $grid, $button, $acquireItems) use($model) { $items = $acquireItems($request); if (!$items) { return; } foreach ($items as $item) { $children = $item->Children(); foreach ($children as $child) { $link = $model->create(); $link->Type = 'SiteTree'; $link->SiteTreeID = $child->ID; $link->write(); $grid->getList()->add($link); } } })->setUndoHandler(function ($request, $grid, $button, $acquireItems) use($model) { $items = $acquireItems($request); if (!$items) { return; } foreach ($items as $item) { if ($links = $grid->getList()->Relation('SiteTree')->sort('Created DESC')->filter('ParentID', $item->ID)) { $links->delete(); } } }), new CopyChildrenFromRoot('actions-buttons-before-left')); } if ($detailForm = $config->getComponentByType('GridFieldDetailForm')) { $detailForm->setItemEditFormCallback(function ($form, $controller) use($item) { if (isset($controller->record)) { $record = $controller->record; } elseif ($form->Record) { $record = $form->Record; } else { $record = null; } if ($record && $record instanceof \Link) { $record->allowLinkToActAsMenu($form->Fields(), $form, 'MenuLinks', $item, $controller); } }); } } else { $fieldsForForm[] = $links = \FormMessageField::create('ERR-SAVE_FIRST', _t('LinkableMenus.SAVE_FIRST', 'Please save before adding any sub-menu links'), 'warning')->cms(); } $fields->addFieldsToTab('Root.Main', [$fieldsForForm[] = \LiteralField::create('HR-SUB_MENU', '<p><br /></p>'), $fieldsForForm[] = \HeaderField::create('HEADING-SUB_MENU', _t('Link.SUB_MENU', 'Sub-menu'), 3), $links]); if ($form) { foreach ($fieldsForForm as $field) { $field->setForm($form); } } $this->owner->extend('updateLinkThatCanActAsMenuFields', $fields, $form, $relation, $parent, $controller, $item); }
public function updateCMSFields(FieldList $fields) { $log = singleton($this->owner->OrderStatusLogs()->dataClass()); $order = $this->owner; if (!$this->owner->IsCart()) { $state = $this->owner->State; $stateLog = $this->owner->StateLog; if (in_array($state, OrderLog::$ARCHIVED_STATUS)) { $fields->insertBefore('Status', \FormMessageField::create('IS-ARCHIVED', _t('OrderLog.ORDER_IS_ARCHIVED', 'This order was archived on <strong>{date}</strong>', ['date' => $stateLog->Created]), 'info')->cms()); } if (isset($log->config()->status_list[$state])) { $state = $log->config()->status_list[$state]['icon'] . ' ' . $log->config()->status_list[$state]['title']; } $fields->replaceField('Status', $state = ReadonlyField::create('READONLY-State', 'Status', $state)->addExtraClass('important')->setDescription(_t('Order.DESC-State', 'The status of your order is controlled by the order logging system. <a href="{logTab}" class="ss-tabset-goto">You can add a new log here.</a>', ['logTab' => singleton('director')->url('#tab-Root_Logs')]))); $state->dontEscape = true; } singleton('require')->include_font_css(); $maxRecords = $log->config()->max_records_per_order; $fields->addFieldsToTab('Root.Logs', [GridField::create('OrderStatusLogs', 'History', $this->owner->LogsByStatusPriority(), $gfc = GridFieldConfig_RecordEditor::create($maxRecords)->removeComponentsByType('GridFieldAddNewButton')->removeComponentsByType('GridFieldEditButton')->removeComponentsByType('GridFieldDetailForm')->addComponents(new DisplayAsTimeline(), $editable = new EditableRow(), new MinorActionsHolder('buttons-before-right'), $addNew[] = $button = new AddNewInlineExtended('actions-buttons-before-right', _t('OrderLog.ACTION-EMAIL', 'Send an email'), $log->NotificationFields)))]); $button->urlSegment = 'sendAnEmail'; $button->setItemEditFormCallback(function ($form) use($order, $log) { $form->loadDataFrom(['Status' => 'Notified', 'Send' => true, 'Note' => _t('OrderLog.DEFAULT-NOTIFIED-Note', 'Email was sent to customer'), 'Public' => true]); }); $gfc->addComponent((new HelpButton('buttons-before-left', _t('OrderLog.EMAIL_VARIABLES', 'Email helpers')))->setTemplate('OrderStatusLog_EmailHelpers')); singleton('require')->css(basename(dirname(dirname(dirname(__FILE__)))) . '/css/admin.css'); if (!$this->owner->OrderStatusLogs()->filter('Status', OrderLog::$SHIPPED_STATUS)->exists()) { $gfc->addComponent($minorActions[] = $addNew[] = $button = new AddNewInlineExtended('actions-buttons-before-right', _t('OrderLog.ACTION-SHIP', 'Send shipping details'), $log->ShippedToFields)); $shippedStatus = OrderLog::$SHIPPED_STATUS; $button->urlSegment = 'sendShippingDetails'; $button->setItemEditFormCallback(function ($form) use($order, $log, $shippedStatus) { $form->loadDataFrom(['Status' => $shippedStatus[0], 'Title' => _t('OrderLog.DEFAULT-SHIPPING-Title', '$Order.Reference has been shipped'), 'Note' => _t('OrderLog.DEFAULT-SHIPPING-Note', '$Order.Reference[/b] has been shipped to the following address: $Order.ShippingAddress.Title'), 'Public' => true, 'Send' => true, 'Send_Subject' => _t('OrderLog.DEFAULT-SHIPPING-Send_Subject', '$Order.Reference has been shipped'), 'Send_Body' => _t('OrderLog.DEFAULT-SHIPPING-Send_Body', '[b]$Order.Reference[/b] has been shipped to the following address:' . "<br />\n" . '[b]$Order.ShippingAddress.Title[/b]' . "<br /><br />\n\n" . '$Order.DispatchInformation')]); }); } $gfc->addComponent($addNew[] = $button = new AddNewInlineExtended('actions-buttons-before-right', _t('OrderLog.ACTION-QUERY', 'Log a customer query'))); $button->urlSegment = 'logQuery'; $button->setItemEditFormCallback(function ($form) use($order, $log) { $params = ['Status' => 'Query', 'Send' => true, 'Title' => _t('OrderLog.DEFAULT-QUERY-Title', 'A query was made by the customer'), 'Send_Subject' => _t('OrderLog.DEFAULT-QUERY-Subject', 'Query concerning $Order.Reference'), 'Public' => true]; $dataFields = $form->Fields()->dataFields(); if (isset($dataFields['Send_To']) && isset($dataFields['Send_From'])) { $params['Send_To'] = $dataFields['Send_From']->getAttribute('placeholder'); $params['Send_From'] = $dataFields['Send_To']->getAttribute('placeholder'); } $form->loadDataFrom($params); }); $gfc->addComponent($addNew[] = new AddNewInlineExtended('actions-buttons-before-right', _t('OrderLog.ACTION-DEFAULT', 'Detailed status update'))); if ($this->owner->OrderStatusLogs()->count() <= $maxRecords) { $gfc->removeComponentsByType('GridFieldPageCount'); $gfc->removeComponentsByType('GridFieldPaginator'); } foreach ($addNew as $button) { $button->prepend = true; } if ($dc = $gfc->getComponentByType('GridFieldDataColumns')) { $dc->setDisplayFields(['Title' => 'Status', 'Created' => 'Date']); $dc->setFieldFormatting(['Title' => '<strong>$Title</strong> $DetailsForDataGrid', 'Created' => '<strong>Logged $Created</strong>']); } foreach ($addNew as $button) { $cb = $button->getItemEditFormCallback(); $button->setItemEditFormCallback(function ($form, $controller, $grid, $modelClass, $removeEditableColumnFields) use($order, $log, $cb) { $log->setEditFormWithParent($order, $form, $controller); if ($cb) { $cb($form, $this, $grid, $modelClass, $removeEditableColumnFields); } }); } }