Skip to content

Commit 1080a73

Browse files
Minor updates to some Inputfield features relevant mainly to FormBuilder.
1 parent 8afaa59 commit 1080a73

File tree

4 files changed

+70
-5
lines changed

4 files changed

+70
-5
lines changed

wire/core/Inputfield.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ abstract class Inputfield extends WireData implements Module {
6666
const skipLabelNo = false; // don't skip the label at all (default)
6767
const skipLabelFor = true; // don't use a 'for' attribute with the <label>
6868
const skipLabelHeader = 2; // don't use a ui-widget-header label at all
69+
const skipLabelBlank = 4; // skip the label only when blank
6970

7071
/**
7172
* The total number of Inputfield instances, kept as a way of generating unique 'id' attributes
@@ -209,7 +210,10 @@ public function set($key, $value) {
209210
*
210211
*/
211212
public function get($key) {
212-
if($key == 'label' && !parent::get('label')) return $this->attributes['name'];
213+
if($key == 'label' && !parent::get('label')) {
214+
if($this->skipLabel & self::skipLabelBlank) return '';
215+
return $this->attributes['name'];
216+
}
213217
if($key == 'attributes') return $this->attributes;
214218
if($key == 'parent') return $this->parent;
215219
if(($value = $this->getFuel($key)) !== null) return $value;

wire/core/InputfieldWrapper.php

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ public function ___render() {
246246

247247
if($renderValueMode) {
248248
$ffOut = $inputfield->renderValue();
249+
if(is_null($ffOut)) continue;
249250
if(!strlen($ffOut)) $ffOut = '&nbsp;';
250251
} else {
251252
$ffOut = $inputfield->render();

wire/core/ProcessWire.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ProcessWire extends Wire {
3535

3636
const versionMajor = 2;
3737
const versionMinor = 2;
38-
const versionRevision = 8;
38+
const versionRevision = 9;
3939

4040
/**
4141
* Given a Config object, instantiates ProcessWire and it's API
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,86 @@
11
<?php
22

3+
/**
4+
* Intended just for outputting markup as help or commentary among other Inputfields
5+
*
6+
*/
7+
38
class InputfieldMarkup extends InputfieldWrapper {
49

510
public static function getModuleInfo() {
611
return array(
712
'title' => __('Markup', __FILE__),
813
'summary' => __('Contains any other markup and optionally child Inputfields', __FILE__),
9-
'version' => 100,
14+
'version' => 101,
1015
'permanent' => true,
1116
);
1217
}
1318

19+
public function init() {
20+
$this->set('markupText', '');
21+
$this->set('textformatters', array());
22+
$this->skipLabel = Inputfield::skipLabelBlank;
23+
parent::init();
24+
}
25+
1426
public function ___render() {
1527
$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+
1641
if($this->description) {
17-
$out .= "\n<p class='description'>{$this->description}</p>";
42+
$out = "\n<p class='description'>{$this->description}</p>" . $out;
1843
$this->description = ''; // prevents it from appearing again at the bottom
1944
}
20-
if($this->attr('value')) $out .= "\n" . $this->attr('value');
45+
2146
$out .= parent::___render();
2247
return $out;
2348
}
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+
}
2484

2585
}
2686

0 commit comments

Comments
 (0)