Skip to content

Commit

Permalink
Themeの読み込み順変更。bc_form.phpをsetting.phpで変更できるように。 (#3973)
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin4649 authored Nov 7, 2024
1 parent 74b66d7 commit d2efe4f
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 40 deletions.
10 changes: 10 additions & 0 deletions plugins/baser-core/config/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@
*/
'enableRootRoutes' => false,

/**
* bc_formのテンプレートを指定
* config/bc_form.phpを差し替える
* プラグイン記法 (プラグイン名.テンプレート名)
*/
//basercms/plugins/baser-core/src/View/AppView.php
'AppFormTemplate' => 'BaserCore.bc_form',
//basercms/plugins/baser-core/src/View/BcAdminAppView.php
'AdminFormTemplate' => 'BaserCore.bc_form',

/**
* システムナビ
*
Expand Down
119 changes: 84 additions & 35 deletions plugins/baser-core/src/BaserCorePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function bootstrap(PluginApplicationInterface $app): void
}

/**
* プラグインロード
* テーマ・プラグインロード
*/
if (!filter_var(env('USE_DEBUG_KIT', true), FILTER_VALIDATE_BOOLEAN)) {
// 明示的に指定がない場合、DebugKitは重すぎるのでデバッグモードでも利用しない
Expand All @@ -164,19 +164,19 @@ public function bootstrap(PluginApplicationInterface $app): void
}

if (BcUtil::isTest()) $app->addPlugin('CakephpFixtureFactories');
$app->addPlugin('Authentication');
$app->addPlugin('Migrations');

$this->addTheme($app);

$plugins = BcUtil::getEnablePlugins();
if ($plugins) {
foreach($plugins as $plugin) {
if (BcUtil::includePluginClass($plugin->name)) {
$this->loadPlugin($app, $plugin->name, $plugin->priority);
}
}
}
// 利用可能なテーマを取得
$themes = $this->getAvailableThemes();
// プラグインを追加する前にテーマが保有するプラグインのパスをセット
$this->setupThemePlugin($themes);
// テーマが保有するプラグインも含めてプラグインを読み込む
$this->addPlugin($app);
// ======================================================
// テーマはプラグインの後に読み込む
// テーマもプラグインとして扱う場合があるため、
// その場合に、テーマでプラグインの設定等を上書きできるようにする
// ======================================================
$this->addTheme($app, $themes);

/**
* デフォルトテンプレートを設定する
Expand All @@ -194,42 +194,65 @@ public function bootstrap(PluginApplicationInterface $app): void
$event->on(new BcAuthenticationEventListener());
}

/**
* プラグインを追加する
* @param PluginApplicationInterface $app
* @return void
* @checked
* @noTodo
*/
public function addPlugin(PluginApplicationInterface $app): void
{
$app->addPlugin('Authentication');
$app->addPlugin('Migrations');

$plugins = BcUtil::getEnablePlugins();
if(!$plugins) return;
foreach($plugins as $plugin) {
if (!BcUtil::includePluginClass($plugin->name)) continue;
$this->loadPlugin($app, $plugin->name, $plugin->priority);
}
}

/**
* テーマを追加する
*
* テーマ内のプラグインも追加する
*
* @param PluginApplicationInterface $application
* @noTodo
* @checked
*/
public function addTheme(PluginApplicationInterface $application)
public function addTheme(PluginApplicationInterface $application, array $themes): void
{
$application->addPlugin(Inflector::camelize(Configure::read('BcApp.coreAdminTheme'), '-'));
$application->addPlugin(Inflector::camelize(Configure::read('BcApp.coreFrontTheme'), '-'));
if (!BcUtil::isInstalled()) return;
$sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites');
try {
$sites = $sitesTable->find()->where(['Sites.status' => true]);
} catch (MissingConnectionException) {
return;
}

$path = [];
foreach($sites as $site) {
if ($site->theme) {
if(!BcUtil::includePluginClass($site->theme)) continue;
try {
$application->addPlugin($site->theme);
$pluginPath = CorePlugin::path($site->theme) . 'plugins' . DS;
if (!is_dir($pluginPath)) continue;
$path[] = $pluginPath;
} catch (MissingPluginException $e) {
$this->log($e->getMessage());
}
foreach($themes as $theme) {
if(!BcUtil::includePluginClass($theme)) continue;
try {
$application->addPlugin($theme);
} catch (MissingPluginException $e) {
$this->log($e->getMessage());
}
}
// テーマプラグインを追加
}

/**
* テーマが保有するプラグインのパスを追加する
* @param array $themes
* @return void
* @checked
* @noTodo
*/
public function setupThemePlugin(array $themes): void
{
if (!BcUtil::isInstalled()) return;
if(!$themes) return;
foreach($themes as $theme) {
$pluginsPath = CorePlugin::path($theme) . 'plugins' . DS;
if (!is_dir($pluginsPath)) continue;
$path[] = $pluginsPath;
}
if($path) {
Configure::write('App.paths.plugins', array_merge(
Configure::read('App.paths.plugins'),
Expand All @@ -238,6 +261,32 @@ public function addTheme(PluginApplicationInterface $application)
}
}

/**
* 利用可能なテーマを取得する
* @return array
* @checked
* @noTodo
*/
public function getAvailableThemes(): array
{
if (!BcUtil::isInstalled()) return [];
$sitesTable = TableRegistry::getTableLocator()->get('BaserCore.Sites');
try {
$sites = $sitesTable->find()->where(['Sites.status' => true]);
} catch (MissingConnectionException) {
return [];
}
$themes = [];
foreach($sites as $site) {
if ($site->theme) {
if (!is_dir(CorePlugin::path($site->theme))) continue;
if(in_array($site->theme, $themes)) continue;
$themes[] = $site->theme;
}
}
return $themes;
}

/**
* デフォルトテンプレートを設定する
* @checked
Expand Down
3 changes: 2 additions & 1 deletion plugins/baser-core/src/View/AppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use BaserCore\View\Helper\BcToolbarHelper;
use BaserCore\View\Helper\BcUploadHelper;
use Cake\View\View;
use Cake\Core\Configure;
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use BaserCore\Annotation\UnitTest;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function initialize(): void
{
parent::initialize();
$this->addHelper('BaserCore.BcTime');
$this->addHelper('BaserCore.BcForm', ['templates' => 'BaserCore.bc_form']);
$this->addHelper('BaserCore.BcForm', ['templates' => Configure::read('BcApp.AppFormTemplate')]);
$this->addHelper('BaserCore.BcAdmin');
$this->addHelper('BaserCore.BcContents');
$this->addHelper('BaserCore.BcPage');
Expand Down
2 changes: 1 addition & 1 deletion plugins/baser-core/src/View/BcAdminAppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BcAdminAppView extends AppView
public function initialize(): void
{
parent::initialize();
$this->addHelper('BaserCore.BcAdminForm', ['templates' => 'BaserCore.bc_form']);
$this->addHelper('BaserCore.BcAdminForm', ['templates' => Configure::read('BcApp.AdminFormTemplate')]);
$this->addHelper('BaserCore.BcAuth');
$this->addHelper('BaserCore.BcText');
$this->addHelper('BaserCore.BcContents');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* Class PluginTest
* @property BaserCorePlugin $Plugin
*/
class PluginTest extends BcTestCase
class BaserCorePluginTest extends BcTestCase
{
use ScenarioAwareTrait;

Expand Down
9 changes: 8 additions & 1 deletion plugins/bc-mail/config/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@
['name' => 'email', 'title' => 'Eメールアドレス'],
['name' => 'impp', 'title' => 'インスタントメッセージングプロトコルの端点'],
['name' => 'on', 'title' => '自動設定'],
]
],
/**
* bc_formのテンプレートを指定
* config/bc_form.phpを差し替える
* プラグイン記法 (プラグイン名.テンプレート名)
* basercms/plugins/bc-mail/src/View/MailFrontAppView.php
*/
'formTemplate' => 'BaserCore.bc_form'
]
];
3 changes: 2 additions & 1 deletion plugins/bc-mail/src/View/MailFrontAppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace BcMail\View;

use Cake\Core\Configure;
use BaserCore\View\BcFrontAppView;
use BaserCore\Annotation\UnitTest;
use BaserCore\Annotation\NoTodo;
Expand Down Expand Up @@ -39,7 +40,7 @@ public function initialize(): void
parent::initialize();
$this->addHelper('BcMail.Mail');
$this->addHelper('BcMail.Mailfield');
$this->addHelper('BcMail.Mailform', ['templates' => 'BaserCore.bc_form']);
$this->addHelper('BcMail.Mailform', ['templates' => Configure::read('BcMail.formTemplate')]);
}

}

0 comments on commit d2efe4f

Please sign in to comment.