diff --git a/app/Services/OptionForm.php b/app/Services/OptionForm.php index 9459d997..5327b986 100644 --- a/app/Services/OptionForm.php +++ b/app/Services/OptionForm.php @@ -108,7 +108,7 @@ class OptionForm $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; } @@ -148,13 +148,11 @@ class OptionForm 'name' => '', ], $info); - $classes = "btn btn-{$info['style']} ".implode(' ', (array) Arr::get($info, 'class')); - - if ($info['href']) { - $this->buttons[] = "{$info['text']}"; - } else { - $this->buttons[] = ""; - } + $info['class'] = array_merge( + ['btn', 'btn-'.$info['style']], + (array) Arr::get($info, 'class') + ); + $this->buttons[] = $info; return $this; } @@ -172,7 +170,7 @@ class OptionForm $msg = trans("options.$this->id.message"); } - $this->messages[] = "
$msg
"; + $this->messages[] = ['content' => $msg, 'type' => $style]; return $this; } @@ -353,7 +351,9 @@ class OptionForm $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"); } - $this->hint = view('common.option-form.hint')->with('hint', $hintContent)->render(); + $this->hint = view('forms.hint')->with('hint', $hintContent)->render(); return $this; } @@ -425,7 +425,7 @@ class OptionFormItem public function disabled($disabled = 'disabled') { - $this->disabled = "disabled=\"$disabled\""; + $this->disabled = $disabled; return $this; } @@ -460,7 +460,7 @@ class OptionFormText extends OptionFormItem public function render() { - return view('common.option-form.text')->with([ + return view('forms.text')->with([ 'id' => $this->id, 'value' => $this->value, 'disabled' => $this->disabled, @@ -486,7 +486,7 @@ class OptionFormCheckbox extends OptionFormItem public function render() { - return view('common.option-form.checkbox')->with([ + return view('forms.checkbox')->with([ 'id' => $this->id, 'value' => $this->value, 'label' => $this->label, @@ -508,7 +508,7 @@ class OptionFormTextarea extends OptionFormItem public function render() { - return view('common.option-form.textarea')->with([ + return view('forms.textarea')->with([ 'id' => $this->id, 'rows' => $this->rows, 'value' => $this->value, @@ -530,9 +530,9 @@ class OptionFormSelect extends OptionFormItem public function render() { - return view('common.option-form.select')->with([ + return view('forms.select')->with([ 'id' => $this->id, - 'options' => $this->options, + 'options' => (array) $this->options, 'selected' => $this->value, 'disabled' => $this->disabled, ]); @@ -575,13 +575,13 @@ class OptionFormGroup extends OptionFormItem $item['value'] = option_localized($item['id']); } - $rendered[] = view('common.option-form.'.$item['type'])->with([ + $rendered[] = view('forms.'.$item['type'])->with([ 'id' => $item['id'], 'value' => $item['value'], 'placeholder' => Arr::get($item, 'placeholder'), ]); } - return view('common.option-form.group')->with('items', $rendered); + return view('forms.group')->with('items', $rendered); } } diff --git a/resources/views/common/option-form/checkbox.blade.php b/resources/views/common/option-form/checkbox.blade.php deleted file mode 100644 index c904ff7f..00000000 --- a/resources/views/common/option-form/checkbox.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/resources/views/common/option-form/group.blade.php b/resources/views/common/option-form/group.blade.php deleted file mode 100644 index 7d70e79f..00000000 --- a/resources/views/common/option-form/group.blade.php +++ /dev/null @@ -1,5 +0,0 @@ -
- @foreach($items as $item) - {!! $item->render() !!} - @endforeach -
diff --git a/resources/views/common/option-form/hint.blade.php b/resources/views/common/option-form/hint.blade.php deleted file mode 100644 index 85ca54a7..00000000 --- a/resources/views/common/option-form/hint.blade.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/views/common/option-form/item.blade.php b/resources/views/common/option-form/item.blade.php deleted file mode 100644 index c7c678fd..00000000 --- a/resources/views/common/option-form/item.blade.php +++ /dev/null @@ -1,5 +0,0 @@ -{!! $item->render() !!} - -@if ($item->description) -

{!! $item->description !!}

-@endif diff --git a/resources/views/common/option-form/main.blade.php b/resources/views/common/option-form/main.blade.php deleted file mode 100644 index c0adeed6..00000000 --- a/resources/views/common/option-form/main.blade.php +++ /dev/null @@ -1,41 +0,0 @@ -
-
-

{{ $title }} {!! $hint ?? '' !!}

-
-
- @csrf - -
- - @foreach($messages as $msg) - {!! $msg !!} - @endforeach - - @if ($renderWithoutTable) - @each('common.option-form.item', $items, 'item') - @else - - - @foreach($items as $item) - - @unless ($renderInputTagsOnly) - - @endunless - - - - @endforeach - -
{{ $item->name }} {!! $item->hint ?? '' !!} - @include('common.option-form.item', compact('item')) -
- @endif - -
- -
-
diff --git a/resources/views/common/option-form/select.blade.php b/resources/views/common/option-form/select.blade.php deleted file mode 100644 index 8af9b2da..00000000 --- a/resources/views/common/option-form/select.blade.php +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/resources/views/common/option-form/text.blade.php b/resources/views/common/option-form/text.blade.php deleted file mode 100644 index 1d71c215..00000000 --- a/resources/views/common/option-form/text.blade.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/views/common/option-form/textarea.blade.php b/resources/views/common/option-form/textarea.blade.php deleted file mode 100644 index 60ccfc2a..00000000 --- a/resources/views/common/option-form/textarea.blade.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/views/common/option-form/addon.twig b/resources/views/forms/addon.twig similarity index 100% rename from resources/views/common/option-form/addon.twig rename to resources/views/forms/addon.twig diff --git a/resources/views/forms/checkbox.twig b/resources/views/forms/checkbox.twig new file mode 100644 index 00000000..9f43b391 --- /dev/null +++ b/resources/views/forms/checkbox.twig @@ -0,0 +1,10 @@ + diff --git a/resources/views/forms/form.twig b/resources/views/forms/form.twig new file mode 100644 index 00000000..6771b397 --- /dev/null +++ b/resources/views/forms/form.twig @@ -0,0 +1,62 @@ +
+
+

{{ title }} {{ hint|raw }}

+
+
+ {{ csrf_field() }} + +
+ {% for message in messages %} +
+ {{ message.content|raw }} +
+ {% endfor %} + + {% if renderWithoutTable %} + {% for item in items %} + {{ item.render()|raw }} + {% if item.description %} +

{{ item.description|raw }}

+ {% endif %} + {% endfor %} + {% else %} + + + {% for item in items %} + + {% if not renderInputTagsOnly %} + + {% endif %} + + + {% endfor %} + +
+ {{ item.name }} {{ item.hint|raw }} + + {{ item.render()|raw }} + {% if item.description %} +

{{ item.description|raw }}

+ {% endif %} +
+ {% endif %} +
+ +
+
diff --git a/resources/views/forms/group.twig b/resources/views/forms/group.twig new file mode 100644 index 00000000..ab7f5d6b --- /dev/null +++ b/resources/views/forms/group.twig @@ -0,0 +1,5 @@ +
+ {% for item in items %} + {{ item.render()|raw }} + {% endfor %} +
diff --git a/resources/views/forms/hint.twig b/resources/views/forms/hint.twig new file mode 100644 index 00000000..81a290ab --- /dev/null +++ b/resources/views/forms/hint.twig @@ -0,0 +1 @@ + diff --git a/resources/views/forms/select.twig b/resources/views/forms/select.twig new file mode 100644 index 00000000..6bdb9cea --- /dev/null +++ b/resources/views/forms/select.twig @@ -0,0 +1,10 @@ + diff --git a/resources/views/forms/text.twig b/resources/views/forms/text.twig new file mode 100644 index 00000000..c0a55afc --- /dev/null +++ b/resources/views/forms/text.twig @@ -0,0 +1,8 @@ + diff --git a/resources/views/forms/textarea.twig b/resources/views/forms/textarea.twig new file mode 100644 index 00000000..42a905b2 --- /dev/null +++ b/resources/views/forms/textarea.twig @@ -0,0 +1,6 @@ + diff --git a/tests/ServicesTest/OptionFormTest.php b/tests/ServicesTest/OptionFormTest.php index df2db6aa..3c3dc8fa 100644 --- a/tests/ServicesTest/OptionFormTest.php +++ b/tests/ServicesTest/OptionFormTest.php @@ -87,10 +87,10 @@ class OptionFormTest extends TestCase $a = $crawler->filter('a'); $this->assertEquals('http://example.com', $a->attr('href')); $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'); - $this->assertEquals('press me', $button->text()); + $this->assertEquals('press me', trim($button->text())); $this->assertEquals('btn', $button->attr('name')); $this->assertEquals('button', $button->attr('type')); @@ -106,8 +106,11 @@ class OptionFormTest extends TestCase $this->assertSame($form, $returned); $crawler = new Crawler($form->render()); - $this->assertEquals(trans('options.test.message'), $crawler->filter('.callout-info')->text()); - $this->assertEquals('greeting', $crawler->filter('.callout-warning')->text()); + $this->assertEquals( + trans('options.test.message'), + trim($crawler->filter('.callout-info')->text()) + ); + $this->assertEquals('greeting', trim($crawler->filter('.callout-warning')->text())); } public function testHookBefore() @@ -217,7 +220,7 @@ class OptionFormTest extends TestCase $crawler = new Crawler($form->render()); $button = $crawler->filter('button'); $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_test', $button->attr('name')); } @@ -235,7 +238,10 @@ class OptionFormTest extends TestCase $form->handle(); $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')); }