1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11: * @link https://cakephp.org CakePHP(tm) Project
12: * @since 3.0.0
13: * @license https://opensource.org/licenses/mit-license.php MIT License
14: */
15: namespace Cake\View\Widget;
16:
17: use Cake\View\Form\ContextInterface;
18:
19: /**
20: * Button input class
21: *
22: * This input class can be used to render button elements.
23: * If you need to make basic submit inputs with type=submit,
24: * use the Basic input widget.
25: */
26: class ButtonWidget extends BasicWidget
27: {
28:
29: /**
30: * Render a button.
31: *
32: * This method accepts a number of keys:
33: *
34: * - `text` The text of the button. Unlike all other form controls, buttons
35: * do not escape their contents by default.
36: * - `escape` Set to true to enable escaping on all attributes.
37: * - `type` The button type defaults to 'submit'.
38: *
39: * Any other keys provided in $data will be converted into HTML attributes.
40: *
41: * @param array $data The data to build a button with.
42: * @param \Cake\View\Form\ContextInterface $context The current form context.
43: * @return string
44: */
45: public function render(array $data, ContextInterface $context)
46: {
47: $data += [
48: 'text' => '',
49: 'type' => 'submit',
50: 'escape' => false,
51: 'templateVars' => []
52: ];
53:
54: return $this->_templates->format('button', [
55: 'text' => $data['escape'] ? h($data['text']) : $data['text'],
56: 'templateVars' => $data['templateVars'],
57: 'attrs' => $this->_templates->formatAttributes($data, ['text']),
58: ]);
59: }
60: }
61: