-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldtypeRockGrid.module.php
More file actions
102 lines (87 loc) · 2.3 KB
/
FieldtypeRockGrid.module.php
File metadata and controls
102 lines (87 loc) · 2.3 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace ProcessWire;
use RockGrid\RockGridField;
/**
* @author Bernhard Baumrock, 16.06.2022
* @license MIT as of 2026-01-21
* @link https://www.baumrock.com
*/
class FieldtypeRockGrid extends Fieldtype
{
public static function getModuleInfo()
{
return [
'title' => 'RockGrid',
'version' => json_decode(file_get_contents(__DIR__ . "/package.json"))->version,
'summary' => 'Module to display a RockGrid in the page editor.',
'icon' => 'table',
'requires' => ['RockGrid'],
];
}
public function sanitizeValue(Page $page, Field $field, $value)
{
return $value;
}
/** FIELDTYPE METHODS */
/**
* Return the fields required to configure an instance of FieldtypeText
*
* @param Field $field
* @return InputfieldWrapper
*
*/
public function ___getConfigInputfields(Field $field)
{
$inputfields = parent::___getConfigInputfields($field);
// prepare variables and markup
$url = wire()->pages->get(2)->url . 'setup/grids/';
$grids = '';
foreach (rockgrid()->gridsArray as $k => $v) {
$grids .= "\n$k";
}
// add field
$inputfields->add([
'type' => 'text',
'name' => 'grid',
'label' => 'Name of the grid to display',
'value' => $field->get('grid'),
'notes' => "Manage grids here: [$url]($url)
Available grids: $grids",
]);
return $inputfields;
}
public function ___formatValue(Page $page, Field $field, $value)
{
return new RockGridField($page, $field, $value);
}
/**
* Get database schema used by the Field
*
* @param Field $field
* @return array
*
*/
public function getDatabaseSchema(Field $field)
{
$schema = parent::getDatabaseSchema($field);
$schema['data'] = 'JSON';
// Remove the default index that ProcessWire adds for the data column
// since MySQL doesn't allow direct indexing on JSON columns
// fixes this issue: https://processwire.com/talk/topic/31057--
unset($schema['keys']['data']);
return $schema;
}
/**
* Return the associated Inputfield
*
* @param Page $page
* @param Field $field
* @return Inputfield
*/
public function getInputfield(Page $page, Field $field)
{
$f = $this->wire(new InputfieldRockGrid());
$f->grid = $field->get('grid');
return $f;
}
}