|
1 | 1 | <?php
|
2 | 2 |
|
| 3 | +/** |
| 4 | + * Intended just for outputting markup as help or commentary among other Inputfields |
| 5 | + * |
| 6 | + */ |
| 7 | + |
3 | 8 | class InputfieldMarkup extends InputfieldWrapper {
|
4 | 9 |
|
5 | 10 | public static function getModuleInfo() {
|
6 | 11 | return array(
|
7 | 12 | 'title' => __('Markup', __FILE__),
|
8 | 13 | 'summary' => __('Contains any other markup and optionally child Inputfields', __FILE__),
|
9 |
| - 'version' => 100, |
| 14 | + 'version' => 101, |
10 | 15 | 'permanent' => true,
|
11 | 16 | );
|
12 | 17 | }
|
13 | 18 |
|
| 19 | + public function init() { |
| 20 | + $this->set('markupText', ''); |
| 21 | + $this->set('textformatters', array()); |
| 22 | + $this->skipLabel = Inputfield::skipLabelBlank; |
| 23 | + parent::init(); |
| 24 | + } |
| 25 | + |
14 | 26 | public function ___render() {
|
15 | 27 | $out = '';
|
| 28 | + |
| 29 | + if(strlen($this->attr('value'))) $out .= "\n" . $this->attr('value'); |
| 30 | + if(strlen($this->markupText)) $out .= "\n" . $this->markupText; |
| 31 | + $out = trim($out); |
| 32 | + |
| 33 | + if(count($this->textformatters)) { |
| 34 | + foreach($this->textformatters as $className) { |
| 35 | + $t = wire('modules')->get($className); |
| 36 | + if(!$t) continue; |
| 37 | + $t->formatValue(wire('page'), new Field(), $out); |
| 38 | + } |
| 39 | + } |
| 40 | + |
16 | 41 | if($this->description) {
|
17 |
| - $out .= "\n<p class='description'>{$this->description}</p>"; |
| 42 | + $out = "\n<p class='description'>{$this->description}</p>" . $out; |
18 | 43 | $this->description = ''; // prevents it from appearing again at the bottom
|
19 | 44 | }
|
20 |
| - if($this->attr('value')) $out .= "\n" . $this->attr('value'); |
| 45 | + |
21 | 46 | $out .= parent::___render();
|
22 | 47 | return $out;
|
23 | 48 | }
|
| 49 | + |
| 50 | + public function ___renderValue() { |
| 51 | + if(count($this->children)) return parent::___renderValue(); |
| 52 | + return null; |
| 53 | + } |
| 54 | + |
| 55 | + public function ___getConfigInputfields() { |
| 56 | + |
| 57 | + $inputfields = parent::___getConfigInputfields(); |
| 58 | + if($this->hasFieldtype) return $inputfields; |
| 59 | + |
| 60 | + $f = wire('modules')->get('InputfieldTextarea'); |
| 61 | + $f->attr('id+name', 'markupText'); |
| 62 | + $f->attr('value', $this->markupText); |
| 63 | + $f->attr('rows', 10); |
| 64 | + $f->label = $this->_('Markup Text'); |
| 65 | + $inputfields->add($f); |
| 66 | + |
| 67 | + $f = $this->modules->get('InputfieldAsmSelect'); |
| 68 | + $f->attr('id+name', 'textformatters'); |
| 69 | + $f->label = $this->_('Text Formatters'); |
| 70 | + |
| 71 | + foreach($this->modules->find("className^=Textformatter") as $textformatter) { |
| 72 | + $info = $textformatter->getModuleInfo(); |
| 73 | + $f->addOption($textformatter->className(), "$info[title]"); |
| 74 | + } |
| 75 | + |
| 76 | + $f->attr('value', $this->textformatters); |
| 77 | + |
| 78 | + $f->description = $this->_('Select the format that your Markup Text is in, or the formatters that you want to be applied to it, in the order you want them applied.'); |
| 79 | + $f->notes = $this->_('If your Markup Text is plain HTML, you may not want to select any Text Formatters.'); |
| 80 | + $inputfields->add($f); |
| 81 | + |
| 82 | + return $inputfields; |
| 83 | + } |
24 | 84 |
|
25 | 85 | }
|
26 | 86 |
|
0 commit comments