|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Creates links through for |
|
5
|
|
|
* |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class CMSTricks extends Object |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
private static $excluded_has_one_classes = array("Image", "File"); |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
private static $completion_array = array(); |
|
13
|
|
|
|
|
14
|
|
|
private static $tab_name_for_link = "Root.Links"; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
private static $tab_name_for_calc = "Root.Main"; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
private static $excluded_casted_variables = array("Title", "CSSClasses"); |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
public static function add_links_to_fields($obj, $fields) |
|
21
|
|
|
{ |
|
22
|
|
|
if (!isset(self::$completion_array[$obj->ClassName])) { |
|
23
|
|
|
self::$completion_array[$obj->ClassName] = true; |
|
24
|
|
|
if ($obj->exists()) { |
|
25
|
|
|
$fieldLabels = array_merge($obj->FieldLabels(), (array)$obj->Config()->get("field_labels")); |
|
26
|
|
|
$hasOneLinks = $obj->Config()->get("has_one"); |
|
27
|
|
|
if (is_array($hasOneLinks) && count($hasOneLinks)) { |
|
28
|
|
|
$linkTabName = Config::inst()->get("CMSTricks", "tab_name_for_link"); |
|
29
|
|
|
$fields->addFieldToTab($linkTabName, new LiteralField("YouAreLookingAt", '<h2>This objects links to ...</h2>')); |
|
30
|
|
|
foreach ($hasOneLinks as $methodName => $className) { |
|
31
|
|
|
$dbFieldName = $methodName."ID"; |
|
32
|
|
|
$label = isset($fieldLabels[$methodName]) ? $fieldLabels[$methodName] : null; |
|
33
|
|
|
if ($obj->$dbFieldName && $relationObject = $obj->$methodName()) { |
|
34
|
|
|
if (!in_array($relationObject->ClassName, Config::inst()->get("CMSTricks", "excluded_has_one_classes"))) { |
|
35
|
|
|
$fields->addFieldToTab( |
|
36
|
|
|
$linkTabName, |
|
37
|
|
|
new LiteralField( |
|
38
|
|
|
"LinkThroughFor".$relationObject->ClassName.$relationObject->ID, |
|
39
|
|
|
'<h3><a href="'.$relationObject->CMSEditLink().'" target="_blank">open related '.$label.'</a></h3>' |
|
40
|
|
|
) |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
$castedVariables = $obj->Config()->get("casting"); |
|
47
|
|
|
if (is_array($castedVariables) && count($castedVariables)) { |
|
48
|
|
|
$calcTabName = Config::inst()->get("CMSTricks", "tab_name_for_calc"); |
|
49
|
|
|
$fields->addFieldToTab($calcTabName, new LiteralField("CalculatedValues", '<h2>Calculated Values ...</h2>')); |
|
50
|
|
|
foreach ($castedVariables as $castedVariableName => $castedVariableType) { |
|
51
|
|
|
if (!in_array($castedVariableName, Config::inst()->get("CMSTricks", "excluded_casted_variables"))) { |
|
52
|
|
|
$label = isset($fieldLabels[$castedVariableName]) ? $fieldLabels[$castedVariableName] : null; |
|
53
|
|
|
$fields->addFieldToTab( |
|
54
|
|
|
$calcTabName, |
|
55
|
|
|
new ReadonlyField( |
|
56
|
|
|
$castedVariableName, |
|
57
|
|
|
$label |
|
58
|
|
|
) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
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.