diff --git a/common/modules/blog/entities/BlogCategory.php b/common/modules/blog/entities/BlogCategory.php index 619dcea..56189ca 100644 --- a/common/modules/blog/entities/BlogCategory.php +++ b/common/modules/blog/entities/BlogCategory.php @@ -3,6 +3,7 @@ namespace common\modules\blog\entities; use core\behaviors\MetaBehavior; +use yii\behaviors\SluggableBehavior; use core\entities\Meta; use yii\db\ActiveRecord; use Yii; @@ -82,7 +83,13 @@ class BlogCategory extends ActiveRecord public function behaviors(): array { return [ - MetaBehavior::className(), + MetaBehavior::class, + [ + 'class' => SluggableBehavior::class, + 'attribute' => 'title', + 'ensureUnique' => true, + 'preserveNonEmptyValues' => true, + ], ]; } } \ No newline at end of file diff --git a/common/modules/blog/entities/BlogPost.php b/common/modules/blog/entities/BlogPost.php index 22abb1c..4f2efc7 100644 --- a/common/modules/blog/entities/BlogPost.php +++ b/common/modules/blog/entities/BlogPost.php @@ -4,7 +4,6 @@ namespace common\modules\blog\entities; use common\modules\blog\entities\queries\BlogPostQuery; use core\behaviors\MetaBehavior; -use core\behaviors\RevisionBehavior; use core\entities\Meta; use lhs\Yii2SaveRelationsBehavior\SaveRelationsBehavior; use yii\behaviors\TimestampBehavior; @@ -12,6 +11,7 @@ use yii\db\ActiveQuery; use yii\db\ActiveRecord; use yii\web\UploadedFile; use yiidreamteam\upload\ImageUploadBehavior; +use yii\behaviors\SluggableBehavior; use Yii; @@ -317,6 +317,12 @@ class BlogPost extends ActiveRecord 'relations' => ['blogTagAssignments', 'blogComments'], ], [ + 'class' => SluggableBehavior::class, + 'attribute' => 'title', + 'ensureUnique' => true, + 'preserveNonEmptyValues' => true, + ], + [ // todo Image Sizes to settings or theme settings 'class' => ImageUploadBehavior::class, 'attribute' => 'image', diff --git a/common/modules/blog/entities/BlogTag.php b/common/modules/blog/entities/BlogTag.php index e883aec..11691d3 100644 --- a/common/modules/blog/entities/BlogTag.php +++ b/common/modules/blog/entities/BlogTag.php @@ -4,6 +4,7 @@ namespace common\modules\blog\entities; use yii\db\ActiveRecord; use yii\caching\TagDependency; +use yii\behaviors\SluggableBehavior; use Yii; /** @@ -43,4 +44,15 @@ class BlogTag extends ActiveRecord { return '{{%blog_tags}}'; } + + public function behaviors() { + return [ + [ + 'class' => SluggableBehavior::class, + 'attribute' => 'name', + 'ensureUnique' => true, + 'preserveNonEmptyValues' => true, + ], + ]; + } } \ No newline at end of file diff --git a/common/modules/blog/forms/BlogCategoryForm.php b/common/modules/blog/forms/BlogCategoryForm.php index b4fcaa5..fba6e9f 100644 --- a/common/modules/blog/forms/BlogCategoryForm.php +++ b/common/modules/blog/forms/BlogCategoryForm.php @@ -41,7 +41,7 @@ class BlogCategoryForm extends CompositeForm public function rules(): array { return [ - [['name', 'slug'], 'required'], + [['name'], 'required'], [['name', 'slug', 'title'], 'string', 'max' => 255], [['description'], 'string'], ['slug', SlugValidator::class], @@ -60,6 +60,12 @@ class BlogCategoryForm extends CompositeForm ]; } + public function attributeHints() { + return [ + 'slug' => Yii::t('blog', 'SEO link will be generated automatically if not specified'), + ]; + } + public function updateSort() { $this->sort = BlogCategory::find()->max('sort') + 1; } diff --git a/common/modules/blog/forms/BlogPostForm.php b/common/modules/blog/forms/BlogPostForm.php index e41fab9..ba7772b 100644 --- a/common/modules/blog/forms/BlogPostForm.php +++ b/common/modules/blog/forms/BlogPostForm.php @@ -108,6 +108,7 @@ class BlogPostForm extends CompositeForm public function attributeHints() { return [ 'published_at' => Yii::t('blog', 'The article will be published after the specified date if its status is not a draft'), + 'slug' => Yii::t('page', 'SEO link will be generated automatically if not specified'), ]; } diff --git a/common/modules/blog/forms/BlogTagForm.php b/common/modules/blog/forms/BlogTagForm.php index 245fcbc..1bc367b 100644 --- a/common/modules/blog/forms/BlogTagForm.php +++ b/common/modules/blog/forms/BlogTagForm.php @@ -4,7 +4,6 @@ namespace common\modules\blog\forms; use common\modules\blog\entities\BlogPost; use common\modules\blog\entities\BlogTag; -use common\modules\blog\entities\BlogTagAssignment; use yii\base\Model; use yii\helpers\ArrayHelper; diff --git a/common/modules/blog/forms/BlogTagSingleForm.php b/common/modules/blog/forms/BlogTagSingleForm.php index c4ee703..e03f881 100644 --- a/common/modules/blog/forms/BlogTagSingleForm.php +++ b/common/modules/blog/forms/BlogTagSingleForm.php @@ -28,7 +28,7 @@ class BlogTagSingleForm extends Model public function rules(): array { return [ - [['name', 'slug'], 'required'], + [['name'], 'required'], [['name', 'slug'], 'string', 'max' => 255], ['slug', SlugValidator::class], [['name', 'slug'], 'unique', 'targetClass' => BlogTag::class, 'filter' => $this->_tag ? ['<>', 'id', $this->_tag->id] : null] @@ -42,4 +42,10 @@ class BlogTagSingleForm extends Model 'slug' => Yii::t('blog', 'SEO link'), ]; } + + public function attributeHints() { + return [ + 'slug' => Yii::t('page', 'SEO link will be generated automatically if not specified'), + ]; + } } \ No newline at end of file diff --git a/common/modules/blog/messages/ru/blog.php b/common/modules/blog/messages/ru/blog.php index 2631584..714f4e9 100644 --- a/common/modules/blog/messages/ru/blog.php +++ b/common/modules/blog/messages/ru/blog.php @@ -77,4 +77,5 @@ return [ 'Are you sure you want to restore this history item?' => 'Вы уверены, что хотите восстановить эту запись?', 'Are you sure you want to remove this history?' => 'Вы уверены, что хотите удалить всю историю?', 'View' => 'Просмотр', + 'SEO link will be generated automatically if not specified' => 'ЧПУ ссылка будет сгенерирована автоматически, если не указано', ]; \ No newline at end of file diff --git a/common/modules/blog/views/manage/category/_form.php b/common/modules/blog/views/manage/category/_form.php index e7ebd26..246b8e8 100644 --- a/common/modules/blog/views/manage/category/_form.php +++ b/common/modules/blog/views/manage/category/_form.php @@ -7,6 +7,22 @@ use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model \common\modules\blog\forms\BlogCategoryForm */ /* @var $form yii\widgets\ActiveForm */ + +$js2 = ' +$(".hint-block").each(function () { + var $hint = $(this); + var label = $hint.parent().find("label"); + label.html(label.html() + \' \'); + label.addClass("help").popover({ + html: true, + trigger: "hover", + placement: "bottom", + content: $hint.html() + }); + $(this).hide(); +}); +'; +$this->registerJs($js2); ?>
diff --git a/common/modules/blog/views/manage/tag/_form.php b/common/modules/blog/views/manage/tag/_form.php index 5922e41..f7aa329 100644 --- a/common/modules/blog/views/manage/tag/_form.php +++ b/common/modules/blog/views/manage/tag/_form.php @@ -6,6 +6,22 @@ use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model \common\modules\blog\forms\BlogTagSingleForm */ /* @var $form yii\widgets\ActiveForm */ + +$js2 = ' +$(".hint-block").each(function () { + var $hint = $(this); + var label = $hint.parent().find("label"); + label.html(label.html() + \' \'); + label.addClass("help").popover({ + html: true, + trigger: "hover", + placement: "bottom", + content: $hint.html() + }); + $(this).hide(); +}); +'; +$this->registerJs($js2); ?>
diff --git a/common/modules/pages/entities/Page.php b/common/modules/pages/entities/Page.php index 8ac42d6..c4cc2f1 100644 --- a/common/modules/pages/entities/Page.php +++ b/common/modules/pages/entities/Page.php @@ -6,10 +6,12 @@ use common\modules\pages\entities\queries\PageQuery; use paulzi\nestedsets\NestedSetsBehavior; use core\behaviors\MetaBehavior; use yii\behaviors\TimestampBehavior; +use yii\behaviors\SluggableBehavior; use common\behaviors\WidgetContentBehavior; use yii\db\ActiveRecord; use core\entities\Meta; use Yii; +use yii\helpers\Inflector; /** * @property int $id @@ -83,6 +85,12 @@ class Page extends ActiveRecord ], TimestampBehavior::class, WidgetContentBehavior::class, + [ + 'class' => SluggableBehavior::class, + 'attribute' => 'title', + 'ensureUnique' => true, + 'preserveNonEmptyValues' => true, + ], ]; } diff --git a/common/modules/pages/forms/PageForm.php b/common/modules/pages/forms/PageForm.php index 03114a5..501d166 100644 --- a/common/modules/pages/forms/PageForm.php +++ b/common/modules/pages/forms/PageForm.php @@ -42,12 +42,11 @@ class PageForm extends CompositeForm public function rules(): array { return [ - [['title', 'slug'], 'required'], + [['title'], 'required'], [['parentId'], 'integer'], [['title', 'slug'], 'string', 'max' => 255], [['content'], 'string'], ['slug', SlugValidator::class], - //[['slug'], 'unique', 'targetClass' => Page::class, 'filter' => $this->_page ? ['<>', 'id', $this->_page->id] : null] [['slug'], 'unique', 'targetClass' => Page::class, 'filter' => function (ActiveQuery $query) { if ($this->type != Page::TYPE_PUBLIC) { $query->andWhere($this->type . '=' . Page::TYPE_PUBLIC); @@ -72,7 +71,13 @@ class PageForm extends CompositeForm ]; } - public function parentsList(): array + public function attributeHints() { + return [ + 'slug' => Yii::t('page', 'SEO link will be generated automatically if not specified'), + ]; + } + + public function parentsList(): array { return ArrayHelper::map(Page::find()->andWhere(['tree' => 1])->orderBy('lft')->asArray()->all(), 'id', function (array $page) { return ($page['depth'] > 1 ? str_repeat('-- ', $page['depth'] - 1) . ' ' : '') . $page['title']; diff --git a/common/modules/pages/messages/ru/page.php b/common/modules/pages/messages/ru/page.php index b0f1475..2ce571d 100644 --- a/common/modules/pages/messages/ru/page.php +++ b/common/modules/pages/messages/ru/page.php @@ -21,4 +21,5 @@ return [ 'View' => 'Просмотр', 'Publish' => 'Публикация', 'Preview on site' => 'Просмотр на сайте', + 'SEO link will be generated automatically if not specified' => 'ЧПУ ссылка будет сгенерирована автоматически, если не указано', ]; \ No newline at end of file diff --git a/common/modules/pages/services/PageManageService.php b/common/modules/pages/services/PageManageService.php index 2c59e50..088bf49 100644 --- a/common/modules/pages/services/PageManageService.php +++ b/common/modules/pages/services/PageManageService.php @@ -42,7 +42,7 @@ class PageManageService return $page; } - public function edit($id, PageForm $form): void + public function edit($id, PageForm $form, $type = Page::TYPE_PUBLIC): void { $page = $this->pages->get($id); @@ -53,7 +53,7 @@ class PageManageService $form->title, $form->slug, $form->content, - $form->type, + $type, new Meta( $form->meta->title, $form->meta->description, diff --git a/common/modules/pages/views/manage/page/_form.php b/common/modules/pages/views/manage/page/_form.php index 3e7257a..57e6964 100644 --- a/common/modules/pages/views/manage/page/_form.php +++ b/common/modules/pages/views/manage/page/_form.php @@ -7,6 +7,22 @@ use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model \common\modules\pages\forms\PageForm */ /* @var $form yii\widgets\ActiveForm */ + +$js2 = ' +$(".hint-block").each(function () { + var $hint = $(this); + var label = $hint.parent().find("label"); + label.html(label.html() + \' \'); + label.addClass("help").popover({ + html: true, + trigger: "hover", + placement: "bottom", + content: $hint.html() + }); + $(this).hide(); +}); +'; +$this->registerJs($js2); ?>