|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DMSDocumentAddExistingField extends CompositeField |
|
4
|
|
|
{ |
|
5
|
|
|
public $useFieldContext = true; |
|
6
|
|
|
|
|
7
|
|
|
public function __construct($name, $title = null) |
|
8
|
|
|
{ |
|
9
|
|
|
$this->name = $name; |
|
10
|
|
|
$this->title = ($title === null) ? $name : $title; |
|
11
|
|
|
|
|
12
|
|
|
parent::__construct( |
|
13
|
|
|
new TreeDropdownField( |
|
14
|
|
|
'PageSelector', |
|
15
|
|
|
'Add from another page', |
|
16
|
|
|
'SiteTree', |
|
17
|
|
|
'ID', |
|
18
|
|
|
'TitleWithNumberOfDocuments' |
|
19
|
|
|
) |
|
20
|
|
|
); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File) |
|
25
|
|
|
* @param DataObject $record |
|
26
|
|
|
*/ |
|
27
|
|
|
public function setRecord($record) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->record = $record; |
|
|
|
|
|
|
30
|
|
|
return $this; |
|
31
|
|
|
} |
|
32
|
|
|
/** |
|
33
|
|
|
* Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it |
|
34
|
|
|
* will use Form->getRecord() or Form->Controller()->data() |
|
35
|
|
|
* @return DataObject |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getRecord() |
|
38
|
|
|
{ |
|
39
|
|
|
if (!$this->record && $this->form) { |
|
|
|
|
|
|
40
|
|
|
if ($this->form->getRecord() && is_a($this->form->getRecord(), 'DataObject')) { |
|
41
|
|
|
$this->record = $this->form->getRecord(); |
|
|
|
|
|
|
42
|
|
|
} elseif ($this->form->Controller() && $this->form->Controller()->hasMethod('data') |
|
|
|
|
|
|
43
|
|
|
&& $this->form->Controller()->data() && is_a($this->form->Controller()->data(), 'DataObject')) { |
|
|
|
|
|
|
44
|
|
|
$this->record = $this->form->Controller()->data(); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
return $this->record; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function FieldHolder($properties = array()) |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->Field($properties); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function Field($properties = array()) |
|
56
|
|
|
{ |
|
57
|
|
|
Requirements::javascript(DMS_DIR . '/javascript/DMSDocumentAddExistingField.js'); |
|
58
|
|
|
Requirements::javascript(DMS_DIR . '/javascript/DocumentHtmlEditorFieldToolbar.js'); |
|
59
|
|
|
Requirements::css(DMS_DIR . '/dist/css/cmsbundle.css'); |
|
60
|
|
|
|
|
61
|
|
|
return $this->renderWith('DMSDocumentAddExistingField'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Sets or unsets the use of the "field" class in the template. The "field" class adds Javascript behaviour |
|
66
|
|
|
* that causes unwelcome hiding side-effects when this Field is used within the link editor pop-up |
|
67
|
|
|
* |
|
68
|
|
|
* @return $this |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setUseFieldClass($use = false) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->useFieldContext = $use; |
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.