mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-24 01:58:00 +08:00
wip
This commit is contained in:
+5
-5
@@ -14,17 +14,17 @@ abstract class Action extends Component
|
||||
|
||||
public static $title;
|
||||
|
||||
public function callHooks($event)
|
||||
public function callFormHooks($event)
|
||||
{
|
||||
return $this->getFields()->callHooks($event, $this);
|
||||
return $this->getForm()->callActionHooks($this, $event);
|
||||
}
|
||||
|
||||
public function fields()
|
||||
{
|
||||
return [];
|
||||
return static::$resource::fields();
|
||||
}
|
||||
|
||||
public function getFields()
|
||||
public function getForm()
|
||||
{
|
||||
$record = null;
|
||||
if (property_exists($this, 'record')) $record = $this->record;
|
||||
@@ -34,7 +34,7 @@ abstract class Action extends Component
|
||||
|
||||
public function getRules()
|
||||
{
|
||||
return $this->getFields()->getRules();
|
||||
return $this->getForm()->getRules();
|
||||
}
|
||||
|
||||
public static function getTitle()
|
||||
|
||||
+10
-10
@@ -10,12 +10,12 @@ class Field
|
||||
{
|
||||
use Tappable;
|
||||
|
||||
public $actionHooks = [];
|
||||
|
||||
public $enabled = true;
|
||||
|
||||
public $fields = [];
|
||||
|
||||
public $hooks = [];
|
||||
|
||||
public $id;
|
||||
|
||||
public $name;
|
||||
@@ -95,16 +95,16 @@ class Field
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFields()
|
||||
public function getForm()
|
||||
{
|
||||
return new Form($this->fields, $this->record);
|
||||
}
|
||||
|
||||
public function getHooks()
|
||||
public function getActionHooks()
|
||||
{
|
||||
$hooks = $this->hooks;
|
||||
$hooks = $this->actionHooks;
|
||||
|
||||
collect($this->getFields()->getHooks())
|
||||
collect($this->getForm()->getActionHooks())
|
||||
->each(function ($callbacks, $event) use (&$hooks) {
|
||||
$hooks[$event] = array_merge($hooks[$event] ?? [], $callbacks);
|
||||
});
|
||||
@@ -116,13 +116,13 @@ class Field
|
||||
{
|
||||
$rules = $this->rules;
|
||||
|
||||
collect($this->getFields()->getRules())
|
||||
collect($this->getForm()->getRules())
|
||||
->each(function ($conditions, $field) use (&$rules) {
|
||||
$conditions = collect($conditions)
|
||||
->map(function ($condition) {
|
||||
if (! is_string($condition)) return $condition;
|
||||
|
||||
return (string) Str::of($condition)->replace('{{record}}', $this->record->getKey());
|
||||
return (string) Str::of($condition)->replace('{{record}}', $this->record ? $this->record->getKey() : '');
|
||||
})
|
||||
->toArray();
|
||||
|
||||
@@ -148,9 +148,9 @@ class Field
|
||||
|
||||
public function registerHook($event, $callback)
|
||||
{
|
||||
if (! array_key_exists($event, $this->hooks)) $this->hooks[$event] = [];
|
||||
if (! array_key_exists($event, $this->actionHooks)) $this->actionHooks[$event] = [];
|
||||
|
||||
$this->hooks[$event][] = $callback;
|
||||
$this->actionHooks[$event][] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ class Fieldset extends Field
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFields()
|
||||
public function getForm()
|
||||
{
|
||||
return parent::getFields()->columns($this->columns);
|
||||
return parent::getForm()->columns($this->columns);
|
||||
}
|
||||
|
||||
public function legend($legend = null)
|
||||
|
||||
@@ -80,7 +80,7 @@ class UpdateAccountForm extends Action
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$this->callHooks('submit');
|
||||
$this->callFormHooks('submit');
|
||||
|
||||
if ($this->newAvatar) {
|
||||
$this->record->avatar = $this->newAvatar->store('avatars', config('filament.storage_disk'));
|
||||
|
||||
@@ -6,12 +6,12 @@ use Illuminate\View\Component;
|
||||
|
||||
class Form extends Component
|
||||
{
|
||||
public $actionHooks = [];
|
||||
|
||||
public $columns = 1;
|
||||
|
||||
public $fields = [];
|
||||
|
||||
public $hooks = [];
|
||||
|
||||
public $rules = [];
|
||||
|
||||
public function __construct($fields = [], $record = null)
|
||||
@@ -21,9 +21,14 @@ class Form extends Component
|
||||
if ($record) $this->passRecordToFields($record);
|
||||
}
|
||||
|
||||
public function callHooks($event, $action)
|
||||
public function actionHooks($hooks)
|
||||
{
|
||||
$hooks = $this->getHooks();
|
||||
$this->actionHooks = $hooks;
|
||||
}
|
||||
|
||||
public function callActionHooks($action, $event)
|
||||
{
|
||||
$hooks = $this->getActionHooks();
|
||||
|
||||
if (! array_key_exists($event, $hooks)) return $action;
|
||||
|
||||
@@ -43,13 +48,13 @@ class Form extends Component
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHooks()
|
||||
public function getActionHooks()
|
||||
{
|
||||
$hooks = $this->hooks;
|
||||
$hooks = $this->actionHooks;
|
||||
|
||||
collect($this->fields)
|
||||
->each(function ($field) use (&$hooks) {
|
||||
collect($field->getHooks())
|
||||
collect($field->getActionHooks())
|
||||
->each(function ($callbacks, $event) use (&$hooks) {
|
||||
$hooks[$event] = array_merge($hooks[$event] ?? [], $callbacks);
|
||||
});
|
||||
@@ -73,11 +78,6 @@ class Form extends Component
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function hooks($hooks)
|
||||
{
|
||||
$this->hooks = $hooks;
|
||||
}
|
||||
|
||||
public function passRecordToFields($record = null)
|
||||
{
|
||||
if (! $record) return $this->fields;
|
||||
@@ -86,7 +86,7 @@ class Form extends Component
|
||||
->map(function ($field) use ($record) {
|
||||
return $field
|
||||
->record($record)
|
||||
->fields($field->getFields()->passRecordToFields($record));
|
||||
->fields($field->getForm()->passRecordToFields($record));
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user