_templates = $templates; } /** * Render a text widget or other simple widget like email/tel/number. * * This method accepts a number of keys: * * - `name` The name attribute. * - `val` The value attribute. * - `escape` Set to false to disable escaping on all attributes. * * Any other keys provided in $data will be converted into HTML attributes. * * @param array $data The data to build an input with. * @param \Cake\View\Form\ContextInterface $context The current form context. * @return string */ public function render(array $data, ContextInterface $context) { $data += [ 'name' => '', 'val' => null, 'type' => 'text', 'escape' => true, 'templateParams' => [] ]; $data['value'] = $data['val']; unset($data['val']); return $this->_templates->format('input', [ 'name' => $data['name'], 'type' => $data['type'], 'templateParams' => $data['templateParams'], 'attrs' => $this->_templates->formatAttributes( $data, ['name', 'type'] ), ]); } /** * {@inheritDoc} */ public function secureFields(array $data) { if (!isset($data['name']) || $data['name'] === '') { return []; } return [$data['name']]; } }