删除"编辑"和"从文件中删除"来自SilverStripe UploadField

时间:2016-03-01 17:02:35

标签: php silverstripe

通过Silverstripe 3.2我正在使用UploadField in a frontend form,它工作正常并且看起来很不错:

enter image description here

但是我想删除不需要的"编辑"和"从文件中删除"上传文件中的操作。

以下是我正在使用的UploadField初始化代码:

// upload field
$uploadField = new UploadField('File', 'Upload File');
$uploadField->setCanAttachExisting(false);
$uploadField->setCanPreviewFolder(false);
$uploadField->relationAutoSetting = false;
$uploadField->setAllowedMaxFileNumber(1);

是否缺少配置选项,或者我应该使用CSS隐藏按钮?

1 个答案:

答案 0 :(得分:5)

以下是我过去解决类似问题的方法:

// prevent showing preview folder
$uploadField->setConfig('canPreviewFolder', false);
// use a custom button-template with only the wanted buttons      
$uploadField->setTemplateFileButtons('UploadField_FrontendButtons');

模板UploadField_FrontendButtons.ss可能如下所示:

<button class="ss-uploadfield-item-remove ss-ui-button ui-corner-all" title="<% _t('UploadField.REMOVEINFO', 'Remove this file from here, but do not delete it from the file store') %>" data-icon="plug-disconnect-prohibition">
<% _t('UploadField.REMOVE', 'Remove') %></button>

上面的模板只是framework/templates/Includes/UploadField_FileButtons.ss

的精简版