1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Provides the entry point to editing a single record presented by the |
5
|
|
|
* {@link GridField}. |
6
|
|
|
* |
7
|
|
|
* Doesn't show an edit view on its own or modifies the record, but rather |
8
|
|
|
* relies on routing conventions established in {@link getColumnContent()}. |
9
|
|
|
* |
10
|
|
|
* The default routing applies to the {@link GridFieldDetailForm} component, |
11
|
|
|
* which has to be added separately to the {@link GridField} configuration. |
12
|
|
|
* |
13
|
|
|
* @package forms |
14
|
|
|
* @subpackage fields-gridfield |
15
|
|
|
*/ |
16
|
|
|
class GridFieldAddNewButtonOriginalPage extends GridFieldAddNewButton |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
public function getHTMLFragments($gridField) |
19
|
|
|
{ |
20
|
|
|
$singleton = singleton($gridField->getModelClass()); |
21
|
|
|
|
22
|
|
|
if (!$singleton->canCreate()) { |
23
|
|
|
return array(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
if (!$this->buttonName) { |
27
|
|
|
// provide a default button name, can be changed by calling {@link setButtonName()} on this component |
28
|
|
|
$objectName = $singleton->i18n_singular_name(); |
29
|
|
|
$this->buttonName = _t('GridField.Add_USING_PAGES_SECTION', 'Add {name} using pages section', array('name' => $objectName)); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$getSegment = ""; |
33
|
|
|
if ($page = $this->BestParentPage()) { |
34
|
|
|
$getSegment = "?ParentID=".$page->ID; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$data = new ArrayData(array( |
38
|
|
|
'NewLink' => "/admin/".Config::inst()->get("CMSPageAddController_Products", "url_segment")."/".$getSegment, |
39
|
|
|
'ButtonName' => $this->buttonName, |
40
|
|
|
)); |
41
|
|
|
|
42
|
|
|
return array( |
43
|
|
|
$this->targetFragment => $data->renderWith('GridFieldAddNewbutton'), |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* finds the most likely root parent for the shop |
50
|
|
|
* |
51
|
|
|
* @return SiteTree | NULL |
52
|
|
|
*/ |
53
|
|
|
public function BestParentPage() |
54
|
|
|
{ |
55
|
|
|
return SiteTree::get()->filter("ParentID", 0)->First(); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.