定制 level51/silverstripe-data-object-actions 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

level51/silverstripe-data-object-actions

最新稳定版本:2.0.1

Composer 安装命令:

composer require level51/silverstripe-data-object-actions

包简介

Custom GridField detail form actions for DataObjects

关键字:

README 文档

README

Module for Silverstripe 6 allowing to add custom actions for DataObjects to the GridFieldDetailForm. See 0.X releases for Silverstripe 4 support and 1.X releases for Silverstripe 5 support.

Installation

composer require level51/silverstripe-data-object-actions

Usage

namespace My\Awesome\Project;

use Level51\DataObjectActions\DataObjectActionProvider;
use Level51\DataObjectActions\DataObjectAction;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DataObject;

// Implement DataObjectActionProvider interface on your DataObject
class MyDataObject extends DataObject implements DataObjectActionProvider {

  // Return a field list containing all custom actions, each one of type DataObjectAction or DataObjectLink
  public function getCustomActions() 
  {
    return FieldList::create(
      [
        DataObjectAction::create('myCustomAction', 'My Custom Action')
          ->addExtraClass('btn-outline-primary font-icon-rocket')
          ->setUseButtonTag(true),
        DataObjectLink::create('externalLink', 'External Link', 'https://lvl51.de')
        	->addExtraClass('btn-outline-dark font-icon-external-link')
          ->setNewWindow(true)
      ]
    );
  }
	
  // Implement the handler method(s)
  public function myCustomAction($data, $form) 
  {
    // Do stuff, e.g. set a property
    // Do NOT call $this->write(), this will be done automatically
    // use `setWriteBeforeAction` when creating the action if the record 
    // should be written before the action is executed
		
    // throw a new \SilverStripe\Core\Validation\ValidationException in case something failed
		
    // Optionally return a success message
    return 'Success message';
  }

}

Usage with DataExtensions

You can update the custom actions of a parent class implementing the DataObjectActionProvider interface using the updateCustomActions extension hook.

public function updateCustomActions(FieldList $fields)
{
    $fields->push(
        DataObjectAction::create(...)
    );
}

To be able to add custom actions to an owner class which is out of your control (e.g. core Member class) you have to use the Level51\DataObjectActions\DataExtension class as base class of your extension. With that you are able to use the getCustomActions method as shown above.

Action Options

  • use setIsAlwaysEnabled to always enable the action, even if the whole edit form is read-only
  • use setWriteBeforeAction if the record should be written before the action is executed

Requirements

  • SilverStripe ^6
  • PHP >= 8.0

Maintainer

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-22