2017-05-03 03:26:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class DMSGridFieldAddNewButton extends GridFieldAddNewButton implements GridField_HTMLProvider
|
|
|
|
{
|
|
|
|
/**
|
2017-05-02 04:49:41 +02:00
|
|
|
* The document set ID that the document should be attached to
|
2017-05-03 03:26:17 +02:00
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2017-05-02 04:49:41 +02:00
|
|
|
protected $documentSetId;
|
2017-05-03 03:26:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Overriding the parent method to change the template that the DMS add button will be rendered with
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getHTMLFragments($gridField)
|
|
|
|
{
|
|
|
|
$singleton = singleton($gridField->getModelClass());
|
|
|
|
|
|
|
|
if (!$singleton->canCreate()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->buttonName) {
|
|
|
|
// provide a default button name, can be changed by calling {@link setButtonName()} on this component
|
|
|
|
$objectName = $singleton->i18n_singular_name();
|
|
|
|
$this->buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
|
|
|
|
}
|
|
|
|
|
|
|
|
$link = singleton('DMSDocumentAddController')->Link();
|
2017-05-02 04:49:41 +02:00
|
|
|
if ($this->getDocumentSetId()) {
|
|
|
|
$link = Controller::join_links($link, '?dsid=' . $this->getDocumentSetId());
|
2017-05-03 03:26:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$data = new ArrayData(array(
|
|
|
|
'NewLink' => $link,
|
|
|
|
'ButtonName' => $this->buttonName,
|
|
|
|
));
|
|
|
|
|
|
|
|
return array(
|
|
|
|
$this->targetFragment => $data->renderWith('DMSGridFieldAddNewButton'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-02 04:49:41 +02:00
|
|
|
* Set the document set ID that this document should be attached to
|
2017-05-03 03:26:17 +02:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return $this
|
|
|
|
*/
|
2017-05-02 04:49:41 +02:00
|
|
|
public function setDocumentSetId($id)
|
2017-05-03 03:26:17 +02:00
|
|
|
{
|
2017-05-02 04:49:41 +02:00
|
|
|
$this->documentSetId = $id;
|
2017-05-03 03:26:17 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-02 04:49:41 +02:00
|
|
|
* Get the document set ID that this document should be attached to
|
2017-05-03 03:26:17 +02:00
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2017-05-02 04:49:41 +02:00
|
|
|
public function getDocumentSetId()
|
2017-05-03 03:26:17 +02:00
|
|
|
{
|
2017-05-02 04:49:41 +02:00
|
|
|
return $this->documentSetId;
|
2017-05-03 03:26:17 +02:00
|
|
|
}
|
|
|
|
}
|