mirror of
https://github.com/flarum/core.git
synced 2025-10-12 23:44:27 +02:00
Merge pull request #1032 from dav-is/patch-1
Prevent deletion of default/all locale(s)
This commit is contained in:
@@ -106,6 +106,7 @@ class CoreServiceProvider extends AbstractServiceProvider
|
||||
|
||||
$events->subscribe('Flarum\Core\Listener\DiscussionMetadataUpdater');
|
||||
$events->subscribe('Flarum\Core\Listener\UserMetadataUpdater');
|
||||
$events->subscribe('Flarum\Core\Listener\ExtensionValidator');
|
||||
$events->subscribe('Flarum\Core\Listener\EmailConfirmationMailer');
|
||||
$events->subscribe('Flarum\Core\Listener\DiscussionRenamedNotifier');
|
||||
|
||||
|
42
src/Core/Listener/ExtensionValidator.php
Normal file
42
src/Core/Listener/ExtensionValidator.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Core\Listener;
|
||||
|
||||
use Flarum\Event\ExtensionWillBeDisabled;
|
||||
use Flarum\Http\Exception\MethodNotAllowedException;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class ExtensionValidator
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ExtensionWillBeDisabled::class, [$this, 'whenExtensionWillBeDisabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ExtensionWillBeDisabled $event
|
||||
* @throws MethodNotAllowedException
|
||||
*/
|
||||
public function whenExtensionWillBeDisabled(ExtensionWillBeDisabled $event)
|
||||
{
|
||||
if (in_array('flarum-locale', $event->extension->extra)) {
|
||||
$default_locale = $this->app->make('flarum.settings')->get('default_locale');
|
||||
$locale = array_get($event->extension->extra, 'flarum-locale.code');
|
||||
if ($locale === $default_locale) {
|
||||
throw new MethodNotAllowedException('You cannot disable the default language pack!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user