コード例 #1
0
ファイル: OptionList.php プロジェクト: rakorium/okapi
 /**
  * @param string $value
  * @param array $config
  * @return string
  */
 protected function renderCheckbox($value, $config)
 {
     $field = $this->field;
     $type = $field->isMultiple() ? 'checkbox' : 'radio';
     // Render the [checkbox]
     $attributes = ['type' => $type, 'name' => $field->name(), 'value' => $value];
     if ($field->hasValue($value)) {
         $attributes["checked"] = "checked";
     }
     $attr = $field->renderAttributes($attributes);
     $html = "<input{$attr}/>";
     // Render the [label]
     if (isset($config['label'])) {
         $attributes = [];
         foreach ($config as $k => $v) {
             if (Form::isBaseAttribute($k)) {
                 $attributes[$k] = $v;
             }
         }
         if (isset($config['attributes'])) {
             $attributes += $config['attributes'];
         }
         $label = $config['label'];
         $attr = $field->renderAttributes($attributes);
         $html = "<label{$attr}>{$html} <span>{$label}</span></label>";
     }
     return $html;
 }