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: * Render a button.
30: *
31: * This method accepts a number of keys:
32: *
33: * - `text` The text of the button. Unlike all other form controls, buttons
34: * do not escape their contents by default.
35: * - `escape` Set to true to enable escaping on all attributes.
36: * - `type` The button type defaults to 'submit'.
37: *
38: * Any other keys provided in $data will be converted into HTML attributes.
39: *
40: * @param array $data The data to build a button with.
41: * @param \Cake\View\Form\ContextInterface $context The current form context.
42: * @return string
43: */
44: public function render(array $data, ContextInterface $context)
45: {
46: $data += [
47: 'text' => '',
48: 'type' => 'submit',
49: 'escape' => false,
50: 'templateVars' => []
51: ];
52:
53: return $this->_templates->format('button', [
54: 'text' => $data['escape'] ? h($data['text']) : $data['text'],
55: 'templateVars' => $data['templateVars'],
56: 'attrs' => $this->_templates->formatAttributes($data, ['text']),
57: ]);
58: }
59: }
60: