Skip to content

Commit 55b07cd

Browse files
committed
URL redirect notify in views
1 parent 91e414b commit 55b07cd

File tree

10 files changed

+147
-21
lines changed

10 files changed

+147
-21
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Changelog
22
=========
33

44
## 1.2.*
5+
* URL redirect notify in views
56
* Added `defaultController` property for module
67

78
## 1.2.2 (2020-04-28)

Diff for: views/cats/_form.php

+12
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@
4747
]
4848
])->label(Yii::t('app/modules/blog', 'Category URL')); ?>
4949

50+
<?php
51+
if (isset(Yii::$app->redirects) && $model->url && ($model->status == $model::STATUS_PUBLISHED)) {
52+
if ($url = Yii::$app->redirects->check($model->url, false)) {
53+
echo Html::tag('div', Yii::t('app/modules/redirects', 'For this URL is active redirect to {url}', [
54+
'url' => $url
55+
]), [
56+
'class' => "alert alert-warning"
57+
]);
58+
}
59+
}
60+
?>
61+
5062
<div class="panel panel-default">
5163
<div class="panel-heading">
5264
<h6 class="panel-title">

Diff for: views/cats/index.php

+23-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/* @var $model wdmg\blog\models\Categories */
1212

1313
$this->title = Yii::t('app/modules/blog', 'All categories');
14-
$this->params['breadcrumbs'][] = ['label' => Yii::t('app/modules/blog', 'Blog'), 'url' => ['posts/index']];
14+
$this->params['breadcrumbs'][] = ['label' => Yii::t('app/modules/blog', 'Blog'), 'url' => ['cats/index']];
1515
$this->params['breadcrumbs'][] = $this->title;
1616

1717
if (isset(Yii::$app->translations) && class_exists('\wdmg\translations\FlagsAsset')) {
@@ -44,9 +44,24 @@
4444
$output .= (($model->id === 1) ? " <span class=\"text-muted\">(" . Yii::t('app/modules/blog', 'default') . ")</span>" : "");
4545
if (($categoryURL = $model->getCategoryUrl(true, true)) && $model->id) {
4646
$output .= '<br/>' . Html::a($model->getUrl(true), $categoryURL, [
47-
'target' => '_blank',
48-
'data-pjax' => 0
47+
'target' => '_blank',
48+
'data-pjax' => 0
49+
]);
50+
}
51+
52+
if (isset(Yii::$app->redirects) && $model->url && ($model->status == $model::STATUS_PUBLISHED)) {
53+
if ($url = Yii::$app->redirects->check($model->url, false)) {
54+
$output .= '&nbsp' . Html::tag('span', '', [
55+
'class' => "text-danger fa fa-exclamation-circle",
56+
'data' => [
57+
'toggle' => "tooltip",
58+
'placement' => "top"
59+
],
60+
'title' => Yii::t('app/modules/redirects', 'For this URL is active redirect to {url}', [
61+
'url' => $url
62+
])
4963
]);
64+
}
5065
}
5166
return $output;
5267
}
@@ -109,7 +124,7 @@
109124
'format' => 'html',
110125
'value' => function($data) {
111126
if ($posts = $data->posts) {
112-
return Html::a(count($posts), ['posts/index', 'cat_id' => $data->id]);
127+
return Html::a(count($posts), ['cats/index', 'cat_id' => $data->id]);
113128
} else {
114129
return 0;
115130
}
@@ -151,7 +166,7 @@
151166
if ($data->locale === $locale['locale']) // It`s source version
152167
$output[] = Html::a($flag,
153168
[
154-
'posts/update', 'id' => $data->id
169+
'cats/update', 'id' => $data->id
155170
], [
156171
'title' => Yii::t('app/modules/blog','Edit source version: {language}', [
157172
'language' => $locale['name']
@@ -161,7 +176,7 @@
161176
else // Other localization versions
162177
$output[] = Html::a($flag,
163178
[
164-
'posts/update', 'id' => $data->id,
179+
'cats/update', 'id' => $data->id,
165180
'locale' => $locale['locale']
166181
], [
167182
'title' => Yii::t('app/modules/blog','Edit language version: {language}', [
@@ -186,7 +201,7 @@
186201
if ($data->locale === $locale) // It`s source version
187202
$output[] = Html::a($language,
188203
[
189-
'news/update', 'id' => $data->id
204+
'cats/update', 'id' => $data->id
190205
], [
191206
'title' => Yii::t('app/modules/blog','Edit source version: {language}', [
192207
'language' => $language
@@ -196,7 +211,7 @@
196211
else // Other localization versions
197212
$output[] = Html::a($language,
198213
[
199-
'news/update', 'id' => $data->id,
214+
'cats/update', 'id' => $data->id,
200215
'locale' => $locale
201216
], [
202217
'title' => Yii::t('app/modules/blog','Edit language version: {language}', [

Diff for: views/cats/view.php

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@
3838
'data-pjax' => 0
3939
]);
4040
}
41+
42+
if (isset(Yii::$app->redirects) && $model->url && ($model->status == $model::STATUS_PUBLISHED)) {
43+
if ($url = Yii::$app->redirects->check($model->url, false)) {
44+
$output .= '&nbsp' . Html::tag('span', '', [
45+
'class' => "text-danger fa fa-exclamation-circle",
46+
'data' => [
47+
'toggle' => "tooltip",
48+
'placement' => "top"
49+
],
50+
'title' => Yii::t('app/modules/redirects', 'For this URL is active redirect to {url}', [
51+
'url' => $url
52+
])
53+
]);
54+
}
55+
}
4156
return $output;
4257
}
4358
],

Diff for: views/posts/_form.php

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@
5252
]
5353
])->label(Yii::t('app/modules/blog', 'Post URL')); ?>
5454

55+
<?php
56+
if (isset(Yii::$app->redirects) && $model->url && ($model->status == $model::STATUS_PUBLISHED)) {
57+
if ($url = Yii::$app->redirects->check($model->url, false)) {
58+
echo Html::tag('div', Yii::t('app/modules/redirects', 'For this URL is active redirect to {url}', [
59+
'url' => $url
60+
]), [
61+
'class' => "alert alert-warning"
62+
]);
63+
}
64+
}
65+
?>
66+
5567
<?= $form->field($model, 'excerpt')->textarea(['rows' => 3]) ?>
5668
<?= $form->field($model, 'content')->widget(Editor::class, [
5769
'options' => [

Diff for: views/posts/index.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,24 @@
4242
$output = Html::tag('strong', $model->name);
4343
if (($postURL = $model->getPostUrl(true, true)) && $model->id) {
4444
$output .= '<br/>' . Html::a($model->getUrl(true), $postURL, [
45-
'target' => '_blank',
46-
'data-pjax' => 0
45+
'target' => '_blank',
46+
'data-pjax' => 0
47+
]);
48+
}
49+
50+
if (isset(Yii::$app->redirects) && $model->url && ($model->status == $model::STATUS_PUBLISHED)) {
51+
if ($url = Yii::$app->redirects->check($model->url, false)) {
52+
$output .= '&nbsp' . Html::tag('span', '', [
53+
'class' => "text-danger fa fa-exclamation-circle",
54+
'data' => [
55+
'toggle' => "tooltip",
56+
'placement' => "top"
57+
],
58+
'title' => Yii::t('app/modules/redirects', 'For this URL is active redirect to {url}', [
59+
'url' => $url
60+
])
4761
]);
62+
}
4863
}
4964
return $output;
5065
}
@@ -268,7 +283,7 @@
268283
if ($data->locale === $locale) // It`s source version
269284
$output[] = Html::a($language,
270285
[
271-
'news/update', 'id' => $data->id
286+
'posts/update', 'id' => $data->id
272287
], [
273288
'title' => Yii::t('app/modules/blog','Edit source version: {language}', [
274289
'language' => $language
@@ -278,7 +293,7 @@
278293
else // Other localization versions
279294
$output[] = Html::a($language,
280295
[
281-
'news/update', 'id' => $data->id,
296+
'posts/update', 'id' => $data->id,
282297
'locale' => $locale
283298
], [
284299
'title' => Yii::t('app/modules/blog','Edit language version: {language}', [

Diff for: views/posts/view.php

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@
3737
'data-pjax' => 0
3838
]);
3939
}
40+
41+
if (isset(Yii::$app->redirects) && $model->url && ($model->status == $model::STATUS_PUBLISHED)) {
42+
if ($url = Yii::$app->redirects->check($model->url, false)) {
43+
$output .= '&nbsp' . Html::tag('span', '', [
44+
'class' => "text-danger fa fa-exclamation-circle",
45+
'data' => [
46+
'toggle' => "tooltip",
47+
'placement' => "top"
48+
],
49+
'title' => Yii::t('app/modules/redirects', 'For this URL is active redirect to {url}', [
50+
'url' => $url
51+
])
52+
]);
53+
}
54+
}
4055
return $output;
4156
}
4257
],

Diff for: views/tags/_form.php

+12
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@
4848
]
4949
])->label(Yii::t('app/modules/blog', 'Tag URL')); ?>
5050

51+
<?php
52+
if (isset(Yii::$app->redirects) && $model->url && ($model->status == $model::STATUS_PUBLISHED)) {
53+
if ($url = Yii::$app->redirects->check($model->url, false)) {
54+
echo Html::tag('div', Yii::t('app/modules/redirects', 'For this URL is active redirect to {url}', [
55+
'url' => $url
56+
]), [
57+
'class' => "alert alert-warning"
58+
]);
59+
}
60+
}
61+
?>
62+
5163
<div class="panel panel-default">
5264
<div class="panel-heading">
5365
<h6 class="panel-title">

Diff for: views/tags/index.php

+23-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/* @var $model wdmg\blog\models\Tags */
1212

1313
$this->title = Yii::t('app/modules/blog', 'All tags');
14-
$this->params['breadcrumbs'][] = ['label' => Yii::t('app/modules/blog', 'Blog'), 'url' => ['posts/index']];
14+
$this->params['breadcrumbs'][] = ['label' => Yii::t('app/modules/blog', 'Blog'), 'url' => ['tags/index']];
1515
$this->params['breadcrumbs'][] = $this->title;
1616

1717
if (isset(Yii::$app->translations) && class_exists('\wdmg\translations\FlagsAsset')) {
@@ -43,9 +43,24 @@
4343
$output = Html::tag('strong', $model->name);
4444
if (($tagURL = $model->getTagUrl(true, true)) && $model->id) {
4545
$output .= '<br/>' . Html::a($model->getUrl(true), $tagURL, [
46-
'target' => '_blank',
47-
'data-pjax' => 0
46+
'target' => '_blank',
47+
'data-pjax' => 0
48+
]);
49+
}
50+
51+
if (isset(Yii::$app->redirects) && $model->url && ($model->status == $model::STATUS_PUBLISHED)) {
52+
if ($url = Yii::$app->redirects->check($model->url, false)) {
53+
$output .= '&nbsp' . Html::tag('span', '', [
54+
'class' => "text-danger fa fa-exclamation-circle",
55+
'data' => [
56+
'toggle' => "tooltip",
57+
'placement' => "top"
58+
],
59+
'title' => Yii::t('app/modules/redirects', 'For this URL is active redirect to {url}', [
60+
'url' => $url
61+
])
4862
]);
63+
}
4964
}
5065
return $output;
5166
}
@@ -108,7 +123,7 @@
108123
'format' => 'html',
109124
'value' => function($data) {
110125
if ($posts = $data->posts) {
111-
return Html::a(count($posts), ['posts/index', 'tag_id' => $data->id]);
126+
return Html::a(count($posts), ['tags/index', 'tag_id' => $data->id]);
112127
} else {
113128
return 0;
114129
}
@@ -150,7 +165,7 @@
150165
if ($data->locale === $locale['locale']) // It`s source version
151166
$output[] = Html::a($flag,
152167
[
153-
'posts/update', 'id' => $data->id
168+
'tags/update', 'id' => $data->id
154169
], [
155170
'title' => Yii::t('app/modules/blog','Edit source version: {language}', [
156171
'language' => $locale['name']
@@ -160,7 +175,7 @@
160175
else // Other localization versions
161176
$output[] = Html::a($flag,
162177
[
163-
'posts/update', 'id' => $data->id,
178+
'tags/update', 'id' => $data->id,
164179
'locale' => $locale['locale']
165180
], [
166181
'title' => Yii::t('app/modules/blog','Edit language version: {language}', [
@@ -185,7 +200,7 @@
185200
if ($data->locale === $locale) // It`s source version
186201
$output[] = Html::a($language,
187202
[
188-
'news/update', 'id' => $data->id
203+
'tags/update', 'id' => $data->id
189204
], [
190205
'title' => Yii::t('app/modules/blog','Edit source version: {language}', [
191206
'language' => $language
@@ -195,7 +210,7 @@
195210
else // Other localization versions
196211
$output[] = Html::a($language,
197212
[
198-
'news/update', 'id' => $data->id,
213+
'tags/update', 'id' => $data->id,
199214
'locale' => $locale
200215
], [
201216
'title' => Yii::t('app/modules/blog','Edit language version: {language}', [
@@ -225,7 +240,6 @@
225240
return null;
226241
}
227242
],
228-
229243
[
230244
'class' => 'yii\grid\ActionColumn',
231245
'header' => Yii::t('app/modules/blog','Actions'),

Diff for: views/tags/view.php

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@
3838
'data-pjax' => 0
3939
]);
4040
}
41+
42+
if (isset(Yii::$app->redirects) && $model->url && ($model->status == $model::STATUS_PUBLISHED)) {
43+
if ($url = Yii::$app->redirects->check($model->url, false)) {
44+
$output .= '&nbsp' . Html::tag('span', '', [
45+
'class' => "text-danger fa fa-exclamation-circle",
46+
'data' => [
47+
'toggle' => "tooltip",
48+
'placement' => "top"
49+
],
50+
'title' => Yii::t('app/modules/redirects', 'For this URL is active redirect to {url}', [
51+
'url' => $url
52+
])
53+
]);
54+
}
55+
}
4156
return $output;
4257
}
4358
],

0 commit comments

Comments
 (0)