Esempio n. 1
0
 /**
  * test render escape
  *
  * @return void
  */
 public function testRenderAttributes()
 {
     $label = new Label($this->templates);
     $data = ['text' => 'My > text', 'for' => 'some-id', 'id' => 'some-id', 'data-foo' => 'value'];
     $result = $label->render($data);
     $expected = ['label' => ['id' => 'some-id', 'data-foo' => 'value', 'for' => 'some-id'], 'My > text', '/label'];
     $this->assertTags($result, $expected);
 }
Esempio n. 2
0
 /**
  * Renders a label element for a given radio button.
  *
  * In the future this might be refactored into a separate widget as other
  * input types (multi-checkboxes) will also need labels generated.
  *
  * @param array $radio The input properties.
  * @param false|string|array $label The properties for a label.
  * @param string $input The input widget.
  * @param \Cake\View\Form\ContextInterface $context The form context.
  * @param bool $escape Whether or not to HTML escape the label.
  * @return string Generated label.
  */
 protected function _renderLabel($radio, $label, $input, $context, $escape)
 {
     if ($label === false) {
         return false;
     }
     $labelAttrs = is_array($label) ? $label : [];
     $labelAttrs += ['for' => $radio['id'], 'escape' => $escape, 'text' => $radio['text'], 'input' => $input];
     return $this->_label->render($labelAttrs, $context);
 }
Esempio n. 3
0
 /**
  * Render a single checkbox & wrapper.
  *
  * @param array $checkbox An array containing checkbox key/value option pairs
  * @return string
  */
 protected function _renderInput($checkbox)
 {
     $input = $this->_templates->format('checkbox', ['name' => $checkbox['name'] . '[]', 'value' => $checkbox['escape'] ? h($checkbox['value']) : $checkbox['value'], 'attrs' => $this->_templates->formatAttributes($checkbox, ['name', 'value', 'text'])]);
     $labelAttrs = ['for' => $checkbox['id'], 'escape' => $checkbox['escape'], 'text' => $checkbox['text'], 'input' => $input];
     if (!empty($checkbox['checked']) && empty($labelAttrs['class'])) {
         $labelAttrs['class'] = 'selected';
     }
     $label = $this->_label->render($labelAttrs);
     return $this->_templates->format('checkboxContainer', ['label' => $label, 'input' => $input]);
 }