* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute'); /** * Populate form element's attribute conditional * * * @version 1.0.0 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_SwitchIfEqual extends WBDatasource_FormAttribute { /** * configuration parameter * * - switch named attribute like "disabled". used for value lists * - value switch target value * - left compare left side * - right compare right side * @var array */ protected $config = array( 'switch' => 'disabled', 'value' => 'no', 'left' => '', 'right' => '' ); /** * get attribute's value * * * * @param mixed $current actual attribute value * @return array */ protected function getAttributeValue($current) { if ($this->config['left'] != $this->config['right']) { return $current; } // just the disabled switch if (!is_array($current)) { return $this->config['value']; } // value list foreach ($current as &$c) { $c[$this->config['switch']] = $this->config['value']; } return $current; } }