Skip to content

Commit

Permalink
make compatible with different module ids
Browse files Browse the repository at this point in the history
  • Loading branch information
glpzzz committed Mar 16, 2020
1 parent af979da commit a380faa
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 31 deletions.
1 change: 1 addition & 0 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function bootstrap($app)
$module->viewPath = '@daxslab/website/views/backend';
WebsiteAsset::register($app->view);
} else {
WebsiteAsset::register($app->view);
$module->viewPath = $module->viewPath == Yii::getAlias('@daxslab/website/views')
? '@daxslab/website/views/frontend'
: $module->viewPath;
Expand Down
6 changes: 3 additions & 3 deletions controllers/backend/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function actionIndex()
'query' => Yii::$app->website->getMedias()
->orderBy('filename'),
'pagination' => [
'route' => Url::toRoute(['/website/media/index']),
'route' => Url::toRoute(["/{$this->module->id}/media/index"]),
],
]);

Expand Down Expand Up @@ -143,7 +143,7 @@ public function actionDelete($id)
{
$model = $this->findModel($id);
$model->delete();
return $this->redirect(['/website/media/index']);
return $this->redirect(["/{$this->module->id}/media/index"]);
}

/**
Expand All @@ -162,4 +162,4 @@ protected function findModel($id)
throw new NotFoundHttpException(Yii::t('website','The requested page does not exist.'));
}

}
}
12 changes: 6 additions & 6 deletions controllers/backend/MenuItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function actionIndex($menu_id, $language)
{
$menu = Menu::findOne($menu_id);
if ($menu == null || $menu->website_id != Yii::$app->website->id) {
throw new NotFoundHttpException(Yii::t('website','Menu not found'));
throw new NotFoundHttpException(Yii::t('website', 'Menu not found'));
}

$dataProvider = new ArrayDataProvider([
Expand Down Expand Up @@ -74,7 +74,7 @@ public function actionCreate($menu_id, $language)
{
$menu = Menu::findOne($menu_id);
if ($menu == null || $menu->website_id != Yii::$app->website->id) {
throw new NotFoundHttpException(Yii::t('website','Menu not found'));
throw new NotFoundHttpException(Yii::t('website', 'Menu not found'));
}

$model = new MenuItem([
Expand All @@ -84,7 +84,7 @@ public function actionCreate($menu_id, $language)
]);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['/website/menu/update', 'id' => $menu->id]);
return $this->redirect(["/{$this->module->id}/menu/update", 'id' => $menu->id]);
} else {
return $this->render('create', [
'model' => $model,
Expand All @@ -103,7 +103,7 @@ public function actionUpdate($id)
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['/website/menu/update', 'id' => $model->menu_id]);
return $this->redirect(["/{$this->module->id}/menu/update", 'id' => $model->menu_id]);
} else {
return $this->render('update', [
'model' => $model,
Expand Down Expand Up @@ -141,7 +141,7 @@ public function actionDelete($id)
$menu = $model->menu;
$model->delete();

return $this->redirect(['/website/menu/update', 'id' => $menu->id]);
return $this->redirect(["/{$this->module->id}/menu/update", 'id' => $menu->id]);
}

/**
Expand All @@ -157,6 +157,6 @@ protected function findModel($id)
return $model;
}

throw new NotFoundHttpException(Yii::t('website','The requested page does not exist.'));
throw new NotFoundHttpException(Yii::t('website', 'The requested page does not exist.'));
}
}
6 changes: 3 additions & 3 deletions controllers/backend/MetadataDefinitionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function actionCreate($page_type_id)
]);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['/website/page-type/update', 'id' => $model->page_type_id]);
return $this->redirect(["/{$this->module->id}/page-type/update", 'id' => $model->page_type_id]);
}

return $this->render('create', [
Expand All @@ -86,7 +86,7 @@ public function actionUpdate($id)
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['/website/page-type/update', 'id' => $model->page_type_id]);
return $this->redirect(["/{$this->module->id}/page-type/update", 'id' => $model->page_type_id]);
}

return $this->render('update', [
Expand All @@ -106,7 +106,7 @@ public function actionDelete($id)
$model = $this->findModel($id);
$model->delete();

return $this->redirect(['/website/page-type/update', 'id' => $model->page_type_id]);
return $this->redirect(["/{$this->module->id}/page-type/update", 'id' => $model->page_type_id]);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions controllers/backend/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public function actionIndex($parent_id = null)

$parent = isset($parent_id) ? Page::findOne($parent_id) : null;
if ($parent) {
$module = $this->module->id;
$dataProvider->query = $parent->getPages();
$dataProvider->pagination->route = '/website/page/update';
$dataProvider->pagination->route = "/$module/page/update";
$dataProvider->pagination->pageParam = "subpages-{$parent->id}";
} else {
$dataProvider->query = Yii::$app->website->getRootPages();
Expand Down Expand Up @@ -154,7 +155,8 @@ public function actionAddImageToGallery($gallery_id, $image_id)
]);

if ($galleryItem->save()) {
return $this->redirect(['/website/page/update', 'id' => $gallery->id]);
$module = $this->module->id;
return $this->redirect(["/$module/page/update", 'id' => $gallery->id]);
} else {
Yii::$app->response->format = Response::FORMAT_JSON;
return [
Expand Down Expand Up @@ -202,4 +204,4 @@ protected function findModel($id)
throw new NotFoundHttpException(Yii::t('website','The requested page does not exist.'));
}

}
}
3 changes: 2 additions & 1 deletion views/backend/media/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$this->title = Yii::t('website','Media');

$this->params['breadcrumbs'][] = $this->title;
$module = $this->context->module->id;

?>
<div class="content-index">
Expand All @@ -27,7 +28,7 @@
'options' => [
'paramName' => "Media[filename]",
'method' => 'post',
'url' => Url::toRoute(['/website/media/upload']),
'url' => Url::toRoute(["/$module/media/upload"]),
],
]);
?>
Expand Down
3 changes: 2 additions & 1 deletion views/backend/menu-item/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
/* @var $dataProvider ActiveDataProvider */

$website = Yii::$app->website;
$module = $this->context->module->id;

?>
<div class="menu-item-index">

<p>
<?= Html::a(Yii::t('website','New Item'), [
'/website/menu-item/create',
"/$module/menu-item/create",
'menu_id' => $menu->id,
'language' => $language,
]) ?>
Expand Down
5 changes: 3 additions & 2 deletions views/backend/menu/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('website','Menus'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $model->name;
$module = $this->context->module->id;
?>
<div class="menu-update">

Expand All @@ -22,10 +23,10 @@
]) ?>

<?= \yii\bootstrap4\Tabs::widget([
'items' => array_map(function ($item) use($model) {
'items' => array_map(function ($item) use($model, $module) {
return [
'label' => $item,
'content' => Yii::$app->runAction('website/menu-item/index', ['menu_id' => $model->id, 'language' => $item])
'content' => Yii::$app->runAction("/$module/menu-item/index", ['menu_id' => $model->id, 'language' => $item])
];
}, $this->context->module->languages)
]) ?>
Expand Down
4 changes: 2 additions & 2 deletions views/backend/metadata-definition/_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use yii\helpers\Html;


$module = $this->context->module->id;
?>

<li id="<?= $model->id ?>">
<h3><?= Html::a(Html::encode($model->name), ['/website/metadata-definition/update', 'id' => $model->id]) ?></h3>
<h3><?= Html::a(Html::encode($model->name), ["/$module/metadata-definition/update", 'id' => $model->id]) ?></h3>
<p><?= $model->type ?></p>
</li>

4 changes: 3 additions & 1 deletion views/backend/page-type/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
$this->params['breadcrumbs'][] = ['label' => Yii::t('website','Settings'), 'url' => ['website/update']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('website','Page Types'), 'url' => ['website/update', '#' => 'page-types']];
$this->params['breadcrumbs'][] = $model->name;

$module = $this->context->module->id;
?>
<div class="page-type-update">

Expand All @@ -22,6 +24,6 @@
'model' => $model,
]) ?>

<?= Yii::$app->runAction('/website/metadata-definition/index', ['page_type_id' => $model->id]) ?>
<?= Yii::$app->runAction("/$module/metadata-definition/index", ['page_type_id' => $model->id]) ?>

</div>
9 changes: 5 additions & 4 deletions views/backend/page/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$defaultImage = Yii::getAlias('@web/images/no-image.png');
$currentWebsite = Yii::$app->website;

$module = $this->context->module->id;

?>
<div class="form">
Expand Down Expand Up @@ -44,7 +45,7 @@
'preset' => 'full',
'clientOptions' => [
'extraPlugins' => 'showprotected,imagebrowser,showblocks,pastefromword,div,find,save,clipboard',
'imageBrowser_listUrl' => \yii\helpers\Url::to(['/website/media/get-images-for-gallery']),
'imageBrowser_listUrl' => \yii\helpers\Url::to(["/$module/media/get-images-for-gallery"]),
'imageBrowser_pluginPath' => Yii::$app->assetManager->bundles[\daxslab\website\WebsiteAsset::class]->baseUrl,
'allowedContent' => true,
'contentsCss' => [
Expand Down Expand Up @@ -72,7 +73,7 @@

<?= $model->id == null
? Html::tag('div', Yii::t('website', 'You must save this page before adding subpages'), ['class' => 'alert alert-info'])
: Yii::$app->runAction('/website/page/index', [
: Yii::$app->runAction("/{$module}/page/index", [
'parent_id' => $model->id,
'language' => $model->language,
]) ?>
Expand Down Expand Up @@ -121,7 +122,7 @@
])
?>

<?= Yii::$app->runAction('/website/media/images-gallery') ?>
<?= Yii::$app->runAction("/$module/media/images-gallery") ?>

<?php \yii\bootstrap4\Modal::end() ?>
</div>
Expand Down Expand Up @@ -153,4 +154,4 @@

<?php ActiveForm::end(); ?>

</div><!-- _form -->
</div><!-- _form -->
3 changes: 2 additions & 1 deletion views/backend/page/_list-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/** @var $language string */
/** @var $dataProvider \yii\data\ArrayDataProvider */

$module = $this->context->module->id;
?>

<header class="mb-4">
Expand All @@ -31,7 +32,7 @@
])
?>

<?= Yii::$app->runAction('/website/media/images-gallery') ?>
<?= Yii::$app->runAction("/$module/media/images-gallery") ?>

<?php \yii\bootstrap4\Modal::end() ?>

Expand Down
3 changes: 2 additions & 1 deletion views/backend/page/_view-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use yii\helpers\Html;

$context = $this->context;
$module = $context->module->id;

$thumbnailer = Yii::$app->thumbnailer;

Expand All @@ -14,7 +15,7 @@
<div class="card">
<?= Html::a(Html::img($image, ['class' => 'img-fluid'])) ?>
<div class="card-footer">
<?= Html::a(Yii::t('website','Delete'), ['/website/page/delete', 'id' => $model->id], [
<?= Html::a(Yii::t('website','Delete'), ["/$module/page/delete", 'id' => $model->id], [
'class' => 'btn btn-danger btn-block',
'data-method' => 'post',
'data-confirm' => Yii::t('website','Are you sure you want to delete this item?')
Expand Down
3 changes: 2 additions & 1 deletion views/backend/website/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

$this->title = Yii::t('website','Settings');
$this->params['breadcrumbs'][] = $this->title;
$module = $this->context->module->id;
?>
<div class="website-update">

Expand All @@ -18,6 +19,6 @@
'model' => $model,
]) ?>

<?= Yii::$app->runAction('/website/page-type/index') ?>
<?= Yii::$app->runAction("/$module/page-type/index") ?>

</div>
5 changes: 3 additions & 2 deletions widgets/PageWidgetizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ protected function node2Block($node){
throw new \ErrorException('"slug" or "action" must be set in block nodes');
}

$action = $action ?: "/website/block/view";
$module = $this->view->context->module->id;
$action = $action ?: "/$module/block/view";

foreach($node->attributes as $attribute){
$params[$attribute->name] = $attribute->value;
Expand Down Expand Up @@ -89,4 +90,4 @@ protected function node2Widget($node)

return $className::widget($config);
}
}
}

0 comments on commit a380faa

Please sign in to comment.