mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-10-26 00:36:31 +02:00
Fixed disabling/enabling plugin from the list breaking the plugin configuration
This commit is contained in:
@@ -12,6 +12,6 @@ insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# 2 space indentation
|
||||
[*.{yaml,.yml}]
|
||||
indent_size = 2
|
||||
# 4 space indentation
|
||||
[*.php]
|
||||
indent_size = 4
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
* Fixed persistent focus on Folder field when Adding page (Safari) [#2209](https://github.com/getgrav/grav-plugin-admin/issues/2209)
|
||||
* Fixed performance of Plugins / Themes sort in the installation table
|
||||
* Fixed list field with key/value pairs throwing an exception due to bad value [#2199](https://github.com/getgrav/grav-plugin-admin/issues/2199)
|
||||
* Fixed disabling/enabling plugin from the list breaking the plugin configuration
|
||||
|
||||
# v1.10.29
|
||||
## 01/28/2022
|
||||
|
||||
@@ -22,6 +22,7 @@ use Grav\Common\Page\Medium\Medium;
|
||||
use Grav\Common\Page\Page;
|
||||
use Grav\Common\Page\Pages;
|
||||
use Grav\Common\Page\Collection;
|
||||
use Grav\Common\Plugins;
|
||||
use Grav\Common\Security;
|
||||
use Grav\Common\User\Interfaces\UserCollectionInterface;
|
||||
use Grav\Common\User\Interfaces\UserInterface;
|
||||
@@ -35,6 +36,7 @@ use PicoFeed\Parser\MalformedXmlException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\File\File;
|
||||
use RocketTheme\Toolbox\File\YamlFile;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
|
||||
@@ -629,10 +631,8 @@ class AdminController extends AdminBaseController
|
||||
return false;
|
||||
}
|
||||
|
||||
// Filter value and save it.
|
||||
$this->post = ['enabled' => true];
|
||||
$obj = $this->prepareData($this->post);
|
||||
$obj->save();
|
||||
$type = $this->getDataType();
|
||||
$this->updatePluginState($type, ['enabled' => true]);
|
||||
|
||||
$this->post = ['_redirect' => 'plugins'];
|
||||
if ($this->grav['uri']->param('redirect')) {
|
||||
@@ -662,10 +662,8 @@ class AdminController extends AdminBaseController
|
||||
return false;
|
||||
}
|
||||
|
||||
// Filter value and save it.
|
||||
$this->post = ['enabled' => false];
|
||||
$obj = $this->prepareData($this->post);
|
||||
$obj->save();
|
||||
$type = $this->getDataType();
|
||||
$this->updatePluginState($type, ['enabled' => false]);
|
||||
|
||||
$this->post = ['_redirect' => 'plugins'];
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_DISABLED_PLUGIN'), 'info');
|
||||
@@ -675,6 +673,30 @@ class AdminController extends AdminBaseController
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param array $value
|
||||
* @return void
|
||||
*/
|
||||
protected function updatePluginState(string $type, array $value): void
|
||||
{
|
||||
$obj = Plugins::get(preg_replace('|plugins/|', '', $type));
|
||||
if (null === $obj) {
|
||||
throw new \RuntimeException("Plugin '{$type}' doesn't exist!");
|
||||
}
|
||||
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = $this->grav['locator'];
|
||||
|
||||
// Configuration file will be saved to the existing config stream.
|
||||
$filename = $locator->findResource('config://') . "/{$type}.yaml";
|
||||
|
||||
$file = YamlFile::instance($filename);
|
||||
$contents = $value + $file->content();
|
||||
|
||||
$file->save($contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default theme.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user