当前位置: 首页>>代码示例>>PHP>>正文


PHP Form::loadDataFrom方法代码示例

本文整理汇总了PHP中Form::loadDataFrom方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::loadDataFrom方法的具体用法?PHP Form::loadDataFrom怎么用?PHP Form::loadDataFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Form的用法示例。


在下文中一共展示了Form::loadDataFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testLoadDataFromIgnoreFalseish

 public function testLoadDataFromIgnoreFalseish()
 {
     $form = new Form(new Controller(), 'Form', new FieldList(new TextField('Biography', 'Biography', 'Custom Default')), new FieldList());
     $captainNoDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
     $captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainWithDetails');
     $form->loadDataFrom($captainNoDetails, Form::MERGE_IGNORE_FALSEISH);
     $this->assertEquals($form->getData(), array('Biography' => 'Custom Default'), 'LoadDataFrom() doesn\'t overwrite fields when MERGE_IGNORE_FALSEISH set and values are false-ish');
     $form->loadDataFrom($captainWithDetails, Form::MERGE_IGNORE_FALSEISH);
     $this->assertEquals($form->getData(), array('Biography' => 'Bio 1'), 'LoadDataFrom() does overwrite fields when MERGE_IGNORE_FALSEISH set and values arent false-ish');
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:10,代码来源:FormTest.php

示例2: testLoadDataFromClearMissingFields

 public function testLoadDataFromClearMissingFields()
 {
     $form = new Form(new Controller(), 'Form', new FieldSet(new HeaderField('MyPlayerHeader', 'My Player'), new TextField('Name'), new TextareaField('Biography'), new DateField('Birthday'), new NumericField('BirthdayYear'), $unrelatedField = new TextField('UnrelatedFormField')), new FieldSet());
     $unrelatedField->setValue("random value");
     $captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainWithDetails');
     $captainNoDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
     $form->loadDataFrom($captainWithDetails);
     $this->assertEquals($form->getData(), array('Name' => 'Captain Details', 'Biography' => 'Bio 1', 'Birthday' => '1982-01-01', 'BirthdayYear' => '1982', 'UnrelatedFormField' => 'random value'), 'LoadDataFrom() doesnt overwrite fields not found in the object');
     $captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
     $team2 = $this->objFromFixture('FormTest_Team', 'team2');
     $form->loadDataFrom($captainWithDetails);
     $form->loadDataFrom($team2, true);
     $this->assertEquals($form->getData(), array('Name' => 'Team 2', 'Biography' => '', 'Birthday' => '', 'BirthdayYear' => 0, 'UnrelatedFormField' => null), 'LoadDataFrom() overwrites fields not found in the object with $clearMissingFields=true');
 }
开发者ID:Raiser,项目名称:Praktikum,代码行数:14,代码来源:FormTest.php

示例3: testGetFormFields

 public function testGetFormFields()
 {
     $fields = singleton('FormScaffolderTest_Article')->getFrontEndFields();
     $form = new Form(new Controller(), 'TestForm', $fields, new FieldList());
     $form->loadDataFrom(singleton('FormScaffolderTest_Article'));
     $this->assertFalse($fields->hasTabSet(), 'getFrontEndFields() doesnt produce a TabSet by default');
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:7,代码来源:FormScaffolderTest.php

示例4: getEditForm

 /**
  * @return Form
  */
 function getEditForm($id = null, $fields = null)
 {
     $siteConfig = SiteConfig::current_site_config();
     $fields = $siteConfig->getCMSFields();
     $actions = $siteConfig->getCMSActions();
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->addExtraClass('root-form');
     $form->addExtraClass('cms-edit-form cms-panel-padded center');
     // don't add data-pjax-fragment=CurrentForm, its added in the content template instead
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     $form->setHTMLID('Form_EditForm');
     $form->loadDataFrom($siteConfig);
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     // Use <button> to allow full jQuery UI styling
     $actions = $actions->dataFields();
     if ($actions) {
         foreach ($actions as $action) {
             $action->setUseButtonTag(true);
         }
     }
     $this->extend('updateEditForm', $form);
     return $form;
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:28,代码来源:CMSSettingsController.php

示例5: ExpandableForm

 public function ExpandableForm()
 {
     if ($this->formorfields instanceof FieldList) {
         $fields = $this->formorfields;
     } else {
         if ($this->formorfields instanceof ViewableData) {
             $form = $this->formorfields;
         } else {
             if ($this->record->hasMethod('getExandableForm')) {
                 $form = $this->record->getExandableForm($this, __FUNCTION__);
                 $this->record->extend('updateExandableForm', $form);
             } else {
                 if ($this->record->hasMethod('getExandableFormFields')) {
                     $fields = $this->record->getExandableFormFields();
                     $this->record->extend('updateExandableFormFields', $fields);
                 } else {
                     $fields = $this->record->scaffoldFormFields();
                     $this->record->extend('updateExandableFormFields', $fields);
                 }
             }
         }
     }
     if (empty($form)) {
         $actions = new FieldList();
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setAttribute('data-action-type', 'default'));
         $form = new Form($this, 'ExpandableForm', $fields, $actions, $this->validator);
     }
     $form->loadDataFrom($this->record, Form::MERGE_DEFAULT);
     $form->IncludeFormTag = false;
     return $form;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-gridfield-addons,代码行数:31,代码来源:GridFieldExpandableForm.php

示例6: getEditForm

 /**
  * Returns the edit form for this admin.
  * 
  * @param type $id
  * @param type $fields
  * 
  * @return Form
  */
 public function getEditForm($id = null, $fields = null)
 {
     $fields = new FieldList();
     $desc = _t('SilvercartProductImageAdmin.Description');
     $descriptionField = new SilvercartAlertInfoField('SilvercartProductImagesDescription', str_replace(PHP_EOL, '<br/>', $desc));
     $uploadField = new UploadField('SilvercartProductImages', _t('SilvercartProductImageAdmin.UploadProductImages', 'Upload product images'));
     $uploadField->setFolderName(SilvercartProductImageImporter::get_relative_upload_folder());
     $fields->push($uploadField);
     $fields->push($descriptionField);
     if (!SilvercartProductImageImporter::is_installed()) {
         $cronTitle = _t('SilvercartProductImageAdmin.CronNotInstalledTitle') . ':';
         $cron = _t('SilvercartProductImageAdmin.CronNotInstalledDescription');
         $cronjobInfoField = new SilvercartAlertDangerField('SilvercartProductImagesCronjobInfo', str_replace(PHP_EOL, '<br/>', $cron), $cronTitle);
         $fields->insertAfter('SilvercartProductImages', $cronjobInfoField);
     } elseif (SilvercartProductImageImporter::is_running()) {
         $cronTitle = _t('SilvercartProductImageAdmin.CronIsRunningTitle') . ':';
         $cron = _t('SilvercartProductImageAdmin.CronIsRunningDescription');
         $cronjobInfoField = new SilvercartAlertSuccessField('SilvercartProductImagesCronjobInfo', str_replace(PHP_EOL, '<br/>', $cron), $cronTitle);
         $fields->insertAfter('SilvercartProductImages', $cronjobInfoField);
     }
     $uploadedFiles = $this->getUploadedFiles();
     if (count($uploadedFiles) > 0) {
         $uploadedFilesInfo = '<br/>' . implode('<br/>', $uploadedFiles);
         $fileInfoField = new SilvercartAlertWarningField('SilvercartProductImagesFileInfo', $uploadedFilesInfo, _t('SilvercartProductImageAdmin.FileInfoTitle'));
         $fields->insertAfter('SilvercartProductImages', $fileInfoField);
     }
     $actions = new FieldList();
     $form = new Form($this, "EditForm", $fields, $actions);
     $form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());
     $form->loadDataFrom($this->request->getVars());
     $this->extend('updateEditForm', $form);
     return $form;
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:41,代码来源:SilvercartProductImageAdmin.php

示例7: EditProfileForm

 /**
  * @return Form|SS_HTTPResponse
  */
 public function EditProfileForm()
 {
     if (!Member::currentUser()) {
         $this->setFlash(_t('EditProfilePage.LoginWarning', 'Please login to edit your profile'), 'warning');
         return $this->redirect(Director::absoluteBaseURL());
     }
     $firstName = new TextField('FirstName');
     $firstName->setAttribute('placeholder', _t('EditProfilePage.FirstNamePlaceholder', 'Enter your first name'))->setAttribute('required', 'required')->addExtraClass('form-control');
     $surname = new TextField('Surname');
     $surname->setAttribute('placeholder', _t('EditProfilePage.SurnamePlaceholder', 'Enter your surname'))->setAttribute('required', 'required')->addExtraClass('form-control');
     $email = new EmailField('Email');
     $email->setAttribute('placeholder', _t('EditProfilePage.EmailPlaceholder', 'Enter your email address'))->setAttribute('required', 'required')->addExtraClass('form-control');
     $jobTitle = new TextField('JobTitle');
     $jobTitle->setAttribute('placeholder', _t('EditProfilePage.JobTitlePlaceholder', 'Enter your job title'))->addExtraClass('form-control');
     $website = new TextField('Website');
     $website->setAttribute('placeholder', _t('EditProfilePage.WebsitePlaceholder', 'Enter your website'))->addExtraClass('form-control');
     $blurb = new TextareaField('Blurb');
     $blurb->setAttribute('placeholder', _t('EditProfilePage.BlurbPlaceholder', 'Enter your blurb'))->addExtraClass('form-control');
     $confirmPassword = new ConfirmedPasswordField('Password', _t('EditProfilePage.PasswordLabel', 'New Password'));
     $confirmPassword->canBeEmpty = true;
     $confirmPassword->setAttribute('placeholder', _t('EditProfilePage.PasswordPlaceholder', 'Enter your password'))->addExtraClass('form-control');
     $fields = new FieldList($firstName, $surname, $email, $jobTitle, $website, $blurb, $confirmPassword);
     $action = new FormAction('SaveProfile', _t('EditProfilePage.SaveProfileText', 'Update Profile'));
     $action->addExtraClass('btn btn-primary btn-lg');
     $actions = new FieldList($action);
     // Create action
     $validator = new RequiredFields('FirstName', 'Email');
     //Create form
     $form = new Form($this, 'EditProfileForm', $fields, $actions, $validator);
     //Populate the form with the current members data
     $Member = Member::currentUser();
     $form->loadDataFrom($Member->data());
     //Return the form
     return $form;
 }
开发者ID:ormandroid,项目名称:ss_boilerplate,代码行数:38,代码来源:EditProfilePage.php

示例8: getEditForm

 /**
  * @return Form
  * @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore
  */
 public function getEditForm($id = null, $fields = null)
 {
     Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
     Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
     $folder = $this->currentPage();
     $uploadField = UploadField::create('AssetUploadField', '');
     $uploadField->setConfig('previewMaxWidth', 40);
     $uploadField->setConfig('previewMaxHeight', 30);
     $uploadField->addExtraClass('ss-assetuploadfield');
     $uploadField->removeExtraClass('ss-uploadfield');
     $uploadField->setTemplate('AssetUploadField');
     if ($folder->exists() && $folder->getFilename()) {
         // The Upload class expects a folder relative *within* assets/
         $path = preg_replace('/^' . ASSETS_DIR . '\\//', '', $folder->getFilename());
         $uploadField->setFolderName($path);
     } else {
         $uploadField->setFolderName(ASSETS_DIR);
     }
     $exts = $uploadField->getValidator()->getAllowedExtensions();
     asort($exts);
     $form = new Form($this, 'getEditForm', new FieldList($uploadField, new LiteralField('AllowedExtensions', sprintf('<p>%s: %s</p>', _t('AssetAdmin.ALLOWEDEXTS', 'Allowed extensions'), implode('<em>, </em>', $exts))), new HiddenField('ID')), new FieldList());
     $form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses());
     // Don't use AssetAdmin_EditForm, as it assumes a different panel structure
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     $form->Fields()->push(new LiteralField('BackLink', sprintf('<a href="%s" class="backlink ss-ui-button cms-panel-link" data-icon="back">%s</a>', Controller::join_links(singleton('AssetAdmin')->Link('show'), $folder ? $folder->ID : 0), _t('AssetAdmin.BackToFolder', 'Back to folder'))));
     $form->loadDataFrom($folder);
     return $form;
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:32,代码来源:CMSFileAddController.php

示例9: getGoogleSiteSearchForm

 /**
  * returns the form
  * @return Form
  */
 public function getGoogleSiteSearchForm($name = "GoogleSiteSearchForm")
 {
     $formIDinHTML = "Form_" . $name;
     if ($page = GoogleCustomSearchPage::get()->first()) {
         Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
         Requirements::javascript('googlecustomsearch/javascript/GoogleCustomSearch.js');
         $apiKey = Config::inst()->get("GoogleCustomSearchExt", "api_key");
         $cxKey = Config::inst()->get("GoogleCustomSearchExt", "cx_key");
         if ($apiKey && $cxKey) {
             Requirements::customScript("\n\t\t\t\t\t\tGoogleCustomSearch.apiKey = '" . $apiKey . "';\n\t\t\t\t\t\tGoogleCustomSearch.cxKey = '" . $cxKey . "';\n\t\t\t\t\t\tGoogleCustomSearch.formSelector = '#" . $formIDinHTML . "';\n\t\t\t\t\t\tGoogleCustomSearch.inputFieldSelector = '#" . $formIDinHTML . "_search';\n\t\t\t\t\t\tGoogleCustomSearch.resultsSelector = '#" . $formIDinHTML . "_Results';\n\t\t\t\t\t", "GoogleCustomSearchExt");
             $form = new Form($this->owner, 'GoogleSiteSearchForm', new FieldList($searchField = new TextField('search'), $resultField = new LiteralField($name . "_Results", "<div id=\"" . $formIDinHTML . "_Results\"></div>")), new FieldList(new FormAction('doSearch', _t("GoogleCustomSearchExt.GO", "Full Results"))));
             $form->setFormMethod('GET');
             if ($page = GoogleCustomSearchPage::get()->first()) {
                 $form->setFormAction($page->Link());
             }
             $form->disableSecurityToken();
             $form->loadDataFrom($_GET);
             $searchField->setAttribute("autocomplete", "off");
             $form->setAttribute("autocomplete", "off");
             return $form;
         } else {
             user_error("You must set an API Key and a CX key in your configs to use the Google Custom Search Form", E_USER_NOTICE);
         }
     } else {
         user_error("You must create a GoogleCustomSearchPage first.", E_USER_NOTICE);
     }
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-googlecustomsearch,代码行数:31,代码来源:GoogleCustomSearchExt.php

示例10: TrialSignupForm

 function TrialSignupForm()
 {
     $cardType = array("visa" => "<img src='themes/attwiz/images/visa.png' height=30px></img>", "mc" => "<img src='themes/attwiz/images/mastercard.jpeg' height=30px></img>", "amex" => "<img src='themes/attwiz/images/ae.jpeg' height=30px></img>", "discover" => "<img src='themes/attwiz/images/discover.jpeg' height=30px></img>");
     $monthArray = array();
     for ($i = 1; $i <= 12; $i++) {
         $monthArray[$i] = date('F', mktime(0, 0, 0, $i));
     }
     $yearArray = array();
     $currentYear = date('Y');
     for ($i = 0; $i <= 10; $i++) {
         $yearArray[$currentYear + $i] = $currentYear + $i;
     }
     $trialExpiryDate = date('F-j-Y', mktime(0, 0, 0, date('n') + 1, date('j'), date('Y')));
     $subscriptionInfo = "<div id='SubscriptionInfo'><h2>Post-Trial Subscription Selection</h2>\n\t    <p>Your 10 heatmaps will expire on {$trialExpiryDate}, at which time your account \n\t    will be replenished with a new allocation of heatmap credits according to the \n\t    subscription level you choose below. You may cancel your subscription any time \n\t    before your trial period ends and your  credit card will only be charged 1 dollar.</p></div>";
     $subscriptionType = array("1" => "Bronze - (10 heatmaps for \$27.00 / month)", "2" => "Silver - (50 heatmaps for \$97.00 / month)", "3" => "Gold - (200 heatmaps for \$197.00 / month)");
     $whatsThis = '<span id="WhatsThis"><a id="WhatsThisImage" href="themes/attwiz/images/cvv.jpg" title="What\'s this?">What\'s this?</a></span>';
     $fields = new FieldList(new TextField('FirstName', 'First Name'), new TextField('LastName', 'Last Name'), new TextField('Company', 'Company(optional)'), new TextField('StreetAddress1', 'Street Address1'), new TextField('StreetAddress2', 'Street Address2(optional)'), new TextField('City', 'City'), new TextField('State', 'State/Province'), new TextField('PostalCode', 'Zip/Poatal Code'), new CountryDropdownField('Country'), new OptionsetField('CreditCardType', 'Credit Card Type', $cardType, 'visa'), new TextField('NameOnCard', 'Name On Card'), new NumericField('CreditCardNumber', 'Credit Card Number'), new PasswordField('CVVCode', 'Security/CVV Code'), new LiteralField('WhatIsThis', $whatsThis), new DropdownField('ExpirationMonth', 'Expiration Date', $monthArray), new DropdownField('ExpirationYear', '', $yearArray), new LiteralField('SubscriptionInfo', $subscriptionInfo), new OptionsetField('SubscriptionType', '', $subscriptionType, '1'), new CheckboxField('Agreement', ' I understand that this is a recurring subscription and I will be billed monthly unless I cancel.'));
     // Create action
     $actions = new FieldList($submit = new FormAction('doSignup', 'Start Trial'));
     $submit->setAttribute('src', 'themes/attwiz/images/button_startmytrialnow.gif');
     // Create action
     $validator = new RequiredFields('FirstName', 'LastName', 'StreetAddress1', 'City', 'State', 'PoatalCode', 'Country', 'CreditCardType', 'NameOnCard', 'CreditCardNumber', 'CVVCode', 'ExpirationMonth', 'ExpirationYear', 'SubscriptionInfo', 'SubscriptionType');
     $validator = null;
     $form = new Form($this, 'TrialSignupForm', $fields, $actions, $validator);
     $data = Session::get("FormInfo.Form_TrialSignupForm.data");
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     return $form;
 }
开发者ID:hemant-chakka,项目名称:awss,代码行数:30,代码来源:TrialSignup.php

示例11: RegistrationForm

 public function RegistrationForm()
 {
     if ($this->request->getVar('key') && $this->request->getVar('token')) {
         $key = $this->request->getVar('key');
         $token = $this->request->getVar('token');
     } else {
         if ($this->request->isPOST()) {
             $key = $this->request->requestVar('Key');
             $token = $this->request->requestVar('Token');
         }
     }
     if ($key && $token) {
         $memory = ContributorMaps_Data::get()->filter(array('Unique_Key' => $key, 'EditToken' => $token, 'EditTokenExpires:GreaterThanOrEqual' => date('Y-m-d')))->First();
         if (!$memory) {
             return $this->redirect($this->Link("?action=edit&status=2"));
         }
     } else {
         if (Session::get("FormInfo.RegistrationForm_Edit.data")) {
             $memory = Session::get("FormInfo.RegistrationForm_Edit.data");
         }
     }
     $fields = new FieldList(new TextField('Name', 'Name*'), new TextField('Surname', 'Surname*'), new EmailField('Email', 'Email*'), new TextField('Location', 'Location* (e.g. Berlin, Deutschland)'), new HeaderField('Skills'), new CheckboxField('Skills_Design', 'Design'), new CheckboxField('Skills_Dev', 'Development'), new CheckboxField('Skills_Doc', 'Documentation'), new CheckboxField('Skills_Infra', 'Infrastructure'), new CheckboxField('Skills_l10n', 'Localisation'), new CheckboxField('Skills_Marketing', 'Marketing'), new CheckboxField('Skills_QA', 'Quality Assurance'), new CheckboxField('Skills_Base', 'Support - Base'), new CheckboxField('Skills_Calc', 'Support - Calc'), new CheckboxField('Skills_Draw', 'Support - Draw'), new CheckboxField('Skills_Impress', 'Support - Impress'), new CheckboxField('Skills_Math', 'Support - Math'), new CheckboxField('Skills_Writer', 'Support - Writer'));
     if ($memory) {
         $fields->push(new HiddenField('Key', '', $key));
         $fields->push(new HiddenField('Token', '', $token));
         $actions = new FieldList(new FormAction('processEditForm', 'Update'));
     } else {
         $recaptcha = new RecaptchaField('Captcha');
         $recaptcha->jsOptions = array('theme' => 'white');
         $fields->push($recaptcha);
         $actions = new FieldList(new FormAction('processForm', 'Register'));
     }
     $validator = new RequiredFields('Name', 'Surname', 'Email', 'Location');
     $form = new Form($this, 'RegistrationForm', $fields, $actions, $validator);
     //Load previously submitted data
     if ($memory) {
         $form->loadDataFrom($memory);
         Session::clear("FormInfo.{$form->FormName()}_Edit.data");
     } else {
         if (Session::get("FormInfo.{$form->FormName()}.data")) {
             $form->loadDataFrom(Session::get("FormInfo.{$form->FormName()}.data"));
             Session::clear("FormInfo.{$form->FormName()}.data");
         }
     }
     return $form;
 }
开发者ID:Liongold,项目名称:silverstripe-contributor-maps,代码行数:46,代码来源:ContributorMaps.php

示例12: Form

 /**
  * This form is exactly like the CMS form.  It gives us an opportunity to test the fields outside of the CMS context
  */
 function Form()
 {
     $fields = $this->getCMSFields();
     $actions = new FieldSet(new FormAction("save", "Save"), new ImageFormAction("gohome", "Go home", "frameworktest/images/test-button.png"));
     $form = new Form($this, "Form", $fields, $actions);
     $form->loadDataFrom($this->dataRecord);
     return $form;
 }
开发者ID:normann,项目名称:silverstripe-frameworktest,代码行数:11,代码来源:TestPage.php

示例13: testFormValidation

 public function testFormValidation()
 {
     $form = new Form(new Controller(), 'Form', new FieldList($field = new ConfirmedPasswordField('Password')), new FieldList());
     $form->loadDataFrom(array('Password' => array('_Password' => '123', '_ConfirmPassword' => '999')));
     $this->assertEquals('123', $field->children->first()->Value());
     $this->assertEquals('999', $field->children->last()->Value());
     $this->assertNotEquals($field->children->first()->Value(), $field->children->last()->Value());
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:8,代码来源:ConfirmedPasswordFieldTest.php

示例14: AddForm

 /**
  * @return Form
  */
 public function AddForm()
 {
     $method = $this->parent->parent->getOption('ExtraFields');
     $fields = $this->item->{$method}($this->parent->parent->parent);
     $form = new Form($this, 'AddForm', $fields, new FieldSet(new FormAction('doAdd', _t('ItemSetField.ADD', 'Add'))));
     $form->loadDataFrom($this->item);
     return $form;
 }
开发者ID:d00616,项目名称:silverstripe-itemsetfield,代码行数:11,代码来源:ManyManyPickerField.php

示例15: ItemEditForm

 /**
  * Builds an item edit form.  The arguments to getCMSFields() are the popupController and
  * popupFormName, however this is an experimental API and may change.
  * 
  * @todo In the future, we will probably need to come up with a tigher object representing a partially
  * complete controller with gaps for extra functionality.  This, for example, would be a better way
  * of letting Security/login put its log-in form inside a UI specified elsewhere.
  * 
  * @return Form 
  */
 function ItemEditForm()
 {
     if (empty($this->record)) {
         $controller = Controller::curr();
         $noActionURL = $controller->removeAction($_REQUEST['url']);
         $controller->getResponse()->removeHeader('Location');
         //clear the existing redirect
         return $controller->redirect($noActionURL, 302);
     }
     $actions = new FieldList();
     if ($this->record->ID !== 0) {
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'));
         $actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete'))->addExtraClass('ss-ui-action-destructive'));
     } else {
         // adding new record
         //Change the Save label to 'Create'
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Create', 'Create'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'add'));
         // Add a Cancel link which is a button-like link and link back to one level up.
         $curmbs = $this->Breadcrumbs();
         if ($curmbs && $curmbs->count() >= 2) {
             $one_level_up = $curmbs->offsetGet($curmbs->count() - 2);
             $cancelText = _t('GridFieldDetailForm.CancelBtn', 'Cancel');
             $text = "\r\n\t\t\t\t<a class=\"crumb ss-ui-button ss-ui-action-destructive cms-panel-link ui-corner-all\" href=\"" . $one_level_up->Link . "\">\r\n\t\t\t\t\t{$cancelText}\r\n\t\t\t\t</a>";
             $actions->push(new LiteralField('cancelbutton', $text));
         }
     }
     $fk = $this->gridField->getList()->foreignKey;
     $this->record->{$fk} = $this->gridField->getList()->foreignID;
     $form = new Form($this, 'ItemEditForm', $this->record->getCMSFields(), $actions, $this->component->getValidator());
     $form->loadDataFrom($this->record);
     // TODO Coupling with CMS
     $toplevelController = $this->getToplevelController();
     if ($toplevelController && $toplevelController instanceof LeftAndMain) {
         // Always show with base template (full width, no other panels),
         // regardless of overloaded CMS controller templates.
         // TODO Allow customization, e.g. to display an edit form alongside a search form from the CMS controller
         $form->setTemplate('LeftAndMain_EditForm');
         $form->addExtraClass('cms-content cms-edit-form center ss-tabset');
         $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
         if ($form->Fields()->hasTabset()) {
             $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
         }
         if ($toplevelController->hasMethod('Backlink')) {
             $form->Backlink = $toplevelController->Backlink();
         } elseif ($this->popupController->hasMethod('Breadcrumbs')) {
             $parents = $this->popupController->Breadcrumbs(false)->items;
             $form->Backlink = array_pop($parents)->Link;
         } else {
             $form->Backlink = $toplevelController->Link();
         }
     }
     $cb = $this->component->getItemEditFormCallback();
     if ($cb) {
         $cb($form, $this);
     }
     return $form;
 }
开发者ID:vinstah,项目名称:body,代码行数:67,代码来源:GridFieldDetailForm.php


注:本文中的Form::loadDataFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。