Skip to content

Commit 6605d8b

Browse files
authored
Merge pull request #225 from yajra/macro-editor
feat: add macro in editor builder
2 parents 186d220 + e6a35de commit 6605d8b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Html/Editor/Editor.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Fluent;
7+
use Illuminate\Support\Str;
8+
use Illuminate\Support\Traits\Macroable;
79
use Yajra\DataTables\Html\Editor\Fields\Field;
810
use Yajra\DataTables\Html\HasAuthorizations;
911
use Yajra\DataTables\Utilities\Helper;
@@ -22,7 +24,9 @@
2224
class Editor extends Fluent
2325
{
2426
use HasAuthorizations;
25-
use HasEvents;
27+
use HasEvents, Macroable {
28+
Macroable::__call as macroCall;
29+
}
2630

2731
final public const DISPLAY_LIGHTBOX = 'lightbox';
2832

@@ -314,4 +318,21 @@ public function hiddenOnEdit(array $fields): static
314318
{
315319
return $this->hiddenOn('edit', $fields);
316320
}
321+
322+
public function __call($method, $parameters): static
323+
{
324+
if (Str::startsWith($method, 'on')) {
325+
$event = Str::camel(substr($method, 2, strlen($method) - 2));
326+
327+
return $this->on($event, $parameters[0]);
328+
}
329+
330+
$macroCall = $this->macroCall($method, $parameters);
331+
332+
if (! $macroCall instanceof Editor) {
333+
abort(500, sprintf('Method %s::%s must return an Editor instance.', static::class, $method));
334+
}
335+
336+
return $this;
337+
}
317338
}

0 commit comments

Comments
 (0)