Support specifying enchants.config in plugin
This commit is contained in:
parent
4cc7b4441f
commit
776e8652a0
|
|
@ -11,8 +11,14 @@ class PluginController extends Controller
|
|||
public function config(PluginManager $plugins, $name)
|
||||
{
|
||||
$plugin = $plugins->get($name);
|
||||
if ($plugin && $plugin->isEnabled() && $plugin->hasConfigView()) {
|
||||
return $plugin->getConfigView();
|
||||
if ($plugin && $plugin->isEnabled()) {
|
||||
if ($plugin->hasConfigClass()) {
|
||||
return app()->call($plugin->getConfigClass().'@render');
|
||||
} elseif ($plugin->hasConfigView()) {
|
||||
return $plugin->getConfigView();
|
||||
} else {
|
||||
return abort(404, trans('admin.plugins.operations.no-config-notice'));
|
||||
}
|
||||
} else {
|
||||
return abort(404, trans('admin.plugins.operations.no-config-notice'));
|
||||
}
|
||||
|
|
@ -89,7 +95,7 @@ class PluginController extends Controller
|
|||
'version' => $plugin->version,
|
||||
'url' => $plugin->url,
|
||||
'enabled' => $plugin->isEnabled(),
|
||||
'config' => $plugin->hasConfigView(),
|
||||
'config' => $plugin->hasConfig(),
|
||||
'dependencies' => [
|
||||
'all' => $plugin->require,
|
||||
'unsatisfied' => $plugins->getUnsatisfied($plugin),
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class SideMenuComposer
|
|||
$pluginConfigs = resolve(PluginManager::class)
|
||||
->getEnabledPlugins()
|
||||
->filter(function ($plugin) {
|
||||
return $plugin->hasConfigView();
|
||||
return $plugin->hasConfig();
|
||||
})
|
||||
->map(function ($plugin) {
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -58,6 +58,23 @@ class Plugin
|
|||
return "$baseUrl/{$this->name}/assets/$relativeUri?v=".$this->version;
|
||||
}
|
||||
|
||||
public function hasConfig(): bool
|
||||
{
|
||||
return $this->hasConfigClass() || $this->hasConfigView();
|
||||
}
|
||||
|
||||
public function hasConfigClass(): bool
|
||||
{
|
||||
return Arr::has($this->manifest, 'enchants.config');
|
||||
}
|
||||
|
||||
public function getConfigClass()
|
||||
{
|
||||
$name = Arr::get($this->manifest, 'enchants.config');
|
||||
|
||||
return Str::start($name, $this->manifest['namespace'].'\\');
|
||||
}
|
||||
|
||||
public function getViewPath(string $filename): string
|
||||
{
|
||||
return $this->path."/views/$filename";
|
||||
|
|
|
|||
|
|
@ -50,15 +50,25 @@ class PluginControllerTest extends TestCase
|
|||
->with('fake4')
|
||||
->once()
|
||||
->andReturn($plugin);
|
||||
|
||||
$plugin = new Plugin(resource_path(''), [
|
||||
'namespace' => 'App\\Services',
|
||||
'enchants' => [
|
||||
'config' => 'OptionForm',
|
||||
],
|
||||
]);
|
||||
$plugin->setEnabled(true);
|
||||
$mock->shouldReceive('get')
|
||||
->with('fake5')
|
||||
->once()
|
||||
->andReturn($plugin);
|
||||
});
|
||||
|
||||
// No such plugin.
|
||||
$this->get('/admin/plugins/config/fake1')
|
||||
->assertNotFound();
|
||||
$this->get('/admin/plugins/config/fake1')->assertNotFound();
|
||||
|
||||
// Plugin is disabled
|
||||
$this->get('/admin/plugins/config/fake2')
|
||||
->assertNotFound();
|
||||
$this->get('/admin/plugins/config/fake2')->assertNotFound();
|
||||
|
||||
// Plugin is enabled but it doesn't have config view
|
||||
$this->get('/admin/plugins/config/fake3')
|
||||
|
|
@ -66,8 +76,14 @@ class PluginControllerTest extends TestCase
|
|||
->assertNotFound();
|
||||
|
||||
// Plugin has config view
|
||||
$this->get('/admin/plugins/config/fake4')
|
||||
->assertSuccessful();
|
||||
$this->get('/admin/plugins/config/fake4')->assertSuccessful();
|
||||
|
||||
// Plugin has config class
|
||||
app()->instance(
|
||||
\App\Services\OptionForm::class,
|
||||
new \App\Services\OptionForm('t')
|
||||
);
|
||||
$this->get('/admin/plugins/config/fake5')->assertSee('card');
|
||||
|
||||
option(['plugins_enabled' => '[]']);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user