Skip to content

Commit

Permalink
Fix init of ContentHighlightAsset (#7003)
Browse files Browse the repository at this point in the history
* Fix init of `ContentHighlightAsset`

* Fix build assets for `ContentHighlightAsset`

* Fix assets building
  • Loading branch information
yurabakhtin committed May 16, 2024
1 parent 783b7a0 commit a405027
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
2 changes: 2 additions & 0 deletions protected/humhub/assets/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use humhub\components\assets\WebStaticAssetBundle;
use humhub\modules\content\assets\ContentAsset;
use humhub\modules\content\assets\ContentHighlightAsset;
use humhub\modules\file\assets\FileAsset;
use yii\bootstrap\BootstrapAsset;
use yii\bootstrap\BootstrapPluginAsset;
Expand Down Expand Up @@ -83,6 +84,7 @@ class AppAsset extends WebStaticAssetBundle
*/
CoreApiAsset::class,
ContentAsset::class,
ContentHighlightAsset::class,
FileAsset::class,
];

Expand Down
13 changes: 11 additions & 2 deletions protected/humhub/config/assets-prod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is generated by the "yii asset" command.
* DO NOT MODIFY THIS FILE DIRECTLY.
* @version 2024-03-19 14:36:13
* @version 2024-05-16 10:57:16
*/
return [
'app' => [
Expand Down Expand Up @@ -219,6 +219,14 @@
'app',
],
],
'humhub\\modules\\content\\assets\\ContentHighlightAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'app',
],
],
'humhub\\modules\\file\\assets\\FileAsset' => [
'sourcePath' => null,
'js' => [],
Expand Down Expand Up @@ -253,6 +261,7 @@
'humhub\\assets\\IntersectionObserverPolyfillAsset',
'humhub\\assets\\CoreApiAsset',
'humhub\\modules\\content\\assets\\ContentAsset',
'humhub\\modules\\content\\assets\\ContentHighlightAsset',
'humhub\\modules\\file\\assets\\FileAsset',
'defer',
],
Expand Down Expand Up @@ -523,4 +532,4 @@
'defer',
],
],
];
];
9 changes: 0 additions & 9 deletions protected/humhub/modules/content/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use humhub\commands\CronController;
use humhub\commands\IntegrityController;
use humhub\components\Event;
use humhub\modules\content\assets\ContentHighlightAsset;
use humhub\modules\content\components\ContentActiveRecord;
use humhub\modules\content\models\Content;
use humhub\modules\content\services\ContentSearchService;
Expand Down Expand Up @@ -143,14 +142,6 @@ public static function onCronBeforeAction($event): void
}
}

public static function onViewBeginBody($event)
{
if (Yii::$app->isInstalled()) {
ContentHighlightAsset::register($event->sender);
}
}


private static function canPublishScheduledContent(): bool
{
$lastPublishTime = self::getModule()->settings->get('lastPublishScheduledTS');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use humhub\components\assets\AssetBundle;
use Yii;
use yii\web\Application;

class ContentHighlightAsset extends AssetBundle
{
Expand All @@ -27,16 +28,16 @@ class ContentHighlightAsset extends AssetBundle
/**
* @inheritdoc
*/
public static function register($view)
public function init()
{
if (!Yii::$app->request->isConsoleRequest) {
parent::init();

if (Yii::$app instanceof Application && Yii::$app->isInstalled()) {
$highlight = Yii::$app->session->get('contentHighlight');
if ($highlight !== null && $highlight !== '') {
Yii::$app->session->remove('contentHighlight');
$view->registerJsConfig('content.highlight', ['keyword' => $highlight]);
Yii::$app->view->registerJsConfig('content.highlight', ['keyword' => $highlight]);
}
}

return parent::register($view);
}
}
2 changes: 0 additions & 2 deletions protected/humhub/modules/content/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use humhub\modules\user\models\User;
use humhub\modules\space\models\Space;
use humhub\modules\content\components\ContentActiveRecord;
use yii\web\View;

return [
'id' => 'content',
Expand All @@ -23,7 +22,6 @@
['class' => ContentActiveRecord::class, 'event' => ContentActiveRecord::EVENT_AFTER_DELETE, 'callback' => [Events::class, 'onContentActiveRecordDelete']],
['class' => CronController::class, 'event' => CronController::EVENT_ON_DAILY_RUN, 'callback' => [Events::class, 'onCronDailyRun']],
['class' => CronController::class, 'event' => CronController::EVENT_BEFORE_ACTION, 'callback' => [Events::class, 'onCronBeforeAction']],
['class' => View::class, 'event' => View::EVENT_BEGIN_BODY, 'callback' => [Events::class, 'onViewBeginBody']],
],
'consoleControllerMap' => [
'content-search' => '\humhub\modules\content\commands\SearchController',
Expand Down

0 comments on commit a405027

Please sign in to comment.