value rows * the row will contain one text field for "key" and the other for "value" */ namespace Ppb\Form\Element; use Cube\Form\Element; class MultiKeyValue extends Element { const FIELD_KEY = 'key'; const FIELD_VALUE = 'value'; /** * * type of element - override the variable from the parent class * * @var string */ protected $_element = 'multiKeyValue'; /** * * class constructor * * @param string $name */ public function __construct($name) { parent::__construct($this->_element, $name); $translate = $this->getTranslate(); $this->setBodyCode( ""); } /** * * render the form element * * @return string */ public function render() { $output = null; $values = $this->getValue(); $output .= '
'; foreach ((array)$values[self::FIELD_KEY] as $id => $key) { if (!empty($key)) { $output .= $this->_renderRow(false, $key, $values[self::FIELD_VALUE][$id]); } } $output .= '
'; $output .= $this->_renderRow(); return $output; } /** * * render a single row of the element * * @param bool $new * @param string $key * @param string $value * * @return string */ protected function _renderRow($new = true, $key = null, $value = null) { $translate = $this->getTranslate(); $placeholder = $this->getAttribute('placeholder'); if (!empty($placeholder)) { $placeholder .= ' '; } $this->removeAttribute('placeholder')->addAttribute('placeholder', $translate->_('Key')); $output = '
' . ' renderAttributes() . 'value="' . $key . '" ' . $this->_endTag; $this->removeAttribute('placeholder')->addAttribute('placeholder', $translate->_('Value')); $output .= ' renderAttributes() . 'value="' . $value . '" ' . $this->_endTag . (($new === true) ? ' ' : ' ') . '
'; return $output; } }