forked from TimOetting/kirby-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.php
69 lines (55 loc) · 1.71 KB
/
builder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
use Kirby\Panel\Models\Page\Blueprint\Field;
class BuilderField extends StructureField {
static public $assets = array(
'js' => array(
'builder.js'
),
'css' => array(
'builder.css'
)
);
public function fieldset($fieldsetName) {
return new Field($this->fieldsets[$fieldsetName], $this->page());
}
public function modalsize() {
$sizes = array('small', 'medium', 'large', 'extralarge');
return in_array($this->modalsize, $sizes) ? $this->modalsize : 'large';
}
public function entry($data) {
if(isset($data->_fieldset))
$fieldsetName = $data->_fieldset;
else
return "No fieldset found in entry.";
if(isset($this->fieldsets[$fieldsetName])) {
$fieldset = $this->fieldset($fieldsetName);
$this->snippet = $fieldset->snippet();
$this->entry = $fieldset->entry();
$this->fields = $fieldset->fields();
} else
return 'No fieldset with name "'. $fieldsetName . '" found.';
$data->_fileUrl = $this->page->contentUrl() . DS;
if ($this->snippet){
$data = structure((array) $data, $this->page());
return tpl::load(c::get( 'buildersnippets.path', kirby()->roots()->snippets() ) . DS . $this->snippet . '.php', array(
'page' => $this->page(),
'data' => $data,
));
} else {
return parent::entry($data);
}
}
public function headline() {
$label = BaseField::label();
return $label;
}
public function style() {
return 'items';
}
public function content() {
return tpl::load(__DIR__ . DS . 'template.php', array('field' => $this));
}
public function url($action) {
return purl($this->model(), 'field/' . $this->name() . '/builder/' . $action);
}
}