Blade -> Twig (for forms)
This commit is contained in:
parent
a9e11f7785
commit
322ef7cdeb
|
|
@ -108,7 +108,7 @@ class OptionForm
|
||||||
$hintContent = trans("options.$this->id.hint");
|
$hintContent = trans("options.$this->id.hint");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hint = view('common.option-form.hint')->with('hint', $hintContent)->render();
|
$this->hint = view('forms.hint')->with('hint', $hintContent)->render();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -148,13 +148,11 @@ class OptionForm
|
||||||
'name' => '',
|
'name' => '',
|
||||||
], $info);
|
], $info);
|
||||||
|
|
||||||
$classes = "btn btn-{$info['style']} ".implode(' ', (array) Arr::get($info, 'class'));
|
$info['class'] = array_merge(
|
||||||
|
['btn', 'btn-'.$info['style']],
|
||||||
if ($info['href']) {
|
(array) Arr::get($info, 'class')
|
||||||
$this->buttons[] = "<a href='{$info['href']}' class='$classes'>{$info['text']}</a>";
|
);
|
||||||
} else {
|
$this->buttons[] = $info;
|
||||||
$this->buttons[] = "<button type='{$info['type']}' name='{$info['name']}' class='$classes'>{$info['text']}</button>";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +170,7 @@ class OptionForm
|
||||||
$msg = trans("options.$this->id.message");
|
$msg = trans("options.$this->id.message");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->messages[] = "<div class='callout callout-$style'>$msg</div>";
|
$this->messages[] = ['content' => $msg, 'type' => $style];
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -353,7 +351,9 @@ class OptionForm
|
||||||
|
|
||||||
$this->assignValues();
|
$this->assignValues();
|
||||||
|
|
||||||
return view('common.option-form.main')->with(array_merge(get_object_vars($this)))->render();
|
return view('forms.form')
|
||||||
|
->with(array_merge(get_object_vars($this)))
|
||||||
|
->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -411,7 +411,7 @@ class OptionFormItem
|
||||||
$hintContent = trans("options.$this->parentId.$this->id.hint");
|
$hintContent = trans("options.$this->parentId.$this->id.hint");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hint = view('common.option-form.hint')->with('hint', $hintContent)->render();
|
$this->hint = view('forms.hint')->with('hint', $hintContent)->render();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -425,7 +425,7 @@ class OptionFormItem
|
||||||
|
|
||||||
public function disabled($disabled = 'disabled')
|
public function disabled($disabled = 'disabled')
|
||||||
{
|
{
|
||||||
$this->disabled = "disabled=\"$disabled\"";
|
$this->disabled = $disabled;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -460,7 +460,7 @@ class OptionFormText extends OptionFormItem
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('common.option-form.text')->with([
|
return view('forms.text')->with([
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'value' => $this->value,
|
'value' => $this->value,
|
||||||
'disabled' => $this->disabled,
|
'disabled' => $this->disabled,
|
||||||
|
|
@ -486,7 +486,7 @@ class OptionFormCheckbox extends OptionFormItem
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('common.option-form.checkbox')->with([
|
return view('forms.checkbox')->with([
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'value' => $this->value,
|
'value' => $this->value,
|
||||||
'label' => $this->label,
|
'label' => $this->label,
|
||||||
|
|
@ -508,7 +508,7 @@ class OptionFormTextarea extends OptionFormItem
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('common.option-form.textarea')->with([
|
return view('forms.textarea')->with([
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'rows' => $this->rows,
|
'rows' => $this->rows,
|
||||||
'value' => $this->value,
|
'value' => $this->value,
|
||||||
|
|
@ -530,9 +530,9 @@ class OptionFormSelect extends OptionFormItem
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('common.option-form.select')->with([
|
return view('forms.select')->with([
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'options' => $this->options,
|
'options' => (array) $this->options,
|
||||||
'selected' => $this->value,
|
'selected' => $this->value,
|
||||||
'disabled' => $this->disabled,
|
'disabled' => $this->disabled,
|
||||||
]);
|
]);
|
||||||
|
|
@ -575,13 +575,13 @@ class OptionFormGroup extends OptionFormItem
|
||||||
$item['value'] = option_localized($item['id']);
|
$item['value'] = option_localized($item['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rendered[] = view('common.option-form.'.$item['type'])->with([
|
$rendered[] = view('forms.'.$item['type'])->with([
|
||||||
'id' => $item['id'],
|
'id' => $item['id'],
|
||||||
'value' => $item['value'],
|
'value' => $item['value'],
|
||||||
'placeholder' => Arr::get($item, 'placeholder'),
|
'placeholder' => Arr::get($item, 'placeholder'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('common.option-form.group')->with('items', $rendered);
|
return view('forms.group')->with('items', $rendered);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
<label for="{{ $id }}">
|
|
||||||
<input {!! $value ? 'checked="true"' : '' !!} type="checkbox" id="{{ $id }}" name="{{ $id }}" {{ $disabled ?? '' }} value="true"> {{ $label }}
|
|
||||||
</label>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<div class="input-group">
|
|
||||||
@foreach($items as $item)
|
|
||||||
{!! $item->render() !!}
|
|
||||||
@endforeach
|
|
||||||
</div>
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
<i class="fas fa-question-circle" title="{!! $hint !!}" data-toggle="tooltip" data-placement="top"></i>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
{!! $item->render() !!}
|
|
||||||
|
|
||||||
@if ($item->description)
|
|
||||||
<p class="description">{!! $item->description !!}</p>
|
|
||||||
@endif
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
<div class="card card-{{ $type }}">
|
|
||||||
<div class="card-header">
|
|
||||||
<h3 class="card-title">{{ $title }} {!! $hint ?? '' !!}</h3>
|
|
||||||
</div>
|
|
||||||
<form method="post">
|
|
||||||
@csrf
|
|
||||||
<input type="hidden" name="option" value="{{ $id }}">
|
|
||||||
<div class="card-body">
|
|
||||||
|
|
||||||
@foreach($messages as $msg)
|
|
||||||
{!! $msg !!}
|
|
||||||
@endforeach
|
|
||||||
|
|
||||||
@if ($renderWithoutTable)
|
|
||||||
@each('common.option-form.item', $items, 'item')
|
|
||||||
@else
|
|
||||||
<table class="table">
|
|
||||||
<tbody>
|
|
||||||
@foreach($items as $item)
|
|
||||||
<tr>
|
|
||||||
@unless ($renderInputTagsOnly)
|
|
||||||
<td class="key">{{ $item->name }} {!! $item->hint ?? '' !!}</td>
|
|
||||||
@endunless
|
|
||||||
|
|
||||||
<td class="value">
|
|
||||||
@include('common.option-form.item', compact('item'))
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
@endforeach
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="card-footer">
|
|
||||||
@foreach($buttons as $button)
|
|
||||||
{!! $button !!}
|
|
||||||
@endforeach
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
<select class="form-control" name="{{ $id }}" {{ $disabled ?? '' }}>
|
|
||||||
|
|
||||||
@foreach ((array) $options as $option)
|
|
||||||
<option {!! $selected == $option['value'] ? 'selected="selected"' : '' !!} value="{{ $option['value'] }}">{{ $option['name'] }}</option>
|
|
||||||
@endforeach
|
|
||||||
|
|
||||||
</select>
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
<input type="text" class="form-control" name="{{ $id }}" {{ $disabled ?? '' }} value="{{ $value }}" placeholder="{{ $placeholder ?? '' }}">
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
<textarea class="form-control" rows="{{ $rows }}" name="{{ $id }}" {{ $disabled ?? '' }}>{{ $value }}</textarea>
|
|
||||||
10
resources/views/forms/checkbox.twig
Normal file
10
resources/views/forms/checkbox.twig
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<label for="{{ id }}">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
{{ value ? 'checked="true"' : '' }}
|
||||||
|
id="{{ id }}"
|
||||||
|
name="{{ id }}"
|
||||||
|
{{ disabled ? 'disabled=disabled' : '' }}
|
||||||
|
value="true"
|
||||||
|
> {{ label }}
|
||||||
|
</label>
|
||||||
62
resources/views/forms/form.twig
Normal file
62
resources/views/forms/form.twig
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<div class="card card-{{ type }}">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3 class="card-title">{{ title }} {{ hint|raw }}</h3>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<input type="hidden" name="option" value="{{ id }}">
|
||||||
|
<div class="card-body">
|
||||||
|
{% for message in messages %}
|
||||||
|
<div class="callout callout-{{ message.type }}">
|
||||||
|
{{ message.content|raw }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if renderWithoutTable %}
|
||||||
|
{% for item in items %}
|
||||||
|
{{ item.render()|raw }}
|
||||||
|
{% if item.description %}
|
||||||
|
<p class="description">{{ item.description|raw }}</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
{% for item in items %}
|
||||||
|
<tr>
|
||||||
|
{% if not renderInputTagsOnly %}
|
||||||
|
<td class="key">
|
||||||
|
{{ item.name }} {{ item.hint|raw }}
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
|
<td class="value">
|
||||||
|
{{ item.render()|raw }}
|
||||||
|
{% if item.description %}
|
||||||
|
<p class="description">{{ item.description|raw }}</p>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
{% for button in buttons %}
|
||||||
|
{% if button.href %}
|
||||||
|
<a href="{{ button.href }}" class="{{ button.class|join(' ') }}">
|
||||||
|
{{ button.text|raw }}
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<button
|
||||||
|
type="{{ button.type }}"
|
||||||
|
name="{{ button.name }}"
|
||||||
|
class="{{ button.class|join(' ') }}"
|
||||||
|
>
|
||||||
|
{{ button.text|raw }}
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
5
resources/views/forms/group.twig
Normal file
5
resources/views/forms/group.twig
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
<div class="input-group">
|
||||||
|
{% for item in items %}
|
||||||
|
{{ item.render()|raw }}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
1
resources/views/forms/hint.twig
Normal file
1
resources/views/forms/hint.twig
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<i class="fas fa-question-circle" title="{{ hint }}" data-toggle="tooltip" data-placement="top"></i>
|
||||||
10
resources/views/forms/select.twig
Normal file
10
resources/views/forms/select.twig
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<select class="form-control" name="{{ id }}" {{ disabled ? 'disabled=disabled' : '' }}>
|
||||||
|
{% for option in options %}
|
||||||
|
<option
|
||||||
|
value="{{ option.value }}"
|
||||||
|
{{ selected == option.value ? 'selected=selected' : '' }}
|
||||||
|
>
|
||||||
|
{{ option.name }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
8
resources/views/forms/text.twig
Normal file
8
resources/views/forms/text.twig
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="form-control"
|
||||||
|
name="{{ id }}"
|
||||||
|
{{ disabled ? 'disabled=disabled' : '' }}
|
||||||
|
value="{{ value }}"
|
||||||
|
placeholder="{{ placeholder }}"
|
||||||
|
>
|
||||||
6
resources/views/forms/textarea.twig
Normal file
6
resources/views/forms/textarea.twig
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<textarea
|
||||||
|
class="form-control"
|
||||||
|
rows="{{ rows }}"
|
||||||
|
name="{{ id }}"
|
||||||
|
{{ disabled ? 'disabled=disabled' : '' }}
|
||||||
|
>{{ value }}</textarea>
|
||||||
|
|
@ -87,10 +87,10 @@ class OptionFormTest extends TestCase
|
||||||
$a = $crawler->filter('a');
|
$a = $crawler->filter('a');
|
||||||
$this->assertEquals('http://example.com', $a->attr('href'));
|
$this->assertEquals('http://example.com', $a->attr('href'));
|
||||||
$this->assertEquals('btn btn-default a b', $a->attr('class'));
|
$this->assertEquals('btn btn-default a b', $a->attr('class'));
|
||||||
$this->assertEquals('link', $a->text());
|
$this->assertEquals('link', trim($a->text()));
|
||||||
|
|
||||||
$button = $crawler->filter('button.btn-primary');
|
$button = $crawler->filter('button.btn-primary');
|
||||||
$this->assertEquals('press me', $button->text());
|
$this->assertEquals('press me', trim($button->text()));
|
||||||
$this->assertEquals('btn', $button->attr('name'));
|
$this->assertEquals('btn', $button->attr('name'));
|
||||||
$this->assertEquals('button', $button->attr('type'));
|
$this->assertEquals('button', $button->attr('type'));
|
||||||
|
|
||||||
|
|
@ -106,8 +106,11 @@ class OptionFormTest extends TestCase
|
||||||
$this->assertSame($form, $returned);
|
$this->assertSame($form, $returned);
|
||||||
|
|
||||||
$crawler = new Crawler($form->render());
|
$crawler = new Crawler($form->render());
|
||||||
$this->assertEquals(trans('options.test.message'), $crawler->filter('.callout-info')->text());
|
$this->assertEquals(
|
||||||
$this->assertEquals('greeting', $crawler->filter('.callout-warning')->text());
|
trans('options.test.message'),
|
||||||
|
trim($crawler->filter('.callout-info')->text())
|
||||||
|
);
|
||||||
|
$this->assertEquals('greeting', trim($crawler->filter('.callout-warning')->text()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHookBefore()
|
public function testHookBefore()
|
||||||
|
|
@ -217,7 +220,7 @@ class OptionFormTest extends TestCase
|
||||||
$crawler = new Crawler($form->render());
|
$crawler = new Crawler($form->render());
|
||||||
$button = $crawler->filter('button');
|
$button = $crawler->filter('button');
|
||||||
$this->assertStringContainsString('btn-primary', $button->attr('class'));
|
$this->assertStringContainsString('btn-primary', $button->attr('class'));
|
||||||
$this->assertEquals(trans('general.submit'), $button->text());
|
$this->assertEquals(trans('general.submit'), trim($button->text()));
|
||||||
$this->assertEquals('submit', $button->attr('type'));
|
$this->assertEquals('submit', $button->attr('type'));
|
||||||
$this->assertEquals('submit_test', $button->attr('name'));
|
$this->assertEquals('submit_test', $button->attr('name'));
|
||||||
}
|
}
|
||||||
|
|
@ -235,7 +238,10 @@ class OptionFormTest extends TestCase
|
||||||
|
|
||||||
$form->handle();
|
$form->handle();
|
||||||
$crawler = new Crawler($form->render());
|
$crawler = new Crawler($form->render());
|
||||||
$this->assertEquals(trans('options.option-saved'), $crawler->filter('.callout-success')->text());
|
$this->assertEquals(
|
||||||
|
trans('options.option-saved'),
|
||||||
|
trim($crawler->filter('.callout-success')->text())
|
||||||
|
);
|
||||||
$this->assertEquals('formatted value', option('t'));
|
$this->assertEquals('formatted value', option('t'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user