/** * Test render with additional attributes. * * @return void */ public function testRenderAttributes() { $button = new ButtonWidget($this->templates); $data = ['name' => 'my_input', 'text' => 'Go', 'class' => 'btn', 'required' => true]; $result = $button->render($data, $this->context); $expected = ['button' => ['type' => 'submit', 'name' => 'my_input', 'class' => 'btn', 'required' => 'required'], 'Go', '/button']; $this->assertHtml($expected, $result); }
/** * Renders a button. * * @param array $data The data to build a button with. * @param \Cake\View\Form\ContextInterface $context The current form context. * @return string */ public function render(array $data, ContextInterface $context) { $data = $this->injectClasses('btn', $data); $data['class'] = explode(' ', $data['class']); foreach ($data['class'] as &$class) { if (in_array($class, $this->_styles)) { $class = 'btn-' . $class; break; } } $data['class'] = implode(' ', $data['class']); return parent::render($data, $context); }
/** * Ensure templateVars option is hooked up. * * @return void */ public function testRenderTemplateVars() { $this->templates->add(['button' => '<button {{attrs}} custom="{{custom}}">{{text}}</button>']); $button = new ButtonWidget($this->templates); $data = ['templateVars' => ['custom' => 'value'], 'text' => 'Go']; $result = $button->render($data, $this->context); $expected = ['button' => ['type' => 'submit', 'custom' => 'value'], 'Go', '/button']; $this->assertHtml($expected, $result); }
/** * Renders a button. * * @param array $data The data to build a button with. * @param \Cake\View\Form\ContextInterface $context The current form context. * @return string */ public function render(array $data, ContextInterface $context) { return parent::render($this->injectClasses('btn', $data), $context); }
/** * Renders a button. * * @param array $data The data to build a button with. * @param \Cake\View\Form\ContextInterface $context The current form context. * @return string */ public function render(array $data, ContextInterface $context) { $data = $this->applyButtonClasses($data); return parent::render($data, $context); }