|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This class does load the information from the parent page in the SiteTree. |
|
5
|
|
|
* |
|
6
|
|
|
* If you are keen to avoid extensions (to save resources) please see the end of this file for the method to copy into |
|
7
|
|
|
* your Page.php |
|
8
|
|
|
*/ |
|
9
|
|
|
class InheritageBySiteTreeExtension extends Extension |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Does nothing else than just calling the parent, if exists, and returning $dbField or calling itself again. |
|
13
|
|
|
* |
|
14
|
|
|
* @throws Exception |
|
15
|
|
|
* @param string $dbField |
|
16
|
|
|
* @return null|string|DataList |
|
17
|
|
|
*/ |
|
18
|
|
|
public function getFromParentPage($dbField) |
|
19
|
|
|
{ |
|
20
|
|
|
if (!is_string($dbField)) { |
|
21
|
|
|
throw new Exception('You can only give strings to getFromParentPage'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
$result = null; |
|
25
|
|
|
|
|
26
|
|
|
// if this isn't the top level page... |
|
27
|
|
|
$parentPage = $this->owner->Parent(); |
|
|
|
|
|
|
28
|
|
|
if ($parentPage) { |
|
29
|
|
|
// ... check if it has this field... |
|
30
|
|
|
if ($parentPage->hasField($dbField)) { |
|
31
|
|
|
$result = $parentPage->$dbField; |
|
32
|
|
|
} else if (get_class($parentPage) != 'SiteTree') { |
|
33
|
|
|
// ... if not call its parent. |
|
34
|
|
|
$result = $parentPage->getFromParentPage($dbField); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return $result; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Does nothing else than just calling the parent, if exists, and returning $dbField or calling itself again. |
|
45
|
|
|
* |
|
46
|
|
|
* @see https://www.github.com/bringyourownideas/inheritage-by-sitetree |
|
47
|
|
|
* |
|
48
|
|
|
* @throws Exception |
|
49
|
|
|
* @param string $dbField |
|
50
|
|
|
* @return null|string|DataList |
|
51
|
|
|
*/ |
|
52
|
|
|
/* |
|
53
|
|
|
public function getFromParentPage($dbField) |
|
54
|
|
|
{ |
|
55
|
|
|
if (!is_string($dbField)) { |
|
56
|
|
|
throw new Exception('You can only give strings to getFromParentPage'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$result = null; |
|
60
|
|
|
|
|
61
|
|
|
// if this isn't the top level page... |
|
62
|
|
|
$parentPage = $this->Parent(); |
|
63
|
|
|
if ($parentPage) { |
|
64
|
|
|
// ... check if it has this field... |
|
65
|
|
|
if ($parentPage->hasField($dbField)) { |
|
66
|
|
|
$result = $parentPage->$dbField; |
|
67
|
|
|
} else { |
|
68
|
|
|
// ... if not call its parent. |
|
69
|
|
|
$result = $parentPage->getFromParentPage($dbField); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $result; |
|
74
|
|
|
} |
|
75
|
|
|
*/ |
|
76
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.