¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -23,9 +23,10 @@ trait InputFields
{$attributes}"
. ($disabled ? 'disabled' : '')
. ($readonly ? 'readonly ' : '') .
'>';
'>';
}
protected function textareaField($name, $value, $class, $attributes, $options)
{
$readonly = array_pull($options, 'readonly', false);
@@ -38,21 +39,22 @@ trait InputFields
{$attributes}"
. ($disabled ? 'disabled' : '')
. ($readonly ? 'readonly ' : '') .
">{$value}</textarea>";
">{$value}</textarea>";
}
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)) {
if (!is_null($value)) {
$checked = $value;
}
$html = '<div class="checkbox">';
if (! $disabled) {
if (!$disabled) {
$html .= "<input type='hidden' value='0' name='{$name}'>";
}
@@ -63,9 +65,9 @@ trait InputFields
id='{$name}'
{$attributes}
value='1'"
. ($checked ? 'checked ' : '')
. ($disabled ? 'disabled' : '') .
'>';
. ($checked ? 'checked ' : '')
. ($disabled ? 'disabled' : '') .
'>';
$html .= "<label for='{$name}'>{$label}</label>";
$html .= '</div>';
@@ -73,6 +75,7 @@ trait InputFields
return $html;
}
protected function selectField($name, $value, $class, $attributes, $options, $list)
{
$multiple = array_get($options, 'multiple', false);
@@ -86,7 +89,7 @@ trait InputFields
{$attributes}"
. ($disabled ? 'disabled' : '')
. ($readonly ? 'readonly ' : '') .
'>';
'>';
foreach ($list as $listValue => $listName) {
$listValue = e($listValue);
@@ -94,10 +97,10 @@ trait InputFields
if ($multiple && $value instanceof Collection) {
$selected = $value->where('id', $listValue)->isNotEmpty() ? 'selected' : '';
} elseif ($multiple && is_array($value)) {
} else if ($multiple && is_array($value)) {
$selected = in_array($listValue, $value) ? 'selected' : '';
} else {
$selected = (! is_null($value) && $value == $listValue) ? 'selected' : '';
$selected = (!is_null($value) && $value == $listValue) ? 'selected' : '';
}
$html .= "<option value='{$listValue}' {$selected}>{$listName}</option>";
@@ -108,6 +111,7 @@ trait InputFields
return $html;
}
protected function field($name, $title, $errors, $entity, $options, callable $fieldCallback, ...$args)
{
$value = $this->getValue($entity, $name);
@@ -139,7 +143,7 @@ trait InputFields
$html .= "<div class='col-md-{$fieldCol}'>";
$html .= call_user_func_array($fieldCallback, $params);
if ($help && ! $errors->has($normalizedName)) {
if ($help && !$errors->has($normalizedName)) {
$html .= "<span class='help-block'>{$help}</span>";
}
@@ -151,15 +155,31 @@ trait InputFields
return new HtmlString($html);
}
private function normalizeTranslatableFieldName($name)
protected function generateHtmlAttributes($options = [])
{
if (starts_with($name, 'translatable[')) {
return 'translatable.' . str_between($name, 'translatable[', ']');
$this->unsetUnnecessaryAttributes($options);
$attributes = '';
foreach ($options as $attr => $value) {
$attributes .= "{$attr}='{$value}' ";
}
return $name;
return $attributes;
}
protected function unsetUnnecessaryAttributes(&$options = [])
{
foreach ($this->unnecessaryAttributes as $attribute) {
if (array_key_exists($attribute, $options)) {
unset($options[$attribute]);
}
}
}
protected function label($name, $title, $labelCol = 3, $required = false)
{
$html = "<label for='{$name}' class='col-md-{$labelCol} control-label text-left'>{$title}";
@@ -171,6 +191,7 @@ trait InputFields
return $html .= '</label>';
}
private function getValue($entity, $name)
{
if (is_object($entity) && method_exists($entity, 'translate') && $entity->isTranslationAttribute($name)) {
@@ -201,25 +222,13 @@ trait InputFields
return old($normalizedName, $value);
}
protected function generateHtmlAttributes($options = [])
private function normalizeTranslatableFieldName($name)
{
$this->unsetUnnecessaryAttributes($options);
$attributes = '';
foreach ($options as $attr => $value) {
$attributes .= "{$attr}='{$value}' ";
if (starts_with($name, 'translatable[')) {
return 'translatable.' . str_between($name, 'translatable[', ']');
}
return $attributes;
}
protected function unsetUnnecessaryAttributes(&$options = [])
{
foreach ($this->unnecessaryAttributes as $attribute) {
if (array_key_exists($attribute, $options)) {
unset($options[$attribute]);
}
}
return $name;
}
}