private function buildOptions(&$select, $range) { foreach ($range as $value) { $option = new Option(); $option->setValue($value, true); $option->setLabel($value); $select->addOption($option); } }
function testAddNewOptions() { $option = new Option(); $option->setKey('key'); $option->setDefaultValue('value'); $option->setValue('value'); $option->setType('string'); $wpoptions = new WpOptions('test'); $options = new Options('test', $wpoptions); $options->add($option); $this->assertEquals('value', $options->get('key')->getValue()); }
public function source($options) { foreach ($options as $key => $label) { if (is_object($label)) { $key = $label->getKey(); $label = $label->getValue(); } $option = new Option(); foreach ($this->pushSave as $name => $value) { $option->push($name, $value); } $option->setValue($key); $option->setLabel($label); $this->parent->addOption($option, $this->position); } }
/** * @param $renderApi * @param $unit * @return IOptionProvider */ public function getListOptions($renderApi, $unit) { $options = preg_split('/\\n/', $renderApi->getFormValue($unit, 'listFieldOptions')); foreach ($options as $option) { $checked = false; if (preg_match('/\\*$/', $option)) { $checked = true; $option = preg_replace('/\\*$/', '', $option); } $optionObj = new \Option(); $optionObj->setName($option); $optionObj->setValue($option); $optionObj->setChecked($checked); $this->optionProvider->addOption($optionObj); } return $this->optionProvider; }
/** * Creates an option and adds it to the receiver * * @param String $value * @param String $label * @param (boolean) $checked * @param (String) $id */ public function createOption($value, $label, $checked = false, $id = null) { // by incoming request $val = $this->getRequestValue(); if ($val != null && $val == $value) { $checked = true; } else { if ($val != null && $val != $value) { $checked = false; } } $option = new Option(); $option->setValue($value); $option->setLabel($label); $option->setChecked($checked); if (!is_null($id)) { $option->setId($id); } $this->options[] = $option; return $option; }
/** * @covers Phossa\Console\Option::getValue */ public function testGetValue() { $this->object->setValue('bingo'); $this->assertEquals('bingo', $this->object->getValue()); }