From 0e029a303370ac241f88f9f633aa2e8d79d5870c Mon Sep 17 00:00:00 2001 From: Andrew Aitken-Fincham Date: Wed, 14 Mar 2018 15:18:18 +0000 Subject: [PATCH] sanitise classname on addmulticlass handler --- code/GridFieldAddNewMultiClassHandler.php | 35 ++++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/code/GridFieldAddNewMultiClassHandler.php b/code/GridFieldAddNewMultiClassHandler.php index cf99b5b..4fc61ed 100644 --- a/code/GridFieldAddNewMultiClassHandler.php +++ b/code/GridFieldAddNewMultiClassHandler.php @@ -2,16 +2,31 @@ /** * A custom grid field request handler that allows interacting with form fields when adding records. */ -class GridFieldAddNewMultiClassHandler extends GridFieldDetailForm_ItemRequest { +class GridFieldAddNewMultiClassHandler extends GridFieldDetailForm_ItemRequest +{ + public function Link($action = null) + { + if ($this->record->ID) { + return parent::Link($action); + } - public function Link($action = null) { - if($this->record->ID) { - return parent::Link($action); - } else { - return Controller::join_links( - $this->gridField->Link(), 'add-multi-class', get_class($this->record) - ); - } - } + return Controller::join_links( + $this->gridField->Link(), + 'add-multi-class', + $this->sanitiseClassName(get_class($this->record)) + ); + } + /** + * Sanitise a model class' name for inclusion in a link. + * + * @param mixed $class + * + * @return string + */ + protected function sanitiseClassName($class) + { + return str_replace('\\', '-', $class); + } } +