setRecordID($recordID); } $this->onLoad($data); return $this; } /** * @return int|string */ public function recordID() { return $this->recordID; } /** * @param int|string $id * @return self */ public function setRecordID($id) { $this->recordID = $id; return $this; } /** * Handle submit request * @return \bff\http\Response */ public function onSubmitAction() { return $this->submit(); } /** * Process form submit * @return \bff\http\Response */ public function submit() { $this->app->hook('view.form.beforeSubmit', $this); parent::submit(); $this->app->hook('view.form.submit', $this); return $this->getActionResponse(); } /** * Process form validation * @param array $data * @return array|mixed */ public function validate($data = []) { $this->trigger('beforeValidate', ['data' => & $data]); $data = parent::validate($data); $this->trigger('afterValidate', ['data' => & $data]); return $data; } /** * Reload block content * @return \bff\http\Response */ public function onReloadAction() { $event = $this->request->post('event', TYPE_STR); return $this->reloadBlocks($event); } /** * Process form reload blocks * @param string $event * @return \bff\http\Response */ protected function reloadBlocks($event) { $data = $this->validate(); $this->errors->clear(); $this->trigger('reloadBlocksBefore', ['event' => $event, 'data' => & $data]); $this->onLoad($data); $reload = []; $iterator = function ($block) use ($event, &$reload, &$iterator) { if ($block instanceof FormBlock) { $html = $block->reloadBlock($event); if ($html !== false) { $reload[$block->getKey()] = $html; } $block->blocksIterator($iterator); } }; $this->blocksIterator($iterator); $this->respond('reload', $reload); $this->respond('event', $event); return $this->getActionResponse(); } /** * Trigger event for blocks * @param $event * @param array $data */ public function trigger($event, $data = []) { $method = 'on' . Str::studly($event) . 'Event'; $iterator = function ($block) use ($method, $data, &$iterator) { if ($block instanceof FormBlock) { if (method_exists($block, $method)) { call_user_func([$block, $method], $data); } $block->blocksIterator($iterator); } }; $this->blocksIterator($iterator); } }