['html'], 'needs_context' => true ]) ]; } /** * Génère le code HTML d'un champs * @param array $context Contexte de la vue Twig * @param string $key Clef du champs * @param mixed $value Valeur du champs * @param string|null $label Label à utiliser * @param array $options * @return string */ public function field(array $context, string $key, $value, ?string $label = null, array $options = []): string { $type = $options['type'] ?? 'text'; $error = $this->getErrorHtml($context, $key); $class = 'form-group'; $value = $this->convertValue($value); $attributes = [ 'class' => trim('form-control ' . ($options['class'] ?? '')), 'name' => $key, 'id' => $key ]; if ($error) { $class .= ' has-danger'; $attributes['class'] .= ' form-control-danger'; } if ($type === 'textarea') { $input = $this->textarea($value, $attributes); } elseif ($type === 'file') { $input = $this->file($attributes); } elseif ($type === 'checkbox') { $input = $this->checkbox($value, $attributes); } elseif (array_key_exists('options', $options)) { $input = $this->select($value, $options['options'], $attributes); } else { $attributes['type'] = $options['type'] ?? 'text'; $input = $this->input($value, $attributes); } return "