2024-03-13 16:54:10 -04:00
|
|
|
<?php
|
|
|
|
|
2024-11-03 04:20:53 -05:00
|
|
|
namespace App\BlueprintFramework\Controllers;
|
2024-03-13 16:54:10 -04:00
|
|
|
|
2024-11-03 04:20:53 -05:00
|
|
|
use App\Http\Controllers\Controller;
|
2024-03-13 16:54:10 -04:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2024-11-03 04:20:53 -05:00
|
|
|
use App\Http\Requests\Admin\AdminFormRequest;
|
|
|
|
use App\Contracts\Repository\SettingsRepositoryInterface;
|
2024-03-13 16:54:10 -04:00
|
|
|
|
|
|
|
class ExtensionConfigurationController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* BlueprintExtensionController constructor.
|
|
|
|
*/
|
2024-03-19 12:34:45 -04:00
|
|
|
public function __construct(private SettingsRepositoryInterface $settings,) {}
|
2024-03-13 16:54:10 -04:00
|
|
|
|
|
|
|
/**
|
2024-11-03 04:20:53 -05:00
|
|
|
* @throws \App\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \App\Exceptions\Repository\RecordNotFoundException
|
2024-03-13 16:54:10 -04:00
|
|
|
*/
|
2024-03-13 16:59:45 -04:00
|
|
|
public function update(ExtensionConfigurationRequest $request): RedirectResponse
|
2024-03-13 16:54:10 -04:00
|
|
|
{
|
2024-04-08 07:17:29 -04:00
|
|
|
// set extension eggs to be -1 (Show all), then overwrite if needed
|
|
|
|
$this->settings->set('blueprint::extensionconfig_' . $request->input('_identifier', 'blueprint') . '_eggs', '["-1"]');
|
|
|
|
|
|
|
|
foreach ($request->normalize() as $key => $value) {
|
|
|
|
if (str_ends_with($key, '_eggs')) {
|
|
|
|
// if there are other eggs set, remove the -1 'egg'
|
|
|
|
$eggs = (array)$value['*'];
|
|
|
|
if (count($eggs) > 1 && in_array('-1', $eggs)) {
|
|
|
|
$eggs = array_diff($eggs, ['-1']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = json_encode(array_values($eggs));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->settings->set('blueprint::extensionconfig_' . $key, $value);
|
|
|
|
}
|
|
|
|
|
2024-03-13 16:54:10 -04:00
|
|
|
return redirect()->route('admin.extensions.'.$request->input('_identifier', 'blueprint').'.index');
|
|
|
|
}
|
2024-03-13 16:59:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class ExtensionConfigurationRequest extends AdminFormRequest
|
|
|
|
{
|
|
|
|
public function rules(): array {
|
|
|
|
return [
|
2024-03-19 12:34:45 -04:00
|
|
|
$this->input('_identifier', 'blueprint').'_adminlayouts' => 'boolean',
|
|
|
|
$this->input('_identifier', 'blueprint').'_dashboardwrapper' => 'boolean',
|
2024-04-08 07:17:29 -04:00
|
|
|
$this->input('_identifier', 'blueprint').'_eggs' => 'array',
|
|
|
|
$this->input('_identifier', 'blueprint').'_eggs.*' => 'numeric',
|
2024-03-13 16:59:45 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attributes(): array {
|
|
|
|
return [
|
2024-03-19 12:34:45 -04:00
|
|
|
$this->input('_identifier', 'blueprint').'_adminlayouts' => 'admin layouts permission',
|
|
|
|
$this->input('_identifier', 'blueprint').'_dashboardwrapper' => 'dashboard wrapper permission',
|
2024-03-13 16:59:45 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|