Source of file DefaultLink.php
Size: 2,692 Bytes - Last Modified: 2021-12-23T10:00:19+00:00
/var/www/docs.ssmods.com/process/src/src/DefaultLink.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | <?php namespace LeKoala\CmsActions; use SilverStripe\Admin\ModelAdmin; use SilverStripe\Control\Controller; /** * Create custom links on ModelAdmin */ trait DefaultLink { /** * @var string */ protected $link; /** * @var boolean */ protected $newWindow = false; /** * Build a url to call an action on current model * * Takes into account ModelAdmin current model and set some defaults parameters * to send along * * If you want to call actions on the controller (ModelAdmin), use getControllerLink * * @param string $action * @param array $params * @return string */ public function getModelLink($action, array $params = null) { if ($params === null) { $params = []; } $ctrl = Controller::curr(); $fieldName = $ctrl->getRequest()->param('ModelClass'); $allParams = $ctrl->getRequest()->allParams(); $ID = $allParams['ID'] ?? 0; $params = array_merge(['CustomLink' => $action], $params); $action = '/EditForm/field/' . $fieldName . '/item/' . $ID . '/doCustomLink'; return $this->getControllerLink($action, $params); } /** * Build an url for the current controller and pass along some parameters * * If you want to call actions on a model, use getModelLink * * @param string $action * @param array $params * @return string */ public function getControllerLink($action, array $params = null) { if ($params === null) { $params = []; } $ctrl = Controller::curr(); if ($ctrl instanceof ModelAdmin) { $allParams = $ctrl->getRequest()->allParams(); $modelClass = $ctrl->getRequest()->param('ModelClass'); $action = $modelClass . '/' . $action; $params = array_merge($allParams, $params); } if (!empty($params)) { $action .= '?' . http_build_query($params); } return $ctrl->Link($action); } /** * Get the value of link */ public function getLink() { return $this->link; } /** * Set the value of link * * @return $this */ public function setLink($link) { $this->link = $link; return $this; } /** * Get the value of newWindow */ public function getNewWindow() { return $this->newWindow; } /** * Set the value of newWindow * * @return $this */ public function setNewWindow($newWindow) { $this->newWindow = $newWindow; return $this; } } |