public function MessageForm($request = null, $itemID = 0) { if ($itemID == 0) { $itemID = isset($_REQUEST['ToMemberID']) ? $_REQUEST['ToMemberID'] : 0; } $mergeText = "<ul><li>{" . implode("}</li><li>{", PostmarkHelper::MergeTags()) . "}</li></ul>"; $form = new Form($this, 'MessageForm', new FieldList(array(ObjectSelectorField::create('ToMemberID', 'To:')->setValue($itemID)->setSourceObject(Config::inst()->get('PostmarkAdmin', 'member_class'))->setDisplayField('Email'), DropdownField::create('FromID', 'From')->setSource(PostmarkSignature::get()->filter('IsActive', 1)->map('ID', 'Email')->toArray()), TextField::create('Subject'), QuillEditorField::create('Body'), LiteralField::create('MergeTypes', '<div class="varialbes toggle-block"> <h4>Merge Values</h4> <div class="contents">' . $mergeText . '</div> </div>'), HiddenField::create('InReplyToID')->setValue(isset($_REQUEST['ReplyToMessageID']) ? $_REQUEST['ReplyToMessageID'] : 0), FileField::create('Attachment_1', 'Attachment One'), FileField::create('Attachment_2', 'Attachment Two'), FileField::create('Attachment_3', 'Attachment Three'), FileField::create('Attachment_4', 'Attachment Four'), FileField::create('Attachment_5', 'Attachment Five'))), new FieldList(FormAction::create('postmessage', 'Sent Message'))); $requiredField = new RequiredFields(array('FromID', 'Subject', 'Body')); $form->setValidator($requiredField); $this->extend('updateMessageForm', $form, $itemID); $form->setFormAction($this->Link('PostmarkMessage/MessageForm')); return $form; }
/** * Calls {@link SiteTree->getCMSFields()} * * @param Int $id * @param FieldList $fields * @return Form */ public function getEditForm($id = null, $fields = null) { if (!$id) { $id = $this->currentPageID(); } if (is_object($id)) { $record = $id; } else { $record = $this->getRecord($id); if ($record && !$record->canView()) { return Security::permissionFailure($this); } } if ($record) { $fields = $fields ? $fields : $record->getCMSFields(); if ($fields == null) { user_error("getCMSFields() returned null - it should return a FieldList object. \n\t\t\t\t\tPerhaps you forgot to put a return statement at the end of your method?", E_USER_ERROR); } // Add hidden fields which are required for saving the record // and loading the UI state if (!$fields->dataFieldByName('ClassName')) { $fields->push(new HiddenField('ClassName')); } if (Object::has_extension($this->stat('tree_class'), 'Hierarchy') && !$fields->dataFieldByName('ParentID')) { $fields->push(new HiddenField('ParentID')); } // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load if (in_array('CMSPreviewable', class_implements($record))) { $navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()); $navField->setAllowHTML(true); $fields->push($navField); } if ($record->hasMethod('getAllCMSActions')) { $actions = $record->getAllCMSActions(); } else { $actions = $record->getCMSActions(); // add default actions if none are defined if (!$actions || !$actions->Count()) { if ($record->hasMethod('canEdit') && $record->canEdit()) { $actions->push(FormAction::create('save', _t('CMSMain.SAVE', 'Save'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')); } if ($record->hasMethod('canDelete') && $record->canDelete()) { $actions->push(FormAction::create('delete', _t('ModelAdmin.DELETE', 'Delete'))->addExtraClass('ss-ui-action-destructive')); } } } // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if ($actionsFlattened) { foreach ($actionsFlattened as $action) { $action->setUseButtonTag(true); } } $form = new Form($this, "EditForm", $fields, $actions); $form->addExtraClass('cms-edit-form'); $form->loadDataFrom($record); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); // Set this if you want to split up tabs into a separate header row // if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); // Add a default or custom validator. // @todo Currently the default Validator.js implementation // adds javascript to the document body, meaning it won't // be included properly if the associated fields are loaded // through ajax. This means only serverside validation // will kick in for pages+validation loaded through ajax. // This will be solved by using less obtrusive javascript validation // in the future, see http://open.silverstripe.com/ticket/2915 and // http://open.silverstripe.com/ticket/3386 if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); // The clientside (mainly LeftAndMain*.js) rely on ajax responses // which can be evaluated as javascript, hence we need // to override any global changes to the validation handler. $form->setValidator($validator); } else { $form->unsetValidator(); } if ($record->hasMethod('canEdit') && !$record->canEdit()) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } } else { $form = $this->EmptyForm(); } return $form; }
public function getEditForm($id = null) { if (!$id) { $id = $this->currentPageID(); } $record = $id && $id != "root" ? $this->getRecord($id) : null; if ($record && !$record->canView()) { return Security::permissionFailure($this); } if ($record) { $fields = $record->getCMSFields(); if ($fields == null) { user_error("getCMSFields() returned null - it should return a FieldSet object. \n\t\t\t\t\tPerhaps you forgot to put a return statement at the end of your method?", E_USER_ERROR); } // Add hidden fields which are required for saving the record // and loading the UI state if (!$fields->dataFieldByName('ClassName')) { $fields->push(new HiddenField('ClassName')); } if (Object::has_extension($this->stat('tree_class'), 'Hierarchy') && !$fields->dataFieldByName('ParentID')) { $fields->push(new HiddenField('ParentID')); } if ($record->hasMethod('getAllCMSActions')) { $actions = $record->getAllCMSActions(); } else { $actions = $record->getCMSActions(); // add default actions if none are defined if (!$actions || !$actions->Count()) { if ($record->canEdit()) { $actions->push(new FormAction('save', _t('CMSMain.SAVE', 'Save'))); } } } $form = new Form($this, "EditForm", $fields, $actions); $form->loadDataFrom($record); // Add a default or custom validator. // @todo Currently the default Validator.js implementation // adds javascript to the document body, meaning it won't // be included properly if the associated fields are loaded // through ajax. This means only serverside validation // will kick in for pages+validation loaded through ajax. // This will be solved by using less obtrusive javascript validation // in the future, see http://open.silverstripe.com/ticket/2915 and // http://open.silverstripe.com/ticket/3386 if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); // The clientside (mainly LeftAndMain*.js) rely on ajax responses // which can be evaluated as javascript, hence we need // to override any global changes to the validation handler. $validator->setJavascriptValidationHandler('prototype'); $form->setValidator($validator); } else { $form->unsetValidator(); } if (!$record->canEdit()) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } } else { $form = $this->RootForm(); } return $form; }
/** * Calls {@link DataObject->getCMSFields()} * * @param Int $id * @param FieldList $fields * @return Form */ public function ItemEditForm($id = null, $fields = null) { if ($this->record) { $className = $this->getItemClassName(); $record = null; if ($id && is_numeric($id)) { $record = DataObject::get_by_id($className, (int) $id); } else { if (!empty($_REQUEST['RecordID'])) { $record = DataObject::get_by_id($className, (int) $_REQUEST['RecordID']); } else { if (!empty($_REQUEST['ID'])) { $record = DataObject::get_by_id($className, (int) $_REQUEST['ID']); } else { if ($this->_idField) { $record = DataObject::get_by_id($className, (int) $this->_idField); } else { if ($id = $this->getSessionID()) { $record = DataObject::get_by_id($className, $id); } } } } } if (!$record) { $record = new $className(); } $fields = $fields ? $fields : $record->getCMSFields(); if ($fields == null) { user_error("getCMSFields() returned null - it should return a FieldList object.\n Perhaps you forgot to put a return statement at the end of your method?", E_USER_ERROR); } if ($record->hasMethod('getAllCMSActions')) { $actions = $record->getAllCMSActions(); } else { $actions = $record->getCMSActions(); // add default actions if none are defined if (!$actions || !$actions->Count()) { if ($record->hasMethod('canEdit') && $record->canEdit()) { $actions->push(FormAction::create('save', _t('CMSMain.SAVE', 'Save'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')); } if ($record->hasMethod('canDelete') && $record->canDelete() && $record->exists()) { $actions->push(FormAction::create('delete', _t('ModelAdmin.DELETE', 'Delete'))->addExtraClass('ss-ui-action-destructive')); } } } // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if ($actionsFlattened) { foreach ($actionsFlattened as $action) { $action->setUseButtonTag(true); } } $form = new Form($this, "ItemEditForm", $fields, $actions); $form->addExtraClass('cms-edit-form ContentRelationshipEditor_Form'); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); // Set this if you want to split up tabs into a separate header row // if($form->Fields()->hasTabset()) { // $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); // } // Add a default or custom validator. // @todo Currently the default Validator.js implementation // adds javascript to the document body, meaning it won't // be included properly if the associated fields are loaded // through ajax. This means only serverside validation // will kick in for pages+validation loaded through ajax. // This will be solved by using less obtrusive javascript validation // in the future, see http://open.silverstripe.com/ticket/2915 and // http://open.silverstripe.com/ticket/3386 if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); // The clientside (mainly LeftAndMain*.js) rely on ajax responses // which can be evaluated as javascript, hence we need // to override any global changes to the validation handler. $form->setValidator($validator); } else { $form->unsetValidator(); } if ($record->hasMethod('canEdit') && !$record->canEdit()) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } if ($record->exists()) { //rename to recordID so it doesn't conflict with CMSMain/LeftAndMain $fields->push(new HiddenField('RecordID', 'RecordID', $record->ID)); //store in session so we can use for subfields $this->setSessionID($record->ID); } $form->loadDataFrom($record); //echo $form->getRecord()->ID;exit; $form->setFormAction($this->Link('ItemEditForm')); return $form; } return false; }