| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace Dcat\Admin\Extend;
- use Dcat\Admin\Admin;
- use Dcat\Admin\Contracts\LazyRenderable;
- use Dcat\Admin\Traits\LazyWidget;
- use Dcat\Admin\Widgets\Form;
- abstract class Setting extends Form implements LazyRenderable
- {
- use LazyWidget;
- /**
- * @var ServiceProvider
- */
- protected $extension;
- public function __construct(ServiceProvider $extension = null)
- {
- parent::__construct();
- $this->initExtension($extension);
- }
- protected function initExtension(?ServiceProvider $extension)
- {
- if ($extension) {
- $this->extension = $extension;
- $this->payload(['_extension_' => $extension->getName()]);
- }
- }
- /**
- * 处理请求.
- *
- * @param array $input
- *
- * @return \Dcat\Admin\Http\JsonResponse
- */
- public function handle(array $input)
- {
- $this->extension()->config($this->formatInput($input));
- return $this->response()->success(trans('admin.save_succeeded'));
- }
- /**
- * 格式化配置信息.
- *
- * @param array $input
- *
- * @return array
- */
- protected function formatInput(array $input)
- {
- return $input;
- }
- /**
- * 表单字段定义.
- *
- * @return void
- */
- abstract public function form();
- /**
- * 填充表单数据.
- *
- * @return array
- */
- public function default()
- {
- return $this->extension()->config() ?: [];
- }
- /**
- * @return ServiceProvider
- */
- public function extension()
- {
- if (! empty($this->payload['_extension_'])) {
- return Admin::extension()->get($this->payload['_extension_']);
- }
- return $this->extension;
- }
- }
|