-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldtypeFieldsetPanelOpen.module.php
87 lines (74 loc) · 2.63 KB
/
FieldtypeFieldsetPanelOpen.module.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php namespace ProcessWire;
require_once(wire('config')->paths->modules . "Fieldtype/FieldtypeFieldsetOpen.module");
class InputfieldFieldsetPanelOpen extends InputfieldFieldsetOpen
{
public function __construct()
{
parent::__construct();
$this->set('skipLabel', Inputfield::skipLabelHeader);
$this->set('collapsed', Inputfield::collapsedNever);
}
public function ___render()
{
foreach ($this->children as $c) {
$c->collapsed = Inputfield::collapsedHidden;
}
$editUrl = $this->getEditURL();
if($this->icon){
$icon = "<span class='fa fa-{$this->icon}'></span>";
}
return "<div class=''> <a class='pw-panel' href='$editUrl'>{$icon} {$this->label}</a></div>";
}
public function ___getEditUrl()
{
$page = $this->hasPage;
$process_edit = $this->page;
if ($page && $this->process == "ProcessPageEdit") {
$fields = $this->children->implode(',', function ($item) {
// Check for repeater fields
$pattern = '/_repeater\d+$/';
return preg_replace($pattern, '', $item->name);
});
return $process_edit->url([
'data' => [
'id' => $page->id,
'fields' => $fields
]
]);
}
}
}
class FieldtypeFieldsetPanelOpen extends FieldtypeFieldsetOpen
{
public static function getModuleInfo()
{
return array(
'title' => 'Fieldset Panel (Open)',
'version' => 100,
'summary' => 'Open a fieldset to group fields. Should be followed by a Fieldset (Close) after one or more fields.',
'permanent' => true,
);
}
public function init()
{
// TODO Not working :/
$this->addHookBefore('InputfieldFieldsetPanelOpen::render', function ($e) {
//$markup = InputfieldWrapper::getMarkup();
//$markup['item_label'] = "<label class='sr-only uk-form-label' for='{for}'></label>";
//InputfieldWrapper::setMarkup($markup);
// TODO Make hook after
//bd($e->object);
//$e->object->addHookAfter('InputfieldWrapper::render', function($e) use ($markup){
//bd($e);
//InputfieldWrapper::setMarkup($markup);
//});
});
}
public function getInputfield(Page $page, Field $field)
{
/** @var InputfieldFieldsetPanelOpen $inputfield */
$inputfield = $this->wire(new InputfieldFieldsetPanelOpen());
$inputfield->class = $this->className();
return $inputfield;
}
}