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
|
|
|
class GridFieldAddNewButtonOriginalPageSecondHandProduct extends GridFieldAddNewButtonOriginalPage |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
public function getHTMLFragments($gridField) |
16
|
|
|
{ |
17
|
|
|
$singleton = singleton($gridField->getModelClass()); |
18
|
|
|
|
19
|
|
|
if (! $singleton->canCreate()) { |
20
|
|
|
return array(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
if (!$this->buttonName) { |
24
|
|
|
// provide a default button name, can be changed by calling {@link setButtonName()} on this component |
25
|
|
|
$objectName = $singleton->i18n_singular_name(); |
26
|
|
|
$this->buttonName = _t('GridField.Add_USING_PAGES_SECTION', 'Add {name}', array('name' => $objectName)); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$getSegment = ''; |
30
|
|
|
if ($page = $this->BestRootParentPage()) { |
31
|
|
|
$getSegment = '?ParentID='.$page->ID; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$data = new ArrayData(array( |
35
|
|
|
'NewLink' => '/admin/'.Config::inst()->get('CMSPageAddController_SecondHandProducts', 'url_segment').'/'.$getSegment, |
36
|
|
|
'ButtonName' => $this->buttonName, |
37
|
|
|
)); |
38
|
|
|
|
39
|
|
|
return array( |
40
|
|
|
$this->targetFragment => $data->renderWith('GridFieldAddNewbutton'), |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* finds the most likely root parent for the shop. |
46
|
|
|
* |
47
|
|
|
* @return SiteTree | NULL |
48
|
|
|
*/ |
49
|
|
|
public function BestRootParentPage() |
50
|
|
|
{ |
51
|
|
|
$singleton = Injector::inst()->get('SecondHandProductGroup'); |
52
|
|
|
|
53
|
|
|
return $singleton->BestRootParentPage(); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
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.