Skip to content

Commit

Permalink
🐛 Test for debug module before adding the Elasticsearch panel
Browse files Browse the repository at this point in the history
✨ Give an proper id the the Elasticsearch Debug module panel so that clicking the the ES button in the debug module opens the Elasticsearch tab
Fixes #12
  • Loading branch information
nstCactus committed Sep 30, 2020
1 parent cc26dfc commit 11cd620
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use yii\elasticsearch\DebugPanel;
use yii\elasticsearch\Exception;
use yii\queue\ExecEvent;
use yii\debug\Module as DebugModule;

/**
* @property services\Elasticsearch service
Expand Down Expand Up @@ -204,18 +205,21 @@ function () {
);
}

if (YII_DEBUG) {
// Add the Elasticsearch panel to the Yii debug bar
Event::on(
Application::class,
Application::EVENT_BEFORE_REQUEST,
function () {
/** @var \yii\debug\Module $debugModule */
$debugModule = Craft::$app->getModule('debug');
$debugModule->panels['elasticsearch'] = new DebugPanel(['module' => $debugModule]);
// Add the Elasticsearch panel to the Yii debug bar
Event::on(
Application::class,
Application::EVENT_BEFORE_REQUEST,
function () {
/** @var DebugModule|null $debugModule */
$debugModule = Craft::$app->getModule('debug');
if ($debugModule) {
$debugModule->panels['elasticsearch'] = new DebugPanel([
'id' => 'elasticsearch',
'module' => $debugModule,
]);
}
);
}
}
);

// Register variables
Event::on(
Expand Down

0 comments on commit 11cd620

Please sign in to comment.