Source of file WorkflowFieldActionController.php
Size: 1,575 Bytes - Last Modified: 2021-12-24T06:44:28+00:00
/var/www/docs.ssmods.com/process/src/code/formfields/WorkflowFieldActionController.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?php /** * Handles requests for creating or editing actions. * * @package silverstripe-advancedworkflow */ use SilverStripe\Control\RequestHandler; class WorkflowFieldActionController extends RequestHandler { private static $url_handlers = array( 'new/$Class' => 'handleAdd', 'item/$ID' => 'handleItem' ); private static $allowed_actions = array( 'handleAdd', 'handleItem' ); protected $parent; protected $name; public function __construct($parent, $name) { $this->parent = $parent; $this->name = $name; parent::__construct(); } public function handleAdd() { $class = $this->request->param('Class'); if(!class_exists($class) || !is_subclass_of($class, 'WorkflowAction')) { $this->httpError(400); } $reflector = new ReflectionClass($class); if($reflector->isAbstract() || !singleton($class)->canCreate()) { $this->httpError(400); } $record = new $class(); $record->WorkflowDefID = $this->parent->Definition()->ID; return new WorkflowFieldItemController($this, "new/$class", $record); } public function handleItem() { $id = $this->request->param('ID'); $defn = $this->parent->Definition(); $action = $defn->Actions()->byID($id); if(!$action) { $this->httpError(404); } if(!$action->canEdit()) { $this->httpError(403); } return new WorkflowFieldItemController($this, "item/$id", $action); } public function RootField() { return $this->parent; } public function Link($action = null) { return Controller::join_links($this->parent->Link(), $this->name, $action); } } |