|
6 | 6 | use dokuwiki\plugin\struct\meta\Value; |
7 | 7 | use dokuwiki\plugin\struct\meta\ValueValidator; |
8 | 8 | use dokuwiki\plugin\struct\types\Lookup; |
| 9 | +use dokuwiki\plugin\struct\types\Page; |
9 | 10 |
|
10 | 11 | /** |
11 | 12 | * Allows adding a single struct field as a bureaucracy field |
@@ -96,14 +97,39 @@ public function renderfield($params, Doku_Form $form, $formid) |
96 | 97 | } |
97 | 98 |
|
98 | 99 | // output the field |
99 | | - $value = new Value($this->column, $this->opt['value']); |
100 | | - if ($this->column->getType() instanceof Lookup) { |
101 | | - $value->setValue($this->opt['value'], true); |
102 | | - } |
| 100 | + $value = $this->createValue(); |
103 | 101 | $field = $this->makeField($value, $params['name']); |
104 | 102 | $form->addElement($field); |
105 | 103 | } |
106 | 104 |
|
| 105 | + /** |
| 106 | + * Returns a Value object for the current column. |
| 107 | + * Special handling for Page and Lookup literal form values. |
| 108 | + * |
| 109 | + * @return Value |
| 110 | + */ |
| 111 | + protected function createValue() |
| 112 | + { |
| 113 | + $preparedValue = $this->opt['value']; |
| 114 | + |
| 115 | + // page fields might need to be JSON encoded depending on usetitles config |
| 116 | + if ( |
| 117 | + $this->column->getType() instanceof Page |
| 118 | + && $this->column->getType()->getConfig()['usetitles'] |
| 119 | + ) { |
| 120 | + $preparedValue = json_encode([$this->opt['value'], null]); |
| 121 | + } |
| 122 | + |
| 123 | + $value = new Value($this->column, $preparedValue); |
| 124 | + |
| 125 | + // no way to pass $israw parameter to constructor, so re-set the Lookup value |
| 126 | + if ($this->column->getType() instanceof Lookup) { |
| 127 | + $value->setValue($preparedValue, true); |
| 128 | + } |
| 129 | + |
| 130 | + return $value; |
| 131 | + } |
| 132 | + |
107 | 133 | /** |
108 | 134 | * Create the input field |
109 | 135 | * |
|
0 commit comments