';
}
protected function textareaField($name, $value, $class, $attributes, $options)
{
$readonly = array_pull($options, 'readonly', false);
$disabled = array_get($options, 'disabled', false);
return "";
}
protected function checkboxField($name, $value, $class, $attributes, $options, $label)
{
$checked = array_pull($options, 'checked', false);
$disabled = array_get($options, 'disabled', false);
if (! is_null($value)) {
$checked = $value;
}
$html = '
';
if (! $disabled) {
$html .= "";
}
$html .= "';
$html .= "";
$html .= '
';
return $html;
}
protected function selectField($name, $value, $class, $attributes, $options, $list)
{
$multiple = array_get($options, 'multiple', false);
$disabled = array_get($options, 'disabled', false);
$readonly = array_pull($options, 'readonly', false);
$html = "';
return $html;
}
protected function field($name, $title, $errors, $entity, $options, callable $fieldCallback, ...$args)
{
$value = $this->getValue($entity, $name);
if (is_string($value)) {
$value = e($value);
}
$normalizedName = $this->normalizeTranslatableFieldName($name);
$name = array_get($options, 'multiple', false) ? "{$name}[]" : $name;
$required = array_pull($options, 'required', false);
$help = array_pull($options, 'help', false);
$params = array_merge([
$name,
$value,
array_pull($options, 'class'),
$this->generateHtmlAttributes($options),
$options,
], $args);
$labelCol = array_pull($options, 'labelCol', 3);
$fieldCol = 12 - $labelCol;
$html = '';
return new HtmlString($html);
}
private function normalizeTranslatableFieldName($name)
{
if (starts_with($name, 'translatable[')) {
return 'translatable.' . str_between($name, 'translatable[', ']');
}
return $name;
}
protected function label($name, $title, $labelCol = 3, $required = false)
{
$html = "';
}
private function getValue($entity, $name)
{
if (is_object($entity) && method_exists($entity, 'translate') && $entity->isTranslationAttribute($name)) {
$translatedValue = optional($entity->translate(locale(), false))->$name;
return old($name, $translatedValue);
}
$camelCaseName = camel_case($name);
if (is_object($entity) && method_exists($entity, $camelCaseName) && $entity->{$camelCaseName}() instanceof Relation) {
$name = $camelCaseName;
}
$normalizedName = $this->normalizeTranslatableFieldName($name);
$name = str_between($name, 'translatable[', ']');
try {
$value = data_get($entity, $name);
} catch (LogicException $e) {
$value = $entity->getOriginal('url');
}
if ($value instanceof Money) {
$value = $value->amount();
}
return old($normalizedName, $value);
}
protected function generateHtmlAttributes($options = [])
{
$this->unsetUnnecessaryAttributes($options);
$attributes = '';
foreach ($options as $attr => $value) {
$attributes .= "{$attr}='{$value}' ";
}
return $attributes;
}
protected function unsetUnnecessaryAttributes(&$options = [])
{
foreach ($this->unnecessaryAttributes as $attribute) {
if (array_key_exists($attribute, $options)) {
unset($options[$attribute]);
}
}
}
}