1 | <?php |
||
10 | class RootFolder extends DataExtension |
||
|
|||
11 | { |
||
12 | private static $has_one = array( |
||
13 | 'RootFolder' => 'Folder', |
||
14 | ); |
||
15 | |||
16 | /** |
||
17 | * @var array exclude this page types and class names |
||
18 | */ |
||
19 | private static $ignored_classes = array('VirtualPage', 'ErrorPage'); |
||
20 | |||
21 | /** |
||
22 | * @var bool should folders be created for translated objects? |
||
23 | */ |
||
24 | private static $create_folder_for_translations = false; |
||
25 | |||
26 | /** |
||
27 | * @var string default root for all folders; may be overwritten in config of decorated class |
||
28 | */ |
||
29 | private static $folder_root = 'Articles'; |
||
30 | |||
31 | /** |
||
32 | * create folder and set relation |
||
33 | */ |
||
34 | public function onBeforeWrite() |
||
38 | |||
39 | /** |
||
40 | * check updates and rename folder if needed |
||
41 | */ |
||
42 | public function onAfterWrite() |
||
46 | |||
47 | /** |
||
48 | * reset $RootFolderID on a duplicated page |
||
49 | */ |
||
50 | public function onBeforeDuplicate($originalOrClone) |
||
56 | |||
57 | /** |
||
58 | * Creates a folder for a page as a subfolder of the parent page |
||
59 | * You can exclude page types by setting $ignored_classes in config |
||
60 | * |
||
61 | * Doesn't create folders for translated pages by default. |
||
62 | * |
||
63 | * @TODO doesn't check if page is moved to another parent |
||
64 | */ |
||
65 | public function checkFolder() |
||
88 | |||
89 | /** |
||
90 | * Does the work of creating a new RootFolder, saves the relation in the extended DataObject |
||
91 | */ |
||
92 | protected function createRootFolder() |
||
116 | |||
117 | /** |
||
118 | * Does the work of updating the folder if the URLSegment or ParentID is changed. |
||
119 | * if both it does two writes... |
||
120 | * |
||
121 | * @todo: rethink moving subfolders as it may timeout on real large trees |
||
122 | */ |
||
123 | protected function updateRootFolder() |
||
140 | |||
141 | /** |
||
142 | * Returns the folder root for the current root folder, e.g. 'Articles', |
||
143 | * if a config $folder_root is defined in the decorated class. |
||
144 | * |
||
145 | * Falls back to global config |
||
146 | */ |
||
147 | public function getFolderRoot() |
||
153 | |||
154 | |||
155 | /** |
||
156 | * Helper function to return the name of the RootFolder for setting in @link UploadField or @link GridFieldBulkUpload |
||
157 | * By default relative to /assets/ |
||
158 | * |
||
159 | * @param bool $relativeToAssetsDir |
||
160 | */ |
||
161 | public function getRootFolderName($relativeToAssetsDir = true) |
||
172 | |||
173 | /** |
||
174 | * code taken from SiteTree::onBeforeWrite() |
||
175 | * |
||
176 | * we need $URLSegment already created and checked before there |
||
177 | * |
||
178 | * @return mixed |
||
179 | */ |
||
180 | private function getOrCreateURLSegment() |
||
207 | } |
||
208 | |||
209 |
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.