2013-02-02 04:14:59 +01:00
|
|
|
<?php
|
2016-09-09 09:00:05 +02:00
|
|
|
|
2017-06-16 06:07:09 +02:00
|
|
|
namespace Symbiote\GridFieldExtensions;
|
2016-11-29 18:20:15 +01:00
|
|
|
|
2016-09-09 09:00:05 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
|
|
|
|
2013-02-02 04:14:59 +01:00
|
|
|
/**
|
|
|
|
* A custom grid field request handler that allows interacting with form fields when adding records.
|
|
|
|
*/
|
2016-12-21 03:34:58 +01:00
|
|
|
class GridFieldAddNewMultiClassHandler extends GridFieldDetailForm_ItemRequest
|
|
|
|
{
|
2013-02-02 04:14:59 +01:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
public function Link($action = null)
|
|
|
|
{
|
|
|
|
if ($this->record->ID) {
|
|
|
|
return parent::Link($action);
|
|
|
|
} else {
|
|
|
|
return Controller::join_links(
|
|
|
|
$this->gridField->Link(),
|
|
|
|
'add-multi-class',
|
2017-07-06 07:27:07 +02:00
|
|
|
$this->sanitiseClassName(get_class($this->record))
|
2016-12-21 03:34:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 07:27:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sanitise a model class' name for inclusion in a link
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function sanitiseClassName($class)
|
|
|
|
{
|
|
|
|
return str_replace('\\', '-', $class);
|
|
|
|
}
|
2013-02-02 04:14:59 +01:00
|
|
|
}
|