This commit is contained in:
Dan Harrin
2021-02-05 13:17:59 +00:00
parent c7a758cf6a
commit 8f493f4bd2
3 changed files with 17 additions and 17 deletions
+1 -1
View File
@@ -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
View File
@@ -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;
}
+3 -3
View File
@@ -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);
});