Skip to content

Commit c4292fc

Browse files
committed
Fix editor options implementation
1 parent 4da6ba3 commit c4292fc

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/Html/HasEditor.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ trait HasEditor
1818
*
1919
* @param array|mixed ...$editors
2020
* @return $this
21-
* @throws \Exception
2221
* @see https://editor.datatables.net/
2322
*/
2423
public function editors(...$editors): static
@@ -27,49 +26,30 @@ public function editors(...$editors): static
2726
$editors = $editors[0];
2827
}
2928

29+
$collection = [];
3030
foreach ($editors as $editor) {
31-
$this->editor($editor);
31+
$collection[] = $this->editor($editor);
3232
}
3333

34+
$this->editors = $collection;
35+
3436
return $this;
3537
}
3638

3739
/**
3840
* Integrate with DataTables Editor.
3941
*
40-
* @param Editor $fields
42+
* @param Editor $editor
4143
* @return $this
42-
* @throws \Exception
4344
* @see https://editor.datatables.net/
4445
*/
45-
public function editor(Editor $fields): static
46+
public function editor(Editor $editor): static
4647
{
4748
/** @var string $template */
4849
$template = $this->config->get('datatables-html.editor', 'datatables::editor');
4950

5051
$this->setTemplate($template);
5152

52-
$editor = $this->newEditor($fields);
53-
54-
$this->editors[] = $editor;
55-
56-
return $this;
57-
}
58-
59-
/**
60-
* @param array|Editor $fields
61-
* @return Editor
62-
* @throws \Exception
63-
*/
64-
protected function newEditor(Editor|array $fields): Editor
65-
{
66-
if ($fields instanceof Editor) {
67-
$editor = $fields;
68-
} else {
69-
$editor = new Editor;
70-
$editor->fields($fields);
71-
}
72-
7353
if (! $editor->table) {
7454
$editor->table('#'.$this->getTableAttribute('id'));
7555
}
@@ -78,7 +58,9 @@ protected function newEditor(Editor|array $fields): Editor
7858
$editor->ajax($this->getAjaxUrl());
7959
}
8060

81-
return $editor;
61+
$this->editors[] = $editor;
62+
63+
return $this;
8264
}
8365

8466
/**

tests/BuilderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Yajra\DataTables\Html\Column;
88
use Yajra\DataTables\Html\ColumnDefinition;
99
use Yajra\DataTables\Html\ColumnDefinitions;
10+
use Yajra\DataTables\Html\Editor\Editor;
1011

1112
class BuilderTest extends TestCase
1213
{
@@ -232,4 +233,21 @@ public function it_has_table_options()
232233
$this->assertInstanceOf(HtmlString::class, $builder->table());
233234
$this->assertEquals('<table class="table" id="my-table"><thead><tr></tr></thead></table>', $builder->table()->toHtml());
234235
}
236+
237+
/** @test */
238+
public function it_has_editors()
239+
{
240+
$builder = $this->getHtmlBuilder();
241+
242+
$builder->editor(Editor::make());
243+
$this->assertCount(1, $builder->getEditors());
244+
245+
$builder->editors([
246+
Editor::make(),
247+
Editor::make('edit'),
248+
]);
249+
$this->assertCount(2, $builder->getEditors());
250+
}
251+
252+
235253
}

0 commit comments

Comments
 (0)