本文整理汇总了PHP中UploadField::setRecord方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadField::setRecord方法的具体用法?PHP UploadField::setRecord怎么用?PHP UploadField::setRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadField
的用法示例。
在下文中一共展示了UploadField::setRecord方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadField
/**
* Set form to prevent error with link
* @return Object
*/
public function uploadField()
{
$field = new UploadField('Images');
$field->setRecord($this);
if (ContentModuleField::curr()) {
$field->setForm(ContentModuleField::curr()->getForm());
}
return $field;
}
示例2: getCMSFields
/**
* Returns the fields to power the edit screen of files in the CMS.
* You can modify this FieldList by subclassing folder, or by creating a {@link DataExtension}
* and implemeting updateCMSFields(FieldList $fields) on that extension.
*
* @return FieldList
*/
function getCMSFields()
{
// Preview
if ($this instanceof Image) {
$formattedImage = $this->getFormattedImage('SetWidth', Image::$asset_preview_width);
$thumbnail = $formattedImage ? $formattedImage->URL : '';
$previewField = new LiteralField("ImageFull", "<img id='thumbnailImage' class='thumbnail-preview' src='{$thumbnail}?r=" . rand(1, 100000) . "' alt='{$this->Name}' />\n");
} else {
$previewField = new LiteralField("ImageFull", $this->CMSThumbnail());
}
// Upload
$uploadField = new UploadField('UploadField', 'Upload Field');
$uploadField->setConfig('previewMaxWidth', 40);
$uploadField->setConfig('previewMaxHeight', 30);
$uploadField->setConfig('allowedMaxFileNumber', 1);
//$uploadField->setTemplate('FileEditUploadField');
if ($this->ParentID) {
$parent = $this->Parent();
if ($parent) {
//set the parent that the Upload field should use for uploads
$uploadField->setFolderName($parent->getFilename());
$uploadField->setRecord($parent);
}
}
//create the file attributes in a FieldGroup
$filePreview = CompositeField::create(CompositeField::create($previewField)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'), CompositeField::create(CompositeField::create(new ReadonlyField("FileType", _t('AssetTableField.TYPE', 'File type') . ':'), new ReadonlyField("Size", _t('AssetTableField.SIZE', 'File size') . ':', $this->getSize()), $urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL', 'URL'), sprintf('<a href="%s" target="_blank">%s</a>', $this->Link(), $this->RelativeLink())), new DateField_Disabled("Created", _t('AssetTableField.CREATED', 'First uploaded') . ':'), new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT', 'Last changed') . ':'), new ReadonlyField('BackLinkCount', _t('AssetTableField.BACKLINKCOUNT', 'Used on:'), $this->BackLinkTracking()->Count() . ' ' . _t('AssetTableField.PAGES', 'page(s)'))))->setName("FilePreviewData")->addExtraClass('cms-file-info-data'))->setName("FilePreview")->addExtraClass('cms-file-info');
$urlField->dontEscape = true;
//get a tree listing with only folder, no files
$folderTree = new TreeDropdownField("ParentID", _t('AssetTableField.FOLDER', 'Folder'), 'Folder');
$folderTree->setChildrenMethod('ChildFolders');
$fields = new FieldList(new TabSet('Root', new Tab('Main', $filePreview, new TextField("Title", _t('AssetTableField.TITLE', 'Title')), new TextField("Name", _t('AssetTableField.FILENAME', 'Filename')), new DropdownField("OwnerID", _t('AssetTableField.OWNER', 'Owner'), Member::mapInCMSGroups()), $folderTree)));
// Folder has its own updateCMSFields hook
if (!$this instanceof Folder) {
$this->extend('updateCMSFields', $fields);
}
return $fields;
}
示例3: Form
public function Form()
{
$record = DataObject::get_one('UploadFieldTest_Record', '"Title" = \'Record 1\'');
$fieldNoRelation = new UploadField('NoRelationField');
$fieldNoRelation->setFolderName('UploadFieldTest');
$fieldNoRelation->setRecord($record);
$fieldHasOne = new UploadField('HasOneFile');
$fieldHasOne->setFolderName('UploadFieldTest');
$fieldHasOne->setRecord($record);
$fieldHasOneExtendedFile = new UploadField('HasOneExtendedFile');
$fieldHasOneExtendedFile->setFolderName('UploadFieldTest');
$fieldHasOneExtendedFile->setRecord($record);
$fieldHasOneMaxOne = new UploadField('HasOneFileMaxOne');
$fieldHasOneMaxOne->setFolderName('UploadFieldTest');
$fieldHasOneMaxOne->setConfig('allowedMaxFileNumber', 1);
$fieldHasOneMaxOne->setRecord($record);
$fieldHasOneMaxTwo = new UploadField('HasOneFileMaxTwo');
$fieldHasOneMaxTwo->setFolderName('UploadFieldTest');
$fieldHasOneMaxTwo->setConfig('allowedMaxFileNumber', 2);
$fieldHasOneMaxTwo->setRecord($record);
$fieldHasMany = new UploadField('HasManyFiles');
$fieldHasMany->setFolderName('UploadFieldTest');
$fieldHasMany->setRecord($record);
$fieldHasManyMaxTwo = new UploadField('HasManyFilesMaxTwo');
$fieldHasManyMaxTwo->setFolderName('UploadFieldTest');
$fieldHasManyMaxTwo->setConfig('allowedMaxFileNumber', 2);
$fieldHasManyMaxTwo->setRecord($record);
$fieldManyMany = new UploadField('ManyManyFiles');
$fieldManyMany->setFolderName('UploadFieldTest');
$fieldManyMany->setRecord($record);
$fieldReadonly = new UploadField('ReadonlyField');
$fieldReadonly->setFolderName('UploadFieldTest');
$fieldReadonly->setRecord($record);
$fieldReadonly = $fieldReadonly->performReadonlyTransformation();
$fieldDisabled = new UploadField('DisabledField');
$fieldDisabled->setFolderName('UploadFieldTest');
$fieldDisabled->setRecord($record);
$fieldDisabled = $fieldDisabled->performDisabledTransformation();
$fieldSubfolder = new UploadField('SubfolderField');
$fieldSubfolder->setFolderName('UploadFieldTest/subfolder1');
$fieldSubfolder->setRecord($record);
$form = new Form($this, 'Form', new FieldList($fieldNoRelation, $fieldHasOne, $fieldHasOneMaxOne, $fieldHasOneMaxTwo, $fieldHasOneExtendedFile, $fieldHasMany, $fieldHasManyMaxTwo, $fieldManyMany, $fieldReadonly, $fieldDisabled, $fieldSubfolder), new FieldList(new FormAction('submit')), new RequiredFields('NoRelationField', 'HasOneFile', 'HasOneFileMaxOne', 'HasOneFileMaxTwo', 'HasOneExtendedFile', 'HasManyFiles', 'HasManyFilesMaxTwo', 'ManyManyFiles', 'ReadonlyField', 'DisabledField', 'SubfolderField'));
return $form;
}