Source of file TargetMethodWorkflowAction.php
Size: 1,560 Bytes - Last Modified: 2021-12-23T10:49:13+00:00
/var/www/docs.ssmods.com/process/src/src/Actions/TargetMethodWorkflowAction.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | <?php namespace Symbiote\AdvancedWorkflow\Actions; use SilverStripe\Core\ClassInfo; use SilverStripe\Forms\TextField; use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance; class TargetMethodWorkflowAction extends SetPropertyWorkflowAction { private static $db = [ 'TargetMethodName' => 'Varchar(64)', ]; // prevent users from accidentally doing something bad private static $method_blacklist = [ 'delete', 'write', 'merge', 'update', 'destroy' ]; private static $table_name = 'TargetMethodWorkflowAction'; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldsToTab('Root.Main', [ new TextField('TargetMethodName', $this->fieldLabel('TargetMethodName')), ]); $this->extend('updateTargetMethodCMSFields', $fields); return $fields; } public function fieldLabels($relations = true) { return array_merge(parent::fieldLabels($relations), [ 'TargetMethodName' => _t('TargetMethodWorkflowAction.TARGETMETHODNAME', 'Target method name'), ]); } public function execute(WorkflowInstance $workflow) { parent::execute($workflow); $target = $workflow->getTarget(); $method = $this->TargetMethodName; if ($method && ClassInfo::hasMethod($target, $method)) { if (!in_array($method, static::$method_blacklist)) { return $target->$method($workflow) !== false; } } return false; } } |