/** @test */ public function it_creates_choice_as_radio_buttons() { $options = [ 'attr' => ['class' => 'choice-class-something'], 'choices' => [1 => 'yes', 2 => 'no'], 'selected' => 'no', 'expanded' => true ]; $this->fieldExpetations('radio', Mockery::any()); $this->fieldExpetations('radio', Mockery::any()); $this->fieldExpetations('choice', Mockery::any()); $choice = new ChoiceType('some_choice', 'choice', $this->plainForm, $options); $choice->render(); $this->assertEquals(2, count($choice->getChildren())); $this->assertInstanceOf( 'Kris\LaravelFormBuilder\Fields\CheckableType', $choice->getChild(1) ); $this->assertEquals('no', $choice->getOption('selected')); $this->assertContainsOnlyInstancesOf('Kris\LaravelFormBuilder\Fields\CheckableType', $choice->getChildren()); }
/** * @inheritdoc */ protected function createChildren() { if ($this->getOption('choices')) { return parent::createChildren(); } $entity = $this->getOption('class'); $queryBuilder = $this->getOption('query_builder'); $key = $this->getOption('property_key'); $value = $this->getOption('property'); if (!$entity || !class_exists($entity)) { throw new \InvalidArgumentException(sprintf('Please provide valid "class" option for entity field [%s] in form class [%s]', $this->getRealName(), get_class($this->parent))); } $entity = new $entity(); if ($queryBuilder instanceof \Closure) { $data = $queryBuilder($entity); if (is_object($data) && method_exists($data, 'lists')) { $data = $data->lists($value, $key); } } else { $data = $entity->lists($value, $key); } if ($data instanceof Collection) { $data = $data->all(); } $this->options['choices'] = $data; return parent::createChildren(); }
public function render(array $options = [], $showLabel = true, $showField = true, $showError = true) { return parent::render($options, $showLabel, $showField, $showError); // TODO: Change the autogenerated stub }