Source of file GridFieldDetailForm_ItemRequest.php
Size: 5,011 Bytes - Last Modified: 2021-12-23T10:21:36+00:00
/var/www/docs.ssmods.com/process/src/src/Admin/Forms/GridField/GridFieldDetailForm_ItemRequest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 | <?php namespace SilverCart\Admin\Forms\GridField; use SilverStripe\Core\Extension; use SilverStripe\Security\Member; use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; use SilverStripe\ORM\DataObject; /** * Extension for SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest. * * @package SilverCart * @subpackage Admin\Forms\GridField * @author Sebastian Diel <sdiel@pixeltricks.de> * @since 22.09.2017 * @copyright 2017 pixeltricks GmbH * @license see license file in modules root directory * * @property \SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest $owner Owner */ class GridFieldDetailForm_ItemRequest extends Extension { /** * Map of URL manageable dummy actions and original form actions. * * @var array */ private $actionMap = []; /** * Updates the item edit form. * * @param Form $form Form * * @return void */ public function updateItemEditForm(Form $form) : void { $record = $this->owner->record; if ($record instanceof DataObject) { if ($record instanceof Member && $record->exists() ) { $actions = $form->Actions(); $actions->push(FormAction::create('doSendChangePasswordEmail', _t(GridFieldDetailForm_ItemRequest::class . '.SendChangePasswordEmail', 'Send Change Password Email')) ->setUseButtonTag(true) ->addExtraClass('ss-ui-action-constructive') ->setAttribute('data-icon', 'accept')); } if ($record->hasMethod('getCMSActions') && $record->getCMSActions()->exists() ) { $index = 1; foreach ($record->getCMSActions() as $action) { /* @var $action FormAction */ $this->actionMap[$index] = $action->getName(); $action->setFullAction("action_sccustomaction{$index}"); $action->setName("action_sccustomaction{$index}"); $form->Actions()->push($action); $index++; } } } } /** * Handler for SilverCart custom CMS actions. * * @param int $index Numeric index to identify the original action * @param array $data Submitted data * @param Form $form Form * * @return mixed */ protected function handleSCCustomAction(int $index, array $data, Form $form) { if (!array_key_exists($index, $this->actionMap)) { return; } $originalAction = $this->actionMap[$index]; $methodName = preg_replace(['/^action_/','/_x$|_y$/'], '', $originalAction); $record = $this->owner->record; if ($record instanceof DataObject && $record->hasMethod($methodName) ) { return $record->{$methodName}($this->owner, $data, $form); } } /** * Dummy action handler for the first custom CMS action. * * @param array $data Submitted data * @param Form $form Form * * @return mixed */ public function sccustomaction1(array $data, Form $form) { return $this->handleSCCustomAction(1, $data, $form); } /** * Dummy action handler for the first custom CMS action. * * @param array $data Submitted data * @param Form $form Form * * @return mixed */ public function sccustomaction2(array $data, Form $form) { return $this->handleSCCustomAction(2, $data, $form); } /** * Dummy action handler for the first custom CMS action. * * @param array $data Submitted data * @param Form $form Form * * @return mixed */ public function sccustomaction3(array $data, Form $form) { return $this->handleSCCustomAction(3, $data, $form); } /** * Dummy action handler for the first custom CMS action. * * @param array $data Submitted data * @param Form $form Form * * @return mixed */ public function sccustomaction4(array $data, Form $form) { return $this->handleSCCustomAction(4, $data, $form); } /** * Dummy action handler for the first custom CMS action. * * @param array $data Submitted data * @param Form $form Form * * @return mixed */ public function sccustomaction5(array $data, Form $form) { return $this->handleSCCustomAction(5, $data, $form); } /** * Sends the change password email to the Member. * * @param array $data Data * @param Form $form Form * * @return void */ public function doSendChangePasswordEmail(array $data, Form $form) : void { $member = $this->owner->record; $member->sendChangePasswordEmail(); } } |