* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute'); /** * Populate form element's value to match available values * * Use table data to populate values * * @version 0.1.0 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_ValueFixer extends WBDatasource_FormAttribute { /** * configuration parameter * @var array */ protected $config = array( ); /** * Current HTTP Request * @var WBRequest */ private $req; /** * Get Attribute's Value * * Actually don't change current attribute's value, just fix request value * in order to allow form validation to succeed * * @param mixed $current actual attribute value * @return array */ protected function getAttributeValue($current) { $this->req = WBClass::create('WBRequest'); $name = $this->element->getAttribute('name'); $value = $this->req->get($name, '__NOT_SET__'); if ('__NOT_SET__' == $value) { return $current; } $values = $this->element->getAttribute('values'); foreach ($values as $v) { if ($v['value'] == $value) { return $current; } } $this->element->setValue($current); return $current; } }