This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.php
47 lines (46 loc) · 1.63 KB
/
index.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
<?php
Kirby::plugin('ragi96/table-field', [
'fields' => [
'table' => [
'props' => [
'maxColumns' => function (int $maxColumns = 5) {
return $maxColumns;
},
'minColumns' => function (int $minColumns = 2) {
return $minColumns;
},
]
]
],
'fieldMethods' => [
'toTable' => function ($field) {
if (is_string($field->value())) {
$value = $field->kirbytextinline();
$valueArray = preg_split('/\n|\r\n?/', $value);
$selfmadeValue = [];
$row = [];
foreach ($valueArray as $val) {
$lastSixChars = substr($val, -6);
if ($lastSixChars == '<br />') {
$val = str_replace($lastSixChars, '', $val);
}
if ($val == '-') {
if (count($row) > 0) {
array_push($selfmadeValue, $row);
}
$row = [];
} else {
$val = preg_replace('/^- /', '', ltrim($val), 1);
// removes first and last quotes
$val = preg_replace('/^[\"\'](.*)[\"\']$/', '$1', $val);
array_push($row, $val);
}
}
array_push($selfmadeValue, $row);
return $selfmadeValue;
} else {
return $field->toArray()[$field->key()];
}
}
]
]);