mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-24 01:58:00 +08:00
wip
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ abstract class Action extends Component
|
||||
|
||||
protected function callFormHooks($event)
|
||||
{
|
||||
return $this->getForm()->callActionHooks($this, $event);
|
||||
return $this->getForm()->callHook($this, $event);
|
||||
}
|
||||
|
||||
public function fields()
|
||||
|
||||
+13
-13
@@ -10,8 +10,6 @@ class Field
|
||||
{
|
||||
use Tappable;
|
||||
|
||||
public $actionHooks = [];
|
||||
|
||||
public $context;
|
||||
|
||||
public $enabled = true;
|
||||
@@ -20,6 +18,8 @@ class Field
|
||||
|
||||
public $fields = [];
|
||||
|
||||
public $hooks = [];
|
||||
|
||||
public $id;
|
||||
|
||||
public $includedContexts = [];
|
||||
@@ -117,11 +117,16 @@ class Field
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getActionHooks()
|
||||
public function getForm()
|
||||
{
|
||||
$hooks = $this->actionHooks;
|
||||
return new Form($this->fields, $this->context, $this->record);
|
||||
}
|
||||
|
||||
collect($this->getForm()->getActionHooks())
|
||||
public function getHooks()
|
||||
{
|
||||
$hooks = $this->hooks;
|
||||
|
||||
collect($this->getForm()->getHooks())
|
||||
->each(function ($callbacks, $event) use (&$hooks) {
|
||||
$hooks[$event] = array_merge($hooks[$event] ?? [], $callbacks);
|
||||
});
|
||||
@@ -129,11 +134,6 @@ class Field
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
public function getForm()
|
||||
{
|
||||
return new Form($this->fields, $this->context, $this->record);
|
||||
}
|
||||
|
||||
public function getRules()
|
||||
{
|
||||
if ($this->isDisabled()) return [];
|
||||
@@ -215,11 +215,11 @@ class Field
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function registerActionHook($event, $callback)
|
||||
public function registerHook($event, $callback)
|
||||
{
|
||||
if (! array_key_exists($event, $this->actionHooks)) $this->actionHooks[$event] = [];
|
||||
if (! array_key_exists($event, $this->hooks)) $this->hooks[$event] = [];
|
||||
|
||||
$this->actionHooks[$event][] = $callback;
|
||||
$this->hooks[$event][] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -50,13 +50,13 @@ class Form extends Component
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getActionHooks()
|
||||
public function getHooks()
|
||||
{
|
||||
$hooks = $this->actionHooks;
|
||||
$hooks = $this->hooks;
|
||||
|
||||
collect($this->fields)
|
||||
->each(function ($field) use (&$hooks) {
|
||||
collect($field->getActionHooks())
|
||||
collect($field->getHooks())
|
||||
->each(function ($callbacks, $event) use (&$hooks) {
|
||||
$hooks[$event] = array_merge($hooks[$event] ?? [], $callbacks);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user