public function testGetChoices() { $obj = new ArrayType('koala', array('gum', 'leaves')); $choices = $obj->getChoices(); $this->assertContains('gum', $choices); $this->assertContains('leaves', $choices); }
/** * Get customised value parameters for choice field types. * * @return array */ protected function getChoiceValues(array &$options) { if (is_string($this->baseOptions['choices']) && strpos($this->baseOptions['choices'], 'contenttype::') === 0) { $choice = new ContentType($this->storage, $this->fieldname, $this->baseOptions); // Only unset for a this type as it's custom unset($options['sort']); unset($options['limit']); unset($options['filters']); } else { $choice = new ArrayType($this->fieldname, $this->baseOptions['choices']); } return $choice->getChoices(); }
/** * Add a field to the form * * @param string $formname Name of the form * @param string $type * @param array $options */ public function addField($formname, $fieldname, $type, array $options) { if (isset($options['constraints'])) { if (gettype($options['constraints']) == 'string') { $options['constraints'] = $this->getConstraint($options['constraints']); } else { foreach ($options['constraints'] as $key => $constraint) { $options['constraints'][$key] = $this->getConstraint(array($key => $constraint)); } } } if ($type === 'choice') { if (is_string($options['choices']) && strpos($options['choices'], 'contenttype::') === 0) { $choice = new ContentType($this->app, $fieldname, $options['choices']); } else { $choice = new ArrayType($fieldname, $options['choices']); } $options['choices'] = $choice->getChoices(); } $this->forms[$formname]->add($fieldname, $type, $options); }