From 66c71cb56e1c4510fec6cd1e17aea52d7513094d Mon Sep 17 00:00:00 2001 From: koco Date: Mon, 16 Jan 2017 14:20:00 +0400 Subject: [PATCH 1/4] Change status text to toggle button Fixes #11 --- AssetBundle.php | 7 +- actions/ToggleStatusAction.php | 84 +++++++++++++++++++ assets/css/main.css | 69 ++++++++++++++++ assets/js/i18nContent.js | 59 ++++++++++++++ assets/less/_togglebutton.less | 85 ++++++++++++++++++++ assets/less/main.less | 1 + controllers/ArticleCategoryController.php | 10 +++ controllers/ArticleController.php | 8 +- controllers/PageController.php | 4 + controllers/WidgetCarouselController.php | 10 +++ controllers/WidgetCarouselItemController.php | 4 + controllers/WidgetMenuController.php | 10 +++ controllers/WidgetTextController.php | 4 + helpers/Html.php | 9 +++ views/article-category/index.php | 16 ++-- views/article/index.php | 17 ++-- views/page/index.php | 16 ++-- views/widget-carousel/index.php | 17 ++-- views/widget-carousel/update.php | 19 ++++- views/widget-menu/index.php | 16 ++-- views/widget-text/index.php | 16 ++-- 21 files changed, 446 insertions(+), 35 deletions(-) create mode 100644 actions/ToggleStatusAction.php create mode 100644 assets/js/i18nContent.js create mode 100644 assets/less/_togglebutton.less diff --git a/AssetBundle.php b/AssetBundle.php index 77f334b..c2acf30 100644 --- a/AssetBundle.php +++ b/AssetBundle.php @@ -17,8 +17,13 @@ class AssetBundle extends \yii\web\AssetBundle 'css/main.css' ]; + public $js = [ + 'js/i18nContent.js' + ]; + public $depends = [ - 'yii\bootstrap\BootstrapAsset' + 'yii\bootstrap\BootstrapAsset', + 'yii\bootstrap\BootstrapPluginAsset' ]; public function init() diff --git a/actions/ToggleStatusAction.php b/actions/ToggleStatusAction.php new file mode 100644 index 0000000..8c56383 --- /dev/null +++ b/actions/ToggleStatusAction.php @@ -0,0 +1,84 @@ +model === null){ + throw new InvalidConfigException('In class centigen\i18ncontent\actions\ToggleStatusAction model param must be passed!'); + } + parent::init(); + } + + public function run() + { + $request = Yii::$app->request; + $model = $this->findModel($request->post('id')); + $model->{$this->statusField} = (int)!$model->{$this->statusField}; + + if($model->save()){ + $res = [ + 'success' => true, + 'msg' => '', + 'errors' => '', + ]; + }else{ + $res = [ + 'success' => false, + 'msg' => Yii::t('i18ncontent', 'Status change error!'), + 'errors' => $model->errors, + ]; + } + Yii::$app->response->format = Response::FORMAT_JSON; + + return $res; + } + + + protected function findModel($id) + { + $model = $this->model; + if (($model = $model::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} \ No newline at end of file diff --git a/assets/css/main.css b/assets/css/main.css index 9acbbaa..6ba2085 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -324,6 +324,75 @@ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); margin-bottom: 30px; } +.togglebutton { + vertical-align: middle; +} +.togglebutton, +.togglebutton label, +.togglebutton input, +.togglebutton .toggle { + user-select: none; +} +.togglebutton label { + cursor: pointer; + color: rgba(0, 0, 0, 0.26); +} +.togglebutton label:focus { + outline: 0; +} +.togglebutton label input[type=checkbox] { + opacity: 0; + width: 0; + height: 0; +} +.togglebutton label .toggle { + text-align: left; +} +.togglebutton label .toggle, +.togglebutton label input[type=checkbox][disabled] + .toggle { + content: ""; + display: inline-block; + width: 30px; + height: 15px; + background-color: rgba(80, 80, 80, 0.7); + border-radius: 15px; + margin-right: 15px; + transition: background 0.3s ease; + vertical-align: middle; +} +.togglebutton label .toggle:after { + content: ""; + display: inline-block; + width: 20px; + height: 20px; + background-color: #F1F1F1; + border-radius: 20px; + position: relative; + box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4); + left: -5px; + top: -2px; + transition: left 0.3s ease, background 0.3s ease, box-shadow 0.1s ease; +} +.togglebutton label input[type=checkbox][disabled] + .toggle:after, +.togglebutton label input[type=checkbox][disabled]:checked + .toggle:after { + background-color: #BDBDBD; +} +.togglebutton label input[type=checkbox] + .toggle:active:after, +.togglebutton label input[type=checkbox][disabled] + .toggle:active:after { + box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4), 0 0 0 15px rgba(0, 0, 0, 0.1); +} +.togglebutton label input[type=checkbox]:checked + .toggle:after { + left: 15px; +} +.togglebutton label input[type=checkbox]:checked + .toggle { + background-color: rgba(60, 141, 188, 0.5); +} +.togglebutton label input[type=checkbox]:checked + .toggle:after { + background-color: #3c8dbc; +} +.togglebutton label input[type=checkbox]:checked + .toggle:active:after { + box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4), 0 0 0 15px rgba(60, 141, 188, 0.1); +} .table-wrapper table > thead > tr > th { white-space: nowrap; } diff --git a/assets/js/i18nContent.js b/assets/js/i18nContent.js new file mode 100644 index 0000000..85505ed --- /dev/null +++ b/assets/js/i18nContent.js @@ -0,0 +1,59 @@ +/** + * Created by koco on 1/16/2017. + */ +(function ($) { + var I18nContent = function () { + this.$toggleBtn = $('.togglebutton > label > input'); + + this.init(); + }; + + I18nContent.prototype = { + constructor: I18nContent, + + init: function () { + this.toggleStatus(); + }, + + + toggleStatus: function () { + var me = this; + this.$toggleBtn.change(function() { + var $row = $(this).closest('tr'); + var action = $row.data('toggle-action') || 'toggle-status'; + me._post(action, {id: $row.data('key')}).done(function (res) { + if(res.success) { + + }else{ + alert(res.msg); + } + }); + + }); + }, + + + _get: function (url, data) { + return $.ajax({ + url: url, + type: 'GET', + data: data, + dataType: 'json' + }); + }, + + _post: function (url, data) { + return $.ajax({ + url: url, + type: 'POST', + data: data, + dataType: 'json' + }); + } + + + }; + + + window.i18ncontent = new I18nContent(); +})($); \ No newline at end of file diff --git a/assets/less/_togglebutton.less b/assets/less/_togglebutton.less new file mode 100644 index 0000000..4a80b21 --- /dev/null +++ b/assets/less/_togglebutton.less @@ -0,0 +1,85 @@ +.togglebutton { + vertical-align: middle; + &, label, input, .toggle { + user-select: none; + } + label { + cursor: pointer; + color: rgba(0,0,0, 0.26); + &:focus{ + outline: 0; + } + + // Hide original checkbox + input[type=checkbox] { + opacity: 0; + width: 0; + height: 0; + } + + .toggle { + text-align: left; // Issue #737 horizontal form + } + // Switch bg off and disabled + .toggle, + input[type=checkbox][disabled] + .toggle { + content: ""; + display: inline-block; + width: 30px; + height: 15px; + background-color: rgba(80, 80, 80, 0.7); + border-radius: 15px; + margin-right: 15px; + transition: background 0.3s ease; + vertical-align: middle; + } + // Handle off + .toggle:after { + content: ""; + display: inline-block; + width: 20px; + height: 20px; + background-color: #F1F1F1; + border-radius: 20px; + position: relative; + box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4); + left: -5px; + top: -2px; + transition: left 0.3s ease, background 0.3s ease, box-shadow 0.1s ease; + } + input[type=checkbox] { + // Handle disabled + &[disabled] { + & + .toggle:after, + &:checked + .toggle:after { + background-color: #BDBDBD; + } + } + + & + .toggle:active:after, + &[disabled] + .toggle:active:after { + box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4), 0 0 0 15px rgba(0, 0, 0, 0.1); + } + + // Ripple off and disabled + &:checked + .toggle:after { + left: 15px; + } + } + + // set bg when checked + input[type=checkbox]:checked { + + .toggle { + background-color: fade(#3c8dbc, 50%); // Switch bg on + } + + + .toggle:after { + background-color: #3c8dbc; // Handle on + } + + + .toggle:active:after { + box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4), 0 0 0 15px fade(#3c8dbc, 10%); // Ripple on + } + } + } +} diff --git a/assets/less/main.less b/assets/less/main.less index 8ec6c66..dee7e06 100644 --- a/assets/less/main.less +++ b/assets/less/main.less @@ -1,6 +1,7 @@ @import "mixins"; @import "helpers"; @import "tabs"; +@import "_togglebutton"; .table-wrapper { table > thead > tr > th { diff --git a/controllers/ArticleCategoryController.php b/controllers/ArticleCategoryController.php index 8acc700..c0aba88 100644 --- a/controllers/ArticleCategoryController.php +++ b/controllers/ArticleCategoryController.php @@ -28,6 +28,16 @@ public function behaviors() ]; } + public function actions() + { + return [ + 'toggle-status' => [ + 'class' => 'centigen\i18ncontent\actions\ToggleStatusAction', + 'model' => 'centigen\i18ncontent\models\ArticleCategory', + ] + ]; + } + /** * Lists all ArticleCategory models. * @return mixed diff --git a/controllers/ArticleController.php b/controllers/ArticleController.php index a7c5c6c..81ff82f 100644 --- a/controllers/ArticleController.php +++ b/controllers/ArticleController.php @@ -22,7 +22,8 @@ public function behaviors() 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ - 'delete' => ['post'] + 'delete' => ['post'], + 'ToggleStatus' => ['post'] ] ], \centigen\base\behaviors\LayoutBehavior::className() @@ -45,6 +46,10 @@ public function actions() 'responseUrlParam'=> 'filelink', 'multiple' => false, 'disableCsrf' => true + ], + 'toggle-status' => [ + 'class' => 'centigen\i18ncontent\actions\ToggleStatusAction', + 'model' => 'centigen\i18ncontent\models\Article', ] ]; } @@ -123,6 +128,7 @@ public function actionDelete($id) return $this->redirect(['index']); } + /** * Finds the Article model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/controllers/PageController.php b/controllers/PageController.php index a97c578..7672bf9 100644 --- a/controllers/PageController.php +++ b/controllers/PageController.php @@ -44,6 +44,10 @@ public function actions() 'responseUrlParam'=> 'filelink', 'multiple' => false, 'disableCsrf' => true + ], + 'toggle-status' => [ + 'class' => 'centigen\i18ncontent\actions\ToggleStatusAction', + 'model' => 'centigen\i18ncontent\models\Page', ] ]; } diff --git a/controllers/WidgetCarouselController.php b/controllers/WidgetCarouselController.php index 61bf044..1058888 100644 --- a/controllers/WidgetCarouselController.php +++ b/controllers/WidgetCarouselController.php @@ -28,6 +28,16 @@ public function behaviors() ]; } + public function actions() + { + return [ + 'toggle-status' => [ + 'class' => 'centigen\i18ncontent\actions\ToggleStatusAction', + 'model' => 'centigen\i18ncontent\models\WidgetCarousel', + ] + ]; + } + /** * Lists all WidgetCarousel models. * @return mixed diff --git a/controllers/WidgetCarouselItemController.php b/controllers/WidgetCarouselItemController.php index 4803f33..66f6e7a 100644 --- a/controllers/WidgetCarouselItemController.php +++ b/controllers/WidgetCarouselItemController.php @@ -51,6 +51,10 @@ public function actions() 'responseUrlParam'=> 'filelink', 'multiple' => false, 'disableCsrf' => true + ], + 'toggle-status' => [ + 'class' => 'centigen\i18ncontent\actions\ToggleStatusAction', + 'model' => 'centigen\i18ncontent\models\WidgetCarouselItem', ] ]; } diff --git a/controllers/WidgetMenuController.php b/controllers/WidgetMenuController.php index 614fc79..61049d2 100644 --- a/controllers/WidgetMenuController.php +++ b/controllers/WidgetMenuController.php @@ -35,6 +35,16 @@ public function behaviors() ]; } + public function actions() + { + return [ + 'toggle-status' => [ + 'class' => 'centigen\i18ncontent\actions\ToggleStatusAction', + 'model' => 'centigen\i18ncontent\models\WidgetMenu', + ] + ]; + } + /** * Lists all WidgetMenu models. * @return mixed diff --git a/controllers/WidgetTextController.php b/controllers/WidgetTextController.php index a572581..87adbe9 100644 --- a/controllers/WidgetTextController.php +++ b/controllers/WidgetTextController.php @@ -44,6 +44,10 @@ public function actions() 'responseUrlParam'=> 'filelink', 'multiple' => false, 'disableCsrf' => true + ], + 'toggle-status' => [ + 'class' => 'centigen\i18ncontent\actions\ToggleStatusAction', + 'model' => 'centigen\i18ncontent\models\WidgetText', ] ]; } diff --git a/helpers/Html.php b/helpers/Html.php index 784347d..e145ed8 100644 --- a/helpers/Html.php +++ b/helpers/Html.php @@ -6,6 +6,7 @@ */ namespace centigen\i18ncontent\helpers; +use centigen\base\i18n\Formatter; use centigen\i18ncontent\Module; use Yii; @@ -18,6 +19,7 @@ */ class Html extends \yii\bootstrap\Html { + /** * Replace $module's `mediaUrlPrefix` occurrence with $module's `mediaUrlReplacement` in given text * @@ -53,5 +55,12 @@ public static function decodeMediaItemUrls($text) return str_replace($module->mediaUrlReplacement, $module->mediaUrlPrefix, $text); } + public static function asFab($model, $disabled = false){ + $formatter = new Formatter(); + return $formatter->asToggle($model->status, $disabled); + } + + + } \ No newline at end of file diff --git a/views/article-category/index.php b/views/article-category/index.php index 4f14084..75a4157 100644 --- a/views/article-category/index.php +++ b/views/article-category/index.php @@ -34,12 +34,18 @@ } ], [ - 'class' => \centigen\base\grid\EnumColumn::className(), + 'label' => Yii::t('i18ncontent', 'Status'), 'attribute' => 'status', - 'format' => ['statusLabel'], - 'enum' => [ - Yii::t('i18ncontent', 'Inactive'), - Yii::t('i18ncontent', 'Active') + 'content' => function($model){ + /** @var \common\models\User $model */ + return \centigen\i18ncontent\helpers\Html::asFab($model); + }, + 'headerOptions' => [ + 'class' => 'text-center', + ], + 'contentOptions' => [ + 'class' => '', + 'style' => 'width: 1px' ], ], [ diff --git a/views/article/index.php b/views/article/index.php index d950a9e..9194ac7 100644 --- a/views/article/index.php +++ b/views/article/index.php @@ -62,12 +62,19 @@ } ], [ - 'class' => \centigen\base\grid\EnumColumn::className(), + 'label' => Yii::t('i18ncontent', 'Status'), 'attribute' => 'status', - 'enum' => [ - Yii::t('i18ncontent', 'Not Published'), - Yii::t('i18ncontent', 'Published') - ] + 'content' => function($model){ + /** @var \common\models\User $model */ + return \centigen\i18ncontent\helpers\Html::asFab($model); + }, + 'headerOptions' => [ + 'class' => 'text-center', + ], + 'contentOptions' => [ + 'class' => '', + 'style' => 'width: 1px' + ], ], [ 'attribute' => 'position', diff --git a/views/page/index.php b/views/page/index.php index 0ac6562..0da5ebd 100644 --- a/views/page/index.php +++ b/views/page/index.php @@ -33,12 +33,18 @@ ], 'slug', [ - 'class' => \centigen\base\grid\EnumColumn::className(), + 'label' => Yii::t('i18ncontent', 'Status'), 'attribute' => 'status', - 'format' => ['statusLabel'], - 'enum' => [ - Yii::t('i18ncontent', 'Inactive'), - Yii::t('i18ncontent', 'Active') + 'content' => function($model){ + /** @var \common\models\User $model */ + return \centigen\i18ncontent\helpers\Html::asFab($model); + }, + 'headerOptions' => [ + 'class' => 'text-center', + ], + 'contentOptions' => [ + 'class' => '', + 'style' => 'width: 1px' ], ], [ diff --git a/views/widget-carousel/index.php b/views/widget-carousel/index.php index fd11cf9..122e391 100644 --- a/views/widget-carousel/index.php +++ b/views/widget-carousel/index.php @@ -1,6 +1,5 @@ \centigen\base\grid\EnumColumn::className(), + 'label' => Yii::t('i18ncontent', 'Status'), 'attribute' => 'status', - 'format' => ['statusLabel'], - 'enum' => [ - Yii::t('i18ncontent', 'Inactive'), - Yii::t('i18ncontent', 'Active') + 'content' => function($model){ + /** @var \common\models\User $model */ + return \centigen\i18ncontent\helpers\Html::asFab($model); + }, + 'headerOptions' => [ + 'class' => 'text-center', + ], + 'contentOptions' => [ + 'class' => '', + 'style' => 'width: 1px' ], ], [ diff --git a/views/widget-carousel/update.php b/views/widget-carousel/update.php index 7573a04..56f88b2 100644 --- a/views/widget-carousel/update.php +++ b/views/widget-carousel/update.php @@ -28,6 +28,11 @@ $carouselItemsProvider, + 'rowOptions' => function(){ + return [ + 'data-toggle-action' => '/i18ncontent/widget-carousel-item/toggle-status' + ]; + }, 'columns' => [ [ 'attribute' => 'order', @@ -55,9 +60,19 @@ 'attribute' => 'activeTranslation.caption', ], [ + 'label' => Yii::t('i18ncontent', 'Status'), 'attribute' => 'status', - 'format' => ['statusLabel'], - 'contentOptions' => ['style' => 'width: 50px'] + 'content' => function($model){ + /** @var \common\models\User $model */ + return \centigen\i18ncontent\helpers\Html::asFab($model); + }, + 'headerOptions' => [ + 'class' => 'text-center', + ], + 'contentOptions' => [ + 'class' => '', + 'style' => 'width: 1px' + ], ], [ diff --git a/views/widget-menu/index.php b/views/widget-menu/index.php index edefb80..5fb598d 100644 --- a/views/widget-menu/index.php +++ b/views/widget-menu/index.php @@ -32,12 +32,18 @@ 'title', 'key', [ - 'class' => \centigen\base\grid\EnumColumn::className(), + 'label' => Yii::t('i18ncontent', 'Status'), 'attribute' => 'status', - 'format' => ['statusLabel'], - 'enum' => [ - Yii::t('i18ncontent', 'Inactive'), - Yii::t('i18ncontent', 'Active') + 'content' => function($model){ + /** @var \common\models\User $model */ + return \centigen\i18ncontent\helpers\Html::asFab($model); + }, + 'headerOptions' => [ + 'class' => 'text-center', + ], + 'contentOptions' => [ + 'class' => '', + 'style' => 'width: 1px' ], ], ['class' => 'yii\grid\ActionColumn', 'template'=>'{update} {delete}'], diff --git a/views/widget-text/index.php b/views/widget-text/index.php index 5bbcd22..4463662 100644 --- a/views/widget-text/index.php +++ b/views/widget-text/index.php @@ -34,12 +34,18 @@ } ], [ - 'class' => \centigen\base\grid\EnumColumn::className(), + 'label' => Yii::t('i18ncontent', 'Status'), 'attribute' => 'status', - 'format' => ['statusLabel'], - 'enum' => [ - Yii::t('i18ncontent', 'Inactive'), - Yii::t('i18ncontent', 'Active') + 'content' => function($model){ + /** @var \common\models\User $model */ + return \centigen\i18ncontent\helpers\Html::asFab($model); + }, + 'headerOptions' => [ + 'class' => 'text-center', + ], + 'contentOptions' => [ + 'class' => '', + 'style' => 'width: 1px' ], ], 'created_at:datetime', From 84bdd15427ec0d899c23e0b4abeabfc85b3710b3 Mon Sep 17 00:00:00 2001 From: koco Date: Mon, 16 Jan 2017 15:59:08 +0400 Subject: [PATCH 2/4] Fix jui and bs load order Fixes #1 --- web/Controller.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/Controller.php b/web/Controller.php index 41c5827..cf6ba89 100644 --- a/web/Controller.php +++ b/web/Controller.php @@ -15,5 +15,15 @@ public function init() { parent::init(); AssetBundle::register($this->getView()); + + } + + + public function beforeAction($action) + { + if(isset(\Yii::$app->assetManager->bundles['yii\bootstrap\BootstrapPluginAsset'])){ + \Yii::$app->assetManager->bundles['yii\bootstrap\BootstrapPluginAsset']->depends[] = 'yii\jui\JuiAsset'; + } + return parent::beforeAction($action); } } \ No newline at end of file From 22c3d1fa823af2ebc6bdaf9b30011bd463c0e865 Mon Sep 17 00:00:00 2001 From: koco Date: Mon, 16 Jan 2017 17:46:32 +0400 Subject: [PATCH 3/4] Fix article publish_date bug after validation fail Fixes #12 --- helpers/Html.php | 5 +++++ models/Article.php | 3 +-- models/TranslatableModel.php | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/helpers/Html.php b/helpers/Html.php index e145ed8..1008be6 100644 --- a/helpers/Html.php +++ b/helpers/Html.php @@ -55,6 +55,11 @@ public static function decodeMediaItemUrls($text) return str_replace($module->mediaUrlReplacement, $module->mediaUrlPrefix, $text); } + /** + * @param $model + * @param bool $disabled + * @return string + */ public static function asFab($model, $disabled = false){ $formatter = new Formatter(); return $formatter->asToggle($model->status, $disabled); diff --git a/models/Article.php b/models/Article.php index c57aa2c..8d1528a 100644 --- a/models/Article.php +++ b/models/Article.php @@ -129,12 +129,11 @@ public function rules() [['category_id'], 'required'], [['slug'], 'unique'], [['published_at'], 'default', 'value' => time()], - [['published_at'], 'filter', 'filter' => 'strtotime'], [['category_id'], 'exist', 'targetClass' => ArticleCategory::className(), 'targetAttribute' => 'id'], [['author_id', 'updater_id', 'position', 'status'], 'integer'], [['slug', 'thumbnail_base_url', 'thumbnail_path', 'url'], 'string', 'max' => 2024], [['view'], 'string', 'max' => 255], - [['attachments', 'thumbnail'], 'safe'] + [['attachments', 'thumbnail', 'published_at'], 'safe'] ]; } diff --git a/models/TranslatableModel.php b/models/TranslatableModel.php index fccbbe2..db26753 100644 --- a/models/TranslatableModel.php +++ b/models/TranslatableModel.php @@ -59,6 +59,10 @@ public function load($postData, $formName = null) return false; } + if($this->hasAttribute('published_at')){ + $this->published_at = $this->published_at ? strtotime($this->published_at) : time(); + } + $className = \yii\helpers\StringHelper::basename(static::$translateModel); $translations = ArrayHelper::getValue($postData, $className); $this->newTranslations = []; From 47e53bddca018ec80bdc0738f7c67ba784f62f84 Mon Sep 17 00:00:00 2001 From: koco Date: Mon, 16 Jan 2017 17:55:33 +0400 Subject: [PATCH 4/4] Fix article publish_date bug after validation fail (better way) Fixes #12 --- models/Article.php | 3 +++ models/TranslatableModel.php | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/models/Article.php b/models/Article.php index 8d1528a..4f4c0a5 100644 --- a/models/Article.php +++ b/models/Article.php @@ -129,6 +129,9 @@ public function rules() [['category_id'], 'required'], [['slug'], 'unique'], [['published_at'], 'default', 'value' => time()], + [['published_at'], 'filter', 'filter' => 'strtotime', 'when' => function($model) { + return is_string($model->published_at); + }], [['category_id'], 'exist', 'targetClass' => ArticleCategory::className(), 'targetAttribute' => 'id'], [['author_id', 'updater_id', 'position', 'status'], 'integer'], [['slug', 'thumbnail_base_url', 'thumbnail_path', 'url'], 'string', 'max' => 2024], diff --git a/models/TranslatableModel.php b/models/TranslatableModel.php index db26753..fccbbe2 100644 --- a/models/TranslatableModel.php +++ b/models/TranslatableModel.php @@ -59,10 +59,6 @@ public function load($postData, $formName = null) return false; } - if($this->hasAttribute('published_at')){ - $this->published_at = $this->published_at ? strtotime($this->published_at) : time(); - } - $className = \yii\helpers\StringHelper::basename(static::$translateModel); $translations = ArrayHelper::getValue($postData, $className); $this->newTranslations = [];