Skip to content

Instantly share code, notes, and snippets.

@Natetronn
Created January 17, 2013 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natetronn/4554543 to your computer and use it in GitHub Desktop.
Save Natetronn/4554543 to your computer and use it in GitHub Desktop.
ProcessWire InputfieldTextarea.module w/ placeholder text
<?php
/**
* An Inputfield for handling XHTML "textarea" form inputs
*
*/
class InputfieldTextarea extends Inputfield {
const defaultRows = 5;
public static function getModuleInfo() {
return array(
'title' => __('Textarea', __FILE__), // Module Title
'summary' => __('Multiple lines of text', __FILE__), // Module Summary
'version' => 100,
'permanent' => true,
);
}
public function init() {
parent::init();
$this->setAttribute('rows', self::defaultRows);
$this->setAttribute('placeholder', '');
}
public function ___render() {
$attrs = $this->getAttributes();
unset($attrs['value']);
$out = "\n<textarea " . $this->getAttributesString($attrs) . ">" .
htmlspecialchars($this->value) .
"</textarea>";
return $out;
}
/**
* Render just the value (not input) in text/markup for presentation purposes
*
* @return string of text or markup where applicable
*
*/
public function ___renderValue() {
$out = nl2br(htmlentities($this->attr('value'), ENT_QUOTES, "UTF-8"));
return $out;
}
public function ___getConfigInputfields() {
$inputfields = parent::___getConfigInputfields();
$field = $this->modules->get('InputfieldInteger');
$field->setAttribute('name', 'rows');
$field->label = $this->_('Rows');
$field->setAttribute('value', $this->attr('rows') > 0 ? $this->attr('rows') : self::defaultRows);
$field->setAttribute('size', 3);
$field->description = $this->_('The number of rows initially shown for this field.');
$inputfields->append($field);
$field = $this->modules->get('InputfieldText');
$field->setAttribute('name', 'placeholder');
$field->label = $this->_('Placeholder Text');
$field->setAttribute('value', $this->attr('placeholder'));
$field->description = $this->_('Optional placeholder phrase of text that appears in the field when blank.');
$field->columnWidth = 100;
$inputfields->append($field);
return $inputfields;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment