/** * @param ElementView $element * @param array $attributes * @param array $options * @return string */ public function renderElement(ElementView $element, $attributes = [], array $options = []) { $this->options->overrideBlocks($element, $options); $html = $this->renderBlock($element->block, ['element' => $element, 'attr' => array_merge($element->attributes, $attributes), 'value' => $element->value, 'options' => array_merge($element->options, $options), 'choices' => $element->choices]); $element->rendered = true; return $html; }
/** @test */ public function it_should_process_an_element_with_options() { $languages = new Select('languages', [1 => 'PHP', 2 => 'Scala']); $languagesView = $languages->buildView(); $options = ['attr' => ['class' => 'js-update'], 'label' => 'Languages', 'label_attr' => ['class' => 'required-label'], 'options' => ['custom_option' => 'custom_value']]; $processedOptions = $this->options->process($languagesView, $options); $this->assertEquals(['element' => $languagesView, 'isValid' => true, 'attr' => ['class' => 'js-update', 'name' => 'languages'], 'options' => ['custom_option' => 'custom_value'], 'label' => 'Languages', 'label_attr' => ['class' => 'required-label']], $processedOptions); }
function it_should_render_a_form_row(BlockOptions $blockOptions, FormTheme $theme, Template $template) { $username = new Text('username'); $username->setValue('john.doe'); $username->setMessages(['User "john.doe" does not exist.']); $options = ['attr' => ['class' => 'inline-element'], 'label' => 'Username', 'label_attr' => ['class' => 'inline-label']]; $usernameView = $username->buildView(); $processedOptions = ['element' => $usernameView, 'isValid' => $usernameView->isValid, 'attr' => $usernameView->attributes + $options['attr'], 'options' => [], 'label' => $options['label'], 'label_attr' => $options['label_attr']]; $theme->loadTemplateFor($usernameView->rowBlock)->willReturn($template); $theme->blocks()->willReturn([]); $blockOptions->process($usernameView, $options)->willReturn($processedOptions); $this->renderRow($usernameView, $options); $template->displayBlock($usernameView->rowBlock, $processedOptions, [])->shouldHaveBeenCalled(); }