Skip to content

Commit 9503405

Browse files
committed
added LongText type based on #349
1 parent fd85dc6 commit 9503405

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

_test/Column.test.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function test_allTypes() {
2121
'DateTime' => 'dokuwiki\\plugin\\struct\\types\\DateTime',
2222
'Decimal' => 'dokuwiki\\plugin\\struct\\types\\Decimal',
2323
'Dropdown' => 'dokuwiki\\plugin\\struct\\types\\Dropdown',
24+
'LongText' => 'dokuwiki\\plugin\\struct\\types\\LongText',
2425
'Lookup' => 'dokuwiki\\plugin\\struct\\types\\Lookup',
2526
'Mail' => 'dokuwiki\\plugin\\struct\\types\\Mail',
2627
'Media' => 'dokuwiki\\plugin\\struct\\types\\Media',
@@ -44,6 +45,7 @@ public function test_extendedTypes() {
4445
'DateTime' => 'dokuwiki\\plugin\\struct\\types\\DateTime',
4546
'Decimal' => 'dokuwiki\\plugin\\struct\\types\\Decimal',
4647
'Dropdown' => 'dokuwiki\\plugin\\struct\\types\\Dropdown',
48+
'LongText' => 'dokuwiki\\plugin\\struct\\types\\LongText',
4749
'Lookup' => 'dokuwiki\\plugin\\struct\\types\\Lookup',
4850
'Mail' => 'dokuwiki\\plugin\\struct\\types\\Mail',
4951
'Media' => 'dokuwiki\\plugin\\struct\\types\\Media',

types/LongText.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace dokuwiki\plugin\struct\types;
3+
4+
use dokuwiki\plugin\struct\meta\QueryBuilder;
5+
use dokuwiki\plugin\struct\meta\QueryBuilderWhere;
6+
7+
class LongText extends AbstractMultiBaseType {
8+
use TraitFilterPrefix;
9+
10+
protected $config = array(
11+
'prefix' => '',
12+
'postfix' => '',
13+
);
14+
15+
16+
/**
17+
* Output the stored data
18+
*
19+
* @param string|int $value the value stored in the database
20+
* @param \Doku_Renderer $R the renderer currently used to render the data
21+
* @param string $mode The mode the output is rendered in (eg. XHTML)
22+
* @return bool true if $mode could be satisfied
23+
*/
24+
public function renderValue($value, \Doku_Renderer $R, $mode) {
25+
$R->cdata($this->config['prefix'] . $value . $this->config['postfix']);
26+
return true;
27+
}
28+
29+
/**
30+
* Clean line endings
31+
*
32+
* @param int|string $rawvalue
33+
* @return int|string
34+
*/
35+
public function validate($rawvalue) {
36+
$rawvalue = rtrim($rawvalue);
37+
$rawvalue = cleanText($rawvalue);
38+
return $rawvalue;
39+
}
40+
41+
/**
42+
* Use a text area for input
43+
*
44+
* @param string $name
45+
* @param string $rawvalue
46+
* @param string $htmlID
47+
*
48+
* @return string
49+
*/
50+
public function valueEditor($name, $rawvalue, $htmlID) {
51+
$rawvalue = formText($rawvalue);
52+
$params = array(
53+
'name' => $name,
54+
'class' => 'struct_'.strtolower($this->getClass()),
55+
'id' => $htmlID
56+
);
57+
$attributes = buildAttributes($params, true);
58+
59+
return "<textarea $attributes>$rawvalue</textarea>";
60+
}
61+
}

0 commit comments

Comments
 (0)