|
@@ -30,12 +30,15 @@ class StepBuilder
|
|
|
* @var array
|
|
|
*/
|
|
|
protected $options = [
|
|
|
- 'width' => '1000px',
|
|
|
+ 'width' => '1000px',
|
|
|
+ 'remember' => false,
|
|
|
];
|
|
|
|
|
|
public function __construct(Form $form)
|
|
|
{
|
|
|
- $this->form = $form;
|
|
|
+ $this->form = $form->saved(function () {
|
|
|
+ $this->flushStash();
|
|
|
+ });
|
|
|
|
|
|
$this->collectAssets();
|
|
|
}
|
|
@@ -111,6 +114,15 @@ class StepBuilder
|
|
|
return $this->option('width', $width);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param bool $value
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function remember(bool $value = true)
|
|
|
+ {
|
|
|
+ return $this->option('remember', $value);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param string|Closure $title
|
|
|
* @param Closure|null $callback
|
|
@@ -163,6 +175,51 @@ class StepBuilder
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array $data
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function stash(array $data)
|
|
|
+ {
|
|
|
+ if (! $this->options['remember']) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ session()->put($this->getStashKey(), $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function fetchStash()
|
|
|
+ {
|
|
|
+ if (! $this->options['remember']) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ return session()->get($this->getStashKey()) ?: [];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function flushStash()
|
|
|
+ {
|
|
|
+ if (! $this->options['remember']) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ session()->remove($this->getStashKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ protected function getStashKey()
|
|
|
+ {
|
|
|
+ return 'step-form-input:'.admin_controller_slug();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return void
|
|
|
*/
|