Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add macro in editor builder #225

Merged
merged 3 commits into from
Aug 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading