-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldtypeRockInvoiceItems.module.php
More file actions
84 lines (76 loc) · 1.96 KB
/
FieldtypeRockInvoiceItems.module.php
File metadata and controls
84 lines (76 loc) · 1.96 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
<?php
namespace ProcessWire;
use RockInvoiceItems\Items;
/**
* @author Bernhard Baumrock, 14.01.2025
* @license MIT as of 2026-01-21
* @link https://www.baumrock.com
*/
require_once __DIR__ . '/Item.php';
require_once __DIR__ . '/Items.php';
class FieldtypeRockInvoiceItems extends FieldtypeTextarea
{
/**
* Formatted value is the raw JSON string at the moment
* Maybe change this in the future to a basic table?
* @param mixed $page
* @param mixed $field
* @param mixed $value
* @return string
*/
public function formatValue($page, $field, $value)
{
return (string)$value;
}
/**
* Returns an empty Items object
* @param Page|NullPage $page
* @param Field $field
* @return string|int|object|null
*/
public function getBlankValue(Page $page, Field $field)
{
return new Items();
}
/**
* Links the inputfield to this fieldtype
* @param Page $page
* @param Field $field
* @return Inputfield
* @throws WireException
* @throws WirePermissionException
*/
public function getInputfield(Page $page, Field $field)
{
return wire()->modules->get('InputfieldRockInvoiceItems');
}
/**
* Called when a page is saved (and in some other cases)
*
* This is important to make sure that getUnformatted is always an Items
* object and not a raw json string!
*
* See https://processwire.com/talk/topic/7416-understanding-fieldtypetextarealanguagewakeupvalue/?do=findComment&comment=71711
*
* @param Page $page
* @param Field $field
* @param string $value
* @return string
*/
public function sanitizeValue(Page $page, Field $field, $value)
{
if (!$value instanceof Items) $value = new Items($value);
return $value;
}
/**
* Returns an items object when value is loaded from the DB
* @param mixed $page
* @param mixed $field
* @param mixed $value
* @return Items
*/
public function wakeupValue($page, $field, $value)
{
return new Items($value);
}
}