restruct/silverstripe-copybutton 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

restruct/silverstripe-copybutton

最新稳定版本:2.0.1

Composer 安装命令:

composer require restruct/silverstripe-copybutton

包简介

Adds copy/duplicate button to the GridField.

README 文档

README

Adds a copy/duplicate button to GridFields

Original author

Elvinas Liutkevičius <elvinas (at) unisolutions (dot) eu> (Forked from dhensby's SS4-updated fork for quick maintenance & updates/tags)

Documentation

Simply install the module using the standard method.

To add the button to the GridField you need to extend ModelAdmin and override getEditForm() method like this:

function getEditForm($id = null, $fields = null) {
	$form = parent::getEditForm();

	$form
		->Fields()
		->fieldByName($this->sanitiseClassName($this->modelClass))
		->getConfig()
		->addComponent(new CopyButton(), 'GridFieldEditButton') // or just ->addComponent(new CopyButton())
	;

	return $form;
}

This action will make exact copy of the record (with all relations and etc.). Note: you have to set configs for cascading duplications in your DataObjects to duplicate relations See: https://docs.silverstripe.org/en/4/developer_guides/model/relations/#cascading-duplications

Sometimes you will need to do some actions just after copy operation (i.e. you'll need to remove some relations). It is easily achieved by extending DataObject and writing all the actions in the onAfterDuplicate() method.

class SomeObjectExtension extends DataExtension {

	public function onAfterDuplicate() {
		DB::query("delete from Member_SomeObject where SomeObjectID = ".$this->owner->ID);
	}

}

统计信息

  • 总下载量: 1.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-10-28