/** * @param FieldList $fields */ public function updateCMSFields(FieldList $fields) { $tabName = Config::inst()->get('Downloadable', 'tab_name'); $tabFields = array(); $upload = new UploadField('DownloadableFiles', ''); $upload->setFolderName(Config::inst()->get('Downloadable', 'source_folder')); $tabFields[] = $upload; // For certain types of products, it makes sense to include downloads // from parent (ProductVariation) or child products (GroupedProduct) // NOTE: there could be better ways to do this that don't involve checking // for specific classes. The advantage here is that the fields show up // even if the product has not yet been saved or doesn't yet have a // parent or child products. $p = $this->owner instanceof ProductVariation ? $this->owner->Product() : $this->owner->Parent(); if ($p && $p->exists() && $p->hasExtension('Downloadable')) { $tabFields[] = new CheckboxField('IncludeParentDownloads', 'Include downloads from parent product in purchase'); } elseif (class_exists('GroupedProduct') && $this->owner instanceof GroupedProduct) { $tabFields[] = new CheckboxField('IncludeChildDownloads', 'Include downloads from child products in purchase'); } // this will just add unnecessary queries slowing down the page load //$tabFields[] = new LiteralField('DownloadCount', '<p>Total Downloads: <strong>' . $this->owner->getDownloads()->count() . '</strong></p>'); // Product variations don't have tabs, so we need to be able // to handle either case. if ($fields->first() instanceof TabSet) { $fields->addFieldsToTab("Root.{$tabName}", $tabFields); } else { $fields->push(new HeaderField('DownloadsHeader', $tabName)); foreach ($tabFields as $f) { $fields->push($f); } } }
public function updateCMSFields(FieldList $fields) { $fields->removeByName('LastSignificantChange'); $fields->removeByName('ChangeDescription'); if ($this->owner->LastSignificantChange !== NULL) { $dateTime = new DateTime($this->owner->LastSignificantChange); //Put these fields on the top of the First Tab's form $fields->first()->Tabs()->first()->getChildren()->unshift(LabelField::create("infoLastSignificantChange", "<strong>Last Significant change was at: " . "{$dateTime->Format('d/m/Y H:i')}</strong>")); $fields->insertAfter(CheckboxField::create("isSignificantChange", "CLEAR Last Significant change: {$dateTime->Format('d/m/Y H:i')}")->setDescription('Check and save this Record again to clear the Last Significant change date.')->setValue(FALSE), 'infoLastSignificantChange'); $fields->insertAfter(TextField::create('ChangeDescription', 'Description of Changes')->setDescription('This is an automatically generated list of changes to important fields.'), 'isSignificantChange'); } }
/** * @return TextField */ public function getRawField() { return $this->children->first(); }
/** * Test replacing a field with another one. */ public function testReplaceField() { $fields = new FieldList(); $tab = new Tab('Root'); $fields->push($tab); /* A field gets added to the set */ $fields->addFieldToTab('Root', new TextField('Country')); $this->assertSame($fields->dataFieldByName('Country'), $tab->fieldByName('Country')); $fields->replaceField('Country', new EmailField('Email')); $this->assertEquals(1, $tab->Fields()->Count()); $fields = new FieldList(); $fields->push(new TextField('Name', 'Your name')); $brack = new TextField('Name[Field]', 'Your name'); $fields->replaceField('Name', $brack); $this->assertEquals(1, $fields->Count()); $this->assertEquals('Name[Field]', $fields->first()->getName()); }