public function __construct($controller, $name, $fields = null, $actions = null, $validator = null) { if (!$fields) { $helpHtml = _t('MemberImportForm.Help1', '<p>Import users in <em>CSV format</em> (comma-separated values).' . ' <small><a href="#" class="toggle-advanced">Show advanced usage</a></small></p>'); $helpHtml .= _t('MemberImportForm.Help2', '<div class="advanced">' . '<h4>Advanced usage</h4>' . '<ul>' . '<li>Allowed columns: <em>%s</em></li>' . '<li>Existing users are matched by their unique <em>Code</em> property, and updated with any new values from ' . 'the imported file.</li>' . '<li>Groups can be assigned by the <em>Groups</em> column. Groups are identified by their <em>Code</em> property, ' . 'multiple groups can be separated by comma. Existing group memberships are not cleared.</li>' . '</ul>' . '</div>'); $importer = new MemberCsvBulkLoader(); $importSpec = $importer->getImportSpec(); $helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields']))); $fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('CsvFile', DBField::create_field('HTMLFragment', _t('SecurityAdmin_MemberImportForm.FileFieldLabel', 'CSV File <small>(Allowed extensions: *.csv)</small>')))); $fileField->getValidator()->setAllowedExtensions(array('csv')); } if (!$actions) { $action = new FormAction('doImport', _t('SecurityAdmin_MemberImportForm.BtnImport', 'Import from CSV')); $action->addExtraClass('btn btn-secondary-outline ss-ui-button'); $actions = new FieldList($action); } if (!$validator) { $validator = new RequiredFields('CsvFile'); } parent::__construct($controller, $name, $fields, $actions, $validator); Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/vendor.js'); Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js'); Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css'); $this->addExtraClass('cms'); $this->addExtraClass('import-form'); }
/** * Build the file selection form. * * @skipUpgrade * @return Form */ public function Form() { // Find out the requested folder ID. $folderID = $this->parent->getRequest()->requestVar('ParentID'); if ($folderID === null && $this->parent->getDisplayFolderName()) { $folder = Folder::find_or_make($this->parent->getDisplayFolderName()); $folderID = $folder ? $folder->ID : 0; } // Construct the form $action = new FormAction('doAttach', _t('UploadField.AttachFile', 'Attach file(s)')); $action->addExtraClass('ss-ui-action-constructive icon-accept'); $form = new Form($this, 'Form', new FieldList($this->getListField($folderID)), new FieldList($action)); // Add a class so we can reach the form from the frontend. $form->addExtraClass('uploadfield-form'); return $form; }
public function __construct($controller, $name, $fields = null, $actions = null, $validator = null) { if (!$fields) { $helpHtml = _t('GroupImportForm.Help1', '<p>Import one or more groups in <em>CSV</em> format (comma-separated values).' . ' <small><a href="#" class="toggle-advanced">Show advanced usage</a></small></p>'); $helpHtml .= _t('GroupImportForm.Help2', '<div class="advanced">' . '<h4>Advanced usage</h4>' . '<ul>' . '<li>Allowed columns: <em>%s</em></li>' . '<li>Existing groups are matched by their unique <em>Code</em> value, and updated with any new values from the ' . 'imported file</li>' . '<li>Group hierarchies can be created by using a <em>ParentCode</em> column.</li>' . '<li>Permission codes can be assigned by the <em>PermissionCode</em> column. Existing permission codes are not ' . 'cleared.</li>' . '</ul>' . '</div>'); $importer = new GroupCsvBulkLoader(); $importSpec = $importer->getImportSpec(); $helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields']))); $fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('CsvFile', DBField::create_field('HTMLFragment', _t('SecurityAdmin_MemberImportForm.FileFieldLabel', 'CSV File <small>(Allowed extensions: *.csv)</small>')))); $fileField->getValidator()->setAllowedExtensions(array('csv')); } if (!$actions) { $action = new FormAction('doImport', _t('SecurityAdmin_MemberImportForm.BtnImport', 'Import from CSV')); $action->addExtraClass('ss-ui-button'); $actions = new FieldList($action); } if (!$validator) { $validator = new RequiredFields('CsvFile'); } parent::__construct($controller, $name, $fields, $actions, $validator); $this->addExtraClass('cms'); $this->addExtraClass('import-form'); }
/** * FieldList $actions or string $name (of a method on File to provide a actions) for the EditForm * @example 'getCMSActions' * * @param DataObject $file File context to generate form actions for * @return FieldList Field list containing FormAction */ public function getFileEditActions(DataObject $file) { // Empty actions, generate default if (empty($this->fileEditActions)) { $actions = new FieldList($saveAction = new FormAction('doEdit', _t('UploadField.DOEDIT', 'Save'))); $saveAction->addExtraClass('ss-ui-action-constructive icon-accept'); return $actions; } // Actions instance if ($this->fileEditActions instanceof FieldList) { return $this->fileEditActions; } // Method to call on the given file if ($file->hasMethod($this->fileEditActions)) { return $file->{$this->fileEditActions}(); } throw new InvalidArgumentException("Invalid value for UploadField::fileEditActions"); }