Source of file BetterButton.php
Size: 2,455 Bytes - Last Modified: 2021-12-23T10:56:01+00:00
/var/www/docs.ssmods.com/process/src/src/Buttons/BetterButton.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | <?php namespace UncleCheese\BetterButtons\Buttons; use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest; use UncleCheese\BetterButtons\Extensions\BetterButtonGroupable; use UncleCheese\BetterButtons\Interfaces\BetterButtonInterface; /** * Defines the base class for all buttons that submit form data through GridField * * @author Uncle Cheese <unclecheese@leftandmain.com> * @package silverstripe-gridfield-betterbuttons */ abstract class BetterButton extends FormAction implements BetterButtonInterface { private static $extensions = array ( BetterButtonGroupable::class ); /** * The request that points to the GridFieldDetailForm * @var GridFieldDetailForm_ItemRequest */ protected $gridFieldRequest; /** * Bind to the GridField request * @param Form $form * @param GridFieldDetailForm_ItemRequest $request */ public function bindGridField(Form $form, GridFieldDetailForm_ItemRequest $request) { $this->setForm($form); $this->gridFieldRequest = $request; return $this; } /** * Performs any last-minute transformations to the button in accordance with anything * the user may have done after instantiating the button * * @return BetterButton */ public function baseTransform() { return $this; } /** * Tells the form action to become a standard form submit button * @return FormAction */ public function transformToButton() { $this->baseTransform(); return $this->setUseButtonTag(true); } /** * Tells the form action to become a standard input tag, e.g. for usage in a button group * @return FormAction */ public function transformToInput() { $this->baseTransform(); return $this; } /** * Determines if the button should display or not * @return bool */ public function shouldDisplay() { return true; } /** * Render the field with the correct attributes * @param array $properties * @return FormAction */ public function Field($properties = array ()) { if ($this->isGrouped()) { $this->transformToInput(); } else { $this->transformToButton(); } return parent::Field($properties); } } |