diff --git a/src/ActionsGridFieldItemRequest.php b/src/ActionsGridFieldItemRequest.php index 381ae4b..bfd3dd1 100644 --- a/src/ActionsGridFieldItemRequest.php +++ b/src/ActionsGridFieldItemRequest.php @@ -9,9 +9,11 @@ use SilverStripe\ORM\DataObject; use SilverStripe\Core\Extensible; use SilverStripe\Forms\FieldList; +use SilverStripe\Forms\FormField; use SilverStripe\Control\Director; use SilverStripe\Forms\FormAction; use SilverStripe\Admin\LeftAndMain; +use SilverStripe\Forms\HiddenField; use SilverStripe\ORM\DataExtension; use SilverStripe\Control\Controller; use SilverStripe\Control\HTTPRequest; @@ -23,7 +25,6 @@ use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest; -use SilverStripe\Forms\HiddenField; /** * Decorates GridDetailForm_ItemRequest to use new form actions and buttons. @@ -36,7 +37,7 @@ * * @link https://github.com/unclecheese/silverstripe-gridfield-betterbuttons * @link https://github.com/unclecheese/silverstripe-gridfield-betterbuttons/blob/master/src/Extensions/GridFieldBetterButtonsItemRequest.php - * @property LeftAndMain|GridFieldDetailForm_ItemRequest|ActionsGridFieldItemRequest $owner + * @property LeftAndMain&GridFieldDetailForm_ItemRequest&ActionsGridFieldItemRequest $owner */ class ActionsGridFieldItemRequest extends DataExtension { @@ -68,7 +69,7 @@ class ActionsGridFieldItemRequest extends DataExtension private static $enable_utils_prev_next = false; /** - * @var array Allowed controller actions + * @var array Allowed controller actions */ private static $allowed_actions = [ 'doSaveAndClose', @@ -79,7 +80,8 @@ class ActionsGridFieldItemRequest extends DataExtension ]; /** - * @return array + * @param FieldList $actions + * @return array */ protected function getAvailableActions($actions) { @@ -116,6 +118,8 @@ public function updateEditForm(Form $form) * GridField_ItemRequest defines its own set of actions so we need to add ours * We add our custom save&close, save&next and other tweaks * Actions can be made readonly after this extension point + * @param FieldList $actions + * @return void */ public function updateFormActions($actions) { @@ -201,8 +205,10 @@ public function updateFormActions($actions) protected function processDropUpMenu($actions) { // The Drop-up container may already exist + /** @var ?Tab $dropUpContainer */ $dropUpContainer = $actions->fieldByName('ActionMenus.MoreOptions'); foreach ($actions as $action) { + //@phpstan-ignore-next-line if ($action->hasMethod('getDropUp') && $action->getDropUp()) { if (!$dropUpContainer) { $dropUpContainer = $this->createDropUpContainer($actions); @@ -271,6 +277,7 @@ public function moveCancelAndDelete(FieldList $actions, DataObject $record) } // Set custom title if ($record->hasMethod('getDeleteButtonTitle')) { + //@phpstan-ignore-next-line $deleteAction->setTitle($record->getDeleteButtonTitle()); } } @@ -286,6 +293,7 @@ public function moveCancelAndDelete(FieldList $actions, DataObject $record) } // Set custom titlte if ($record->hasMethod('getCancelButtonTitle')) { + //@phpstan-ignore-next-line $cancelButton->setTitle($record->getCancelButtonTitle()); } } @@ -299,6 +307,7 @@ public function getCustomPreviousRecordID(DataObject $record) { // This will overwrite state provided record if (self::config()->enable_custom_prevnext && $record->hasMethod('PrevRecord')) { + //@phpstan-ignore-next-line return $record->PrevRecord()->ID ?? 0; } return $this->owner->getPreviousRecordID(); @@ -313,11 +322,28 @@ public function getCustomNextRecordID(DataObject $record) // This will overwrite state provided record if (self::config()->enable_custom_prevnext && $record->hasMethod('NextRecord')) { + //@phpstan-ignore-next-line return $record->NextRecord()->ID ?? 0; } return $this->owner->getNextRecordID(); } + /** + * @param FieldList $actions + * @return CompositeField|FieldList + */ + protected function getMajorActions(FieldList $actions) + { + /** @var ?CompositeField $MajorActions */ + $MajorActions = $actions->fieldByName('MajorActions'); + + // If it doesn't exist, push to default group + if (!$MajorActions) { + $MajorActions = $actions; + } + return $MajorActions; + } + /** * @param FieldList $actions * @param DataObject $record @@ -329,12 +355,7 @@ public function addSaveNextAndPrevious(FieldList $actions, DataObject $record) return; } - $MajorActions = $actions->fieldByName('MajorActions'); - - // If it doesn't exist, push to default group - if (!$MajorActions) { - $MajorActions = $actions; - } + $MajorActions = $this->getMajorActions($actions); // TODO: state is having a hard time on post // @link https://github.com/silverstripe/silverstripe-framework/issues/10742 @@ -384,12 +405,7 @@ public function addSaveAndClose(FieldList $actions, DataObject $record) return; } - $MajorActions = $actions->fieldByName('MajorActions'); - - // If it doesn't exist, push to default group - if (!$MajorActions) { - $MajorActions = $actions; - } + $MajorActions = $this->getMajorActions($actions); if ($record->ID) { $label = _t('ActionsGridFieldItemRequest.SAVEANDCLOSE', 'Save and Close'); @@ -419,13 +435,12 @@ protected function getBtnClassForRecord(DataObject $record) if ($record->ID) { return 'btn-outline-primary'; } - return 'btn-primary'; } /** - * @param $action - * @param $definedActions + * @param string $action + * @param array|FieldList $definedActions * @return mixed|CompositeField|null */ protected static function findAction($action, $definedActions) @@ -443,6 +458,7 @@ protected static function findAction($action, $definedActions) $definedActionName = $definedAction->getName(); if ($definedAction->hasMethod('actionName')) { + //@phpstan-ignore-next-line $definedActionName = $definedAction->actionName(); } if ($definedActionName === $action) { @@ -460,7 +476,7 @@ protected static function findAction($action, $definedActions) * Action must be declared in getCMSActions to be called * * @param string $action - * @param array $data + * @param array $data * @param Form $form * @return HTTPResponse|DBHTMLText|string * @throws HTTPResponse_Exception @@ -480,6 +496,7 @@ protected function forwardActionToRecord($action, $data = [], $form = null) } elseif (!empty($data['ClassName']) && !empty($data['ID'])) { $record = DataObject::get_by_id($data['ClassName'], $data['ID']); } elseif ($controller->hasMethod("getRecord")) { + //@phpstan-ignore-next-line $record = $controller->getRecord(); } @@ -533,6 +550,7 @@ protected function forwardActionToRecord($action, $data = [], $form = null) $message = $result; } } catch (Exception $ex) { + $result = null; $error = true; $message = $ex->getMessage(); } @@ -551,11 +569,16 @@ protected function forwardActionToRecord($action, $data = [], $form = null) } // Progressive actions return array with json data + //@phpstan-ignore-next-line if (method_exists($clickedAction, 'getProgressive') && $clickedAction->getProgressive()) { $response = $controller->getResponse(); $response->addHeader('Content-Type', 'application/json'); if ($result) { - $response->setBody(json_encode($result)); + $encodedResult = json_encode($result); + if (!$encodedResult) { + $encodedResult = json_last_error_msg(); + } + $response->setBody($encodedResult); } return $response; @@ -572,6 +595,7 @@ protected function forwardActionToRecord($action, $data = [], $form = null) if (Director::is_ajax()) { $controller->getResponse()->addHeader('X-Status', rawurlencode($message)); + //@phpstan-ignore-next-line if (method_exists($clickedAction, 'getShouldRefresh') && $clickedAction->getShouldRefresh()) { $controller->getResponse()->addHeader('X-Reload', "true"); } @@ -582,6 +606,7 @@ protected function forwardActionToRecord($action, $data = [], $form = null) } else { // If the controller support sessionMessage, use it instead of form if ($controller->hasMethod('sessionMessage')) { + //@phpstan-ignore-next-line $controller->sessionMessage($message, $status, ValidationResult::CAST_HTML); } else { $form->sessionMessage($message, $status, ValidationResult::CAST_HTML); @@ -589,8 +614,10 @@ protected function forwardActionToRecord($action, $data = [], $form = null) } // Custom redirect + //@phpstan-ignore-next-line if (method_exists($clickedAction, 'getRedirectURL') && $clickedAction->getRedirectURL()) { $controller->getResponse()->addHeader('X-Reload', "true"); // we probably need a full ui refresh + //@phpstan-ignore-next-line return $controller->redirect($clickedAction->getRedirectURL()); } @@ -628,7 +655,7 @@ public function doCustomLink(HTTPRequest $request) * [doTestAction] => 1 * ) * - * @param array $data The form data + * @param array $data The form data * @param Form $form The form object * @return HTTPResponse|DBHTMLText|string * @throws Exception @@ -636,15 +663,15 @@ public function doCustomLink(HTTPRequest $request) public function doCustomAction($data, $form) { $action = key($data['action_doCustomAction']); - return $this->forwardActionToRecord($action, $data, $form); } /** * Saves the form and goes back to list view * - * @param array $data The form data + * @param array $data The form data * @param Form $form The form object + * @return HTTPResponse */ public function doSaveAndClose($data, $form) { @@ -666,8 +693,9 @@ public function doSaveAndClose($data, $form) /** * Saves the form and goes back to the next item * - * @param array $data The form data + * @param array $data The form data * @param Form $form The form object + * @return HTTPResponse */ public function doSaveAndNext($data, $form) { @@ -680,6 +708,10 @@ public function doSaveAndNext($data, $form) $class = get_class($record); $getNextRecordID = $data['_cmsactions']['next'][$class] ?? $this->getCustomNextRecordID($record); $class = get_class($record); + if (!$class) { + throw new Exception("Could not get class"); + } + /** @var ?DataObject $next */ $next = $class::get()->byID($getNextRecordID); $link = $this->owner->getEditLink($getNextRecordID); @@ -699,8 +731,9 @@ public function doSaveAndNext($data, $form) /** * Saves the form and goes to the previous item * - * @param array $data The form data + * @param array $data The form data * @param Form $form The form object + * @return HTTPResponse */ public function doSaveAndPrev($data, $form) { @@ -711,8 +744,13 @@ public function doSaveAndPrev($data, $form) $controller->getResponse()->addHeader("X-Pjax", "Content"); $class = get_class($record); - $getPreviousRecordID = $data['_cmsactions']['prev'][$class] ?? $this->getPreviousRecordID($record); + $getPreviousRecordID = $data['_cmsactions']['prev'][$class] ?? $this->getCustomPreviousRecordID($record); $class = get_class($record); + if (!$class) { + throw new Exception("Could not get class"); + } + + /** @var ?DataObject $prev */ $prev = $class::get()->byID($getPreviousRecordID); $link = $this->owner->getEditLink($getPreviousRecordID); @@ -729,6 +767,11 @@ public function doSaveAndPrev($data, $form) return $controller->redirect($link); } + /** + * @param string $url + * @param array $data + * @return string + */ protected function addGridState($url, $data) { // This should not be necessary at all if the state is correctly passed along @@ -766,6 +809,10 @@ protected function getToplevelController() return $controller; } + /** + * @param Controller $controller + * @return boolean + */ protected function isLeftAndMain($controller) { return is_subclass_of($controller, LeftAndMain::class); @@ -775,8 +822,6 @@ protected function isLeftAndMain($controller) * Gets the back link * * @return string - * @todo This had to be directly copied from {@link GridFieldDetailForm_ItemRequest} - * because it is a protected method and not visible to a decorator! */ public function getBackLink() { @@ -784,6 +829,7 @@ public function getBackLink() $toplevelController = $this->getToplevelController(); // Check for LeftAndMain and alike controllers with a Backlink or Breadcrumbs methods if ($toplevelController->hasMethod('Backlink')) { + //@phpstan-ignore-next-line $backlink = $toplevelController->Backlink(); } elseif ($this->owner->getController()->hasMethod('Breadcrumbs')) { $parents = $this->owner->getController()->Breadcrumbs(false)->items; @@ -827,6 +873,9 @@ protected function redirectAfterAction($isNewRecord, $record = null) // Changes to the record properties might've excluded the record from // a filtered list, so return back to the main view if it can't be found $noActionURL = $url = $controller->getRequest()->getURL(); + if (!$url) { + $url = ''; + } // The controller may not have these if ($controller->hasMethod('getAction')) { @@ -840,12 +889,13 @@ protected function redirectAfterAction($isNewRecord, $record = null) } } else { // Simple fallback (last index of) - $pos = strrpos($url ?? '', 'ItemEditForm'); - $noActionURL = substr($url ?? '', 0, $pos); + $pos = strrpos($url, 'ItemEditForm'); + if (is_int($pos)) { + $noActionURL = substr($url, 0, $pos); + } } $controller->getRequest()->addHeader('X-Pjax', 'Content'); - return $controller->redirect($noActionURL, 302); } } diff --git a/src/CmsInlineFormAction.php b/src/CmsInlineFormAction.php index 5db1a53..ff6859e 100644 --- a/src/CmsInlineFormAction.php +++ b/src/CmsInlineFormAction.php @@ -19,13 +19,13 @@ class CmsInlineFormAction extends LiteralField use ProgressiveAction; /** - * @var array + * @var array */ protected $params = []; /** - * @var string + * @var string|null */ protected $buttonIcon = null; @@ -50,9 +50,9 @@ class CmsInlineFormAction extends LiteralField /** * Create a new action button. - * @param action $action The method to call when the button is clicked - * @param title $title The label on the button - * @param extraClass $extraClass A CSS class to apply to the button in addition to 'action' + * @param string $action The method to call when the button is clicked + * @param string $title The label on the button + * @param string $extraClass A CSS class to apply to the button in addition to 'action' */ public function __construct($action, $title = "", $extraClass = 'btn-primary') { @@ -60,11 +60,17 @@ public function __construct($action, $title = "", $extraClass = 'btn-primary') $this->addExtraClass($extraClass); } + /** + * @return FormField + */ public function performReadonlyTransformation() { return $this->castedCopy(self::class); } + /** + * @return string + */ public function getLink() { if (!$this->link) { @@ -77,7 +83,7 @@ public function getLink() /** * Get an icon for this button * - * @return string + * @return string|null */ public function getButtonIcon() { @@ -89,13 +95,12 @@ public function getButtonIcon() * * Feel free to use SilverStripeIcons constants * - * @param string $buttonIcon An icon for this button + * @param string|null $buttonIcon An icon for this button * @return $this */ - public function setButtonIcon(string $buttonIcon) + public function setButtonIcon(string $buttonIcon = null) { $this->buttonIcon = $buttonIcon; - return $this; } @@ -108,7 +113,7 @@ public function Type() } /** - * @param $properties + * @param array $properties * @return FormField|string */ public function FieldHolder($properties = []) @@ -158,7 +163,7 @@ public function FieldHolder($properties = []) /** * Get the value of params * - * @return array + * @return array */ public function getParams() { @@ -168,8 +173,7 @@ public function getParams() /** * Set the value of params * - * @param array $params - * + * @param array $params * @return $this */ public function setParams(array $params) @@ -214,8 +218,6 @@ public function getSubmitSelector() /** * Set the value of {@see self::$submitSelector} * - * Includes - * * @param string $selector * @return $this */ diff --git a/src/CustomAction.php b/src/CustomAction.php index be7b437..8933475 100644 --- a/src/CustomAction.php +++ b/src/CustomAction.php @@ -4,6 +4,7 @@ use SilverStripe\Core\Convert; use SilverStripe\Forms\FormAction; +use SilverStripe\ORM\FieldType\DBHTMLText; /** * Custom actions to use in getCMSActions @@ -51,9 +52,16 @@ public function Type() return 'action'; } + /** + * @param array $properties + * @return DBHTMLText + */ public function Field($properties = []) { - $icon = $this->buttonIcon ?? $this->icon; + $icon = $this->buttonIcon; + if (!$icon) { + $icon = $this->icon; + } if ($icon) { $this->addExtraClass('font-icon'); $this->addExtraClass('font-icon-' . $icon); diff --git a/src/CustomButton.php b/src/CustomButton.php index 9b5be8d..d79bf61 100644 --- a/src/CustomButton.php +++ b/src/CustomButton.php @@ -26,7 +26,7 @@ trait CustomButton /** * An icon for this button - * @var string + * @var string|null */ protected $buttonIcon; diff --git a/src/CustomGridField_FormAction.php b/src/CustomGridField_FormAction.php index ceef3bc..8a808a7 100644 --- a/src/CustomGridField_FormAction.php +++ b/src/CustomGridField_FormAction.php @@ -8,12 +8,14 @@ class CustomGridField_FormAction extends GridField_FormAction { use ProgressiveAction; + /** + * @return string + */ public function Type() { if ($this->progressive) { return 'progressive-action'; } - return 'action'; } } diff --git a/src/CustomLink.php b/src/CustomLink.php index 54618fc..8c98c40 100644 --- a/src/CustomLink.php +++ b/src/CustomLink.php @@ -25,7 +25,7 @@ class CustomLink extends LiteralField /** * @param string $name * @param string $title - * @param string|array $link Will default to name of link on current record if not set + * @param string|array $link Will default to name of link on current record if not set */ public function __construct($name, $title = null, $link = null) { @@ -41,6 +41,7 @@ public function __construct($name, $title = null, $link = null) if ($link && is_string($link)) { $this->link = $link; } else { + //@phpstan-ignore-next-line $this->link = $this->getModelLink($name, $link); } } @@ -58,7 +59,7 @@ public function Type() } /** - * @param array $properties + * @param array $properties * @return FormField|string */ public function FieldHolder($properties = []) @@ -84,7 +85,9 @@ public function FieldHolder($properties = []) $attrs[] = 'target="_blank"'; } if ($this->confirmation) { - $attrs[] = sprintf('data-message="%s"', Convert::raw2htmlatt($this->confirmation)); + /** @var string $att */ + $att = Convert::raw2htmlatt($this->confirmation); + $attrs[] = sprintf('data-message="%s"', $att); if ($this->progressive) { $classes[] = "confirm"; } else { diff --git a/src/DefaultLink.php b/src/DefaultLink.php index c51bc96..6066eea 100644 --- a/src/DefaultLink.php +++ b/src/DefaultLink.php @@ -28,7 +28,7 @@ trait DefaultLink * If you want to call actions on the controller (ModelAdmin), use getControllerLink * * @param string $action - * @param array $params + * @param array|null $params * @return string */ public function getModelLink($action, array $params = null) diff --git a/src/GridFieldRowButton.php b/src/GridFieldRowButton.php index ed2c071..807e429 100644 --- a/src/GridFieldRowButton.php +++ b/src/GridFieldRowButton.php @@ -80,9 +80,9 @@ abstract public function getButtonLabel(GridField $gridField, $record, $columnNa /** * @param GridField $gridField - * @param $actionName - * @param $arguments - * @param $data + * @param string $actionName + * @param array $arguments + * @param array $data * @return mixed */ abstract public function doHandle(GridField $gridField, $actionName, $arguments, $data); @@ -100,7 +100,8 @@ public function getActionName() /** * @param GridField $gridField - * @param array $columns + * @param array $columns + * @return void */ public function augmentColumns($gridField, &$columns) { @@ -115,7 +116,7 @@ public function augmentColumns($gridField, &$columns) * @param GridField $gridField * @param DataObject $record * @param string $columnName - * @return array + * @return array */ public function getColumnAttributes($gridField, $record, $columnName) { @@ -128,7 +129,7 @@ public function getColumnAttributes($gridField, $record, $columnName) * * @param GridField $gridField * @param string $columnName - * @return array + * @return array */ public function getColumnMetadata($gridField, $columnName) { @@ -144,7 +145,7 @@ public function getColumnMetadata($gridField, $columnName) * Which columns are handled by this component * * @param GridField $gridField - * @return array + * @return array */ public function getColumnsHandled($gridField) { @@ -155,7 +156,7 @@ public function getColumnsHandled($gridField) * Which GridField actions are this component handling * * @param GridField $gridField - * @return array + * @return array */ public function getActions($gridField) { @@ -208,7 +209,7 @@ public function getColumnContent($gridField, $record, $columnName) * @param GridField $gridField * @param string $actionName * @param mixed $arguments - * @param array $data - form data + * @param array $data - form data * @return HTTPResponse|void */ public function handleAction(GridField $gridField, $actionName, $arguments, $data) diff --git a/src/GridFieldRowLink.php b/src/GridFieldRowLink.php index 7d421a1..43da7a4 100644 --- a/src/GridFieldRowLink.php +++ b/src/GridFieldRowLink.php @@ -19,7 +19,7 @@ class GridFieldRowLink implements GridField_ColumnProvider /** * HTML classes to be added to GridField buttons * - * @var string[] + * @var array */ protected $extraClass = [ 'grid-field__icon-action--hidden-on-hover' => true, @@ -57,7 +57,8 @@ public function __construct($name, $title, $icon = 'white-question') * Add a column 'Actions' * * @param GridField $gridField - * @param array $columns + * @param array $columns + * @return void */ public function augmentColumns($gridField, &$columns) { @@ -72,7 +73,7 @@ public function augmentColumns($gridField, &$columns) * @param GridField $gridField * @param DataObject $record * @param string $columnName - * @return array + * @return array */ public function getColumnAttributes($gridField, $record, $columnName) { @@ -84,7 +85,7 @@ public function getColumnAttributes($gridField, $record, $columnName) * * @param GridField $gridField * @param string $columnName - * @return array + * @return array */ public function getColumnMetadata($gridField, $columnName) { @@ -99,7 +100,7 @@ public function getColumnMetadata($gridField, $columnName) * Which columns are handled by this component * * @param GridField $gridField - * @return array + * @return array */ public function getColumnsHandled($gridField) { @@ -131,10 +132,11 @@ public function getColumnContent($gridField, $record, $columnName) $data = new ArrayData( [ - 'Link' => $this->getLink($gridField, $record, $columnName), - 'ExtraClass' => $this->getExtraClass(), - 'Title' => $this->title, - 'NewWindow' => $this->newWindow] + 'Link' => $this->getLink($gridField, $record, $columnName), + 'ExtraClass' => $this->getExtraClass(), + 'Title' => $this->title, + 'NewWindow' => $this->newWindow + ] ); $template = SSViewer::get_templates_by_class($this, '', __CLASS__); @@ -229,6 +231,7 @@ public function setTitle(string $title) /** * Get the value of newWindow + * @return bool */ public function getNewWindow() { @@ -238,12 +241,12 @@ public function getNewWindow() /** * Set the value of newWindow * + * @param bool $newWindow * @return $this */ public function setNewWindow($newWindow) { $this->newWindow = $newWindow; - return $this; } } diff --git a/src/GridFieldTableButton.php b/src/GridFieldTableButton.php index 43486e6..9884095 100644 --- a/src/GridFieldTableButton.php +++ b/src/GridFieldTableButton.php @@ -46,7 +46,7 @@ abstract class GridFieldTableButton implements GridField_HTMLProvider, GridField protected $fontIcon; /** - * @var string + * @var int */ protected $parentID; @@ -66,7 +66,7 @@ abstract class GridFieldTableButton implements GridField_HTMLProvider, GridField protected $promptDefault; /** - * @var array + * @var array */ protected $attributes = []; @@ -82,6 +82,9 @@ public function __construct($targetFragment = "buttons-before-right", $buttonLab } } + /** + * @return string + */ public function getActionName() { $class = (new ReflectionClass(get_called_class()))->getShortName(); @@ -90,6 +93,9 @@ public function getActionName() return strtolower(str_replace('Button', '', $class)); } + /** + * @return string + */ public function getButtonLabel() { return $this->buttonLabel; @@ -97,6 +103,7 @@ public function getButtonLabel() /** * Place the export button in a

tag below the field + * @return array */ public function getHTMLFragments($gridField) { @@ -107,7 +114,7 @@ public function getHTMLFragments($gridField) $action, $this->getButtonLabel(), $action, - null + [] ); $button->addExtraClass('btn btn-secondary action_' . $action); if ($this->noAjax) { @@ -161,7 +168,7 @@ public function getAttribute($name) /** * @param $gridField - * @return array + * @return array */ public function getActions($gridField) { @@ -170,10 +177,10 @@ public function getActions($gridField) /** * @param GridField $gridField - * @param $actionName - * @param $arguments - * @param $data - * @return array|\SilverStripe\Control\HTTPResponse|void + * @param string $actionName + * @param array $arguments + * @param array $data + * @return array|\SilverStripe\Control\HTTPResponse|void */ public function handleAction(GridField $gridField, $actionName, $arguments, $data) { @@ -203,7 +210,11 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat if ($this->progressive) { $response = $controller->getResponse(); $response->addHeader('Content-Type', 'application/json'); - $response->setBody(json_encode($result)); + $encodedResult = json_encode($result); + if ($encodedResult === false) { + $encodedResult = json_last_error_msg(); + } + $response->setBody($encodedResult); return $response; } @@ -231,6 +242,7 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat /** * it is also a URL + * @return array */ public function getURLHandlers($gridField) { diff --git a/src/GridFieldTableLink.php b/src/GridFieldTableLink.php index 4e613e8..0735581 100644 --- a/src/GridFieldTableLink.php +++ b/src/GridFieldTableLink.php @@ -3,6 +3,7 @@ namespace LeKoala\CmsActions; use ReflectionClass; +use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridField_HTMLProvider; /** @@ -34,7 +35,7 @@ class GridFieldTableLink implements GridField_HTMLProvider protected $fontIcon; /** - * @var string + * @var int */ protected $parentID; @@ -54,7 +55,7 @@ class GridFieldTableLink implements GridField_HTMLProvider protected $promptDefault; /** - * @var array + * @var array */ protected $attributes = []; @@ -66,6 +67,7 @@ class GridFieldTableLink implements GridField_HTMLProvider /** * @param string $targetFragment The HTML fragment to write the button into * @param string $buttonLabel + * @param string $actionName */ public function __construct($targetFragment = "buttons-before-right", $buttonLabel = null, $actionName = null) { @@ -102,6 +104,8 @@ public function getButtonLabel() /** * Place the export button in a

tag below the field + * @param GridField $gridField + * @return array */ public function getHTMLFragments($gridField) { @@ -157,7 +161,7 @@ public function setAttribute($name, $value) /** * @param string $name - * @return string + * @return string|null */ public function getAttribute($name) { @@ -168,6 +172,10 @@ public function getAttribute($name) return null; } + /** + * @param GridField $gridField + * @return array + */ public function getActions($gridField) { return [$this->getActionName()];