Skip to content

Commit

Permalink
Merge pull request #225 from yajra/macro-editor
Browse files Browse the repository at this point in the history
feat: add macro in editor builder
  • Loading branch information
yajra authored Aug 31, 2024
2 parents 186d220 + e6a35de commit 6605d8b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Html/Editor/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Support\Arr;
use Illuminate\Support\Fluent;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Yajra\DataTables\Html\Editor\Fields\Field;
use Yajra\DataTables\Html\HasAuthorizations;
use Yajra\DataTables\Utilities\Helper;
Expand All @@ -22,7 +24,9 @@
class Editor extends Fluent
{
use HasAuthorizations;
use HasEvents;
use HasEvents, Macroable {
Macroable::__call as macroCall;
}

final public const DISPLAY_LIGHTBOX = 'lightbox';

Expand Down Expand Up @@ -314,4 +318,21 @@ public function hiddenOnEdit(array $fields): static
{
return $this->hiddenOn('edit', $fields);
}

public function __call($method, $parameters): static
{
if (Str::startsWith($method, 'on')) {
$event = Str::camel(substr($method, 2, strlen($method) - 2));

return $this->on($event, $parameters[0]);
}

$macroCall = $this->macroCall($method, $parameters);

if (! $macroCall instanceof Editor) {
abort(500, sprintf('Method %s::%s must return an Editor instance.', static::class, $method));
}

return $this;
}
}

0 comments on commit 6605d8b

Please sign in to comment.