From 95db39a2555858506c089aa0873094799829016d Mon Sep 17 00:00:00 2001 From: Gio Keshikashvili Date: Fri, 10 Nov 2017 19:37:07 +0400 Subject: [PATCH 1/7] Missing media url decode --- widgets/DbText.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/widgets/DbText.php b/widgets/DbText.php index d5733a1..b11178f 100644 --- a/widgets/DbText.php +++ b/widgets/DbText.php @@ -2,6 +2,7 @@ namespace centigen\i18ncontent\widgets; +use centigen\i18ncontent\helpers\Html; use centigen\i18ncontent\models\WidgetText; use yii\base\Widget; use Yii; @@ -32,7 +33,7 @@ class DbText extends Widget */ public function run() { - return $this->getModel() ? $this->getModel()->{$this->attribute} : ""; + return $this->getModel() ? Html::decodeMediaItemUrls($this->getModel()->{$this->attribute}) : ""; } public function getTitle() From 2acb314b2f2e1c48271e70d163809e8760a68ba8 Mon Sep 17 00:00:00 2001 From: guga Date: Sat, 11 Nov 2017 13:12:16 +0400 Subject: [PATCH 2/7] get default language if translation doesn't exists in the active language --- models/Page.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/models/Page.php b/models/Page.php index 9f171d0..d6f0d72 100644 --- a/models/Page.php +++ b/models/Page.php @@ -24,6 +24,7 @@ * @property string $body * @property PageTranslation[] $translations * @property PageTranslation $activeTranslation + * @property PageTranslation $defaultTranslation */ class Page extends TranslatableModel { @@ -175,11 +176,22 @@ public static function getById($id) public function getTitle() { - return $this->activeTranslation ? $this->activeTranslation->title : ''; + return $this->getTranslation() ? $this->getTranslation()->title : ''; } public function getBody() { - return $this->activeTranslation ? $this->activeTranslation->getBody() : ''; + return $this->getTranslation() ? $this->getTranslation()->getBody() : ''; + } + public function getTranslation() + { + return $this->activeTranslation ?: $this->defaultTranslation; + } + + public function getDefaultTranslation() + { + return $this->hasOne(PageTranslation::className(), ['page_id' => 'id'])->where([ + 'locale' => Yii::$app->sourceLanguage + ]); } } From 9827b27afe3d0b68af8d51ec5dbd6c5eaa18e130 Mon Sep 17 00:00:00 2001 From: Saiat Kalbiev Date: Mon, 13 Nov 2017 13:13:26 +0400 Subject: [PATCH 3/7] Add migration for article translation Add extra description column --- ...tra_description_to_article_translation.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 migrations/m171113_085608_add_extra_description_to_article_translation.php diff --git a/migrations/m171113_085608_add_extra_description_to_article_translation.php b/migrations/m171113_085608_add_extra_description_to_article_translation.php new file mode 100644 index 0000000..56b2cb1 --- /dev/null +++ b/migrations/m171113_085608_add_extra_description_to_article_translation.php @@ -0,0 +1,26 @@ +addColumn(\centigen\i18ncontent\models\ArticleTranslation::tableName(),'extra_description',$this->text()->after('short_description')); + } + + /** + * @inheritdoc + */ + public function safeDown() + { + $this->dropColumn(\centigen\i18ncontent\models\ArticleTranslation::tableName(),'extra_description'); + } + +} From ec65bd6da9bd7b93f30f0ec08eef577eadda7b0c Mon Sep 17 00:00:00 2001 From: Saiat Kalbiev Date: Mon, 13 Nov 2017 13:14:04 +0400 Subject: [PATCH 4/7] Add public method for extra description --- models/Article.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/models/Article.php b/models/Article.php index 6773064..fcaef4b 100644 --- a/models/Article.php +++ b/models/Article.php @@ -344,6 +344,11 @@ public function getShortDescription() return $this->activeTranslation ? $this->activeTranslation->getShortDescription() : ''; } + public function getExtraDescription() + { + return $this->activeTranslation ? $this->activeTranslation->getExtraDescription() : ''; + } + public function getThumbnailUrl() { if ($this->thumbnail_path) { From 90dbabdcdf67a68f15dc59488d35cb1fd7f5532a Mon Sep 17 00:00:00 2001 From: Saiat Kalbiev Date: Mon, 13 Nov 2017 13:14:31 +0400 Subject: [PATCH 5/7] Add extra_description field for article translation model --- models/TranslatableModel.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/models/TranslatableModel.php b/models/TranslatableModel.php index 1542536..a685677 100644 --- a/models/TranslatableModel.php +++ b/models/TranslatableModel.php @@ -70,6 +70,9 @@ public function load($postData, $formName = null) if (isset($modelData['body'])) { $modelData['body'] = Html::encodeMediaItemUrls($modelData['body']); } + if (isset($modelData['extra_description'])) { + $modelData['extra_description'] = Html::encodeMediaItemUrls($modelData['extra_description']); + } if (isset($modelData['short_description']) && ($this->hasAttribute('short_description') || $this->hasProperty('short_description'))) { $this ->short_description = Html::encodeMediaItemUrls($modelData['short_description']); From d42e26a789a3b0a82cfe0dc5979c4176501577c3 Mon Sep 17 00:00:00 2001 From: Saiat Kalbiev Date: Mon, 13 Nov 2017 13:14:51 +0400 Subject: [PATCH 6/7] Add extra description column --- models/ArticleTranslation.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/models/ArticleTranslation.php b/models/ArticleTranslation.php index 48c6570..899d9d2 100644 --- a/models/ArticleTranslation.php +++ b/models/ArticleTranslation.php @@ -14,6 +14,7 @@ * @property string $title * @property string $body * @property string $short_description + * @property string $extra_description * @property string $meta_title * @property string $meta_description * @property string $meta_keywords @@ -40,7 +41,7 @@ public function rules() return [ [['article_id', 'locale', 'title', 'body'], 'required'], [['article_id'], 'integer'], - [['body','short_description'], 'string'], + [['body','short_description','extra_description'], 'string'], [['locale'], 'string', 'max' => 15], [['title', 'keywords', 'meta_title', 'meta_description', 'meta_keywords'], 'string', 'max' => 512] ]; @@ -58,6 +59,7 @@ public function attributeLabels() 'title' => Yii::t('i18ncontent', 'Title'), 'body' => Yii::t('i18ncontent', 'Body'), 'short_description' => Yii::t('i18ncontent', 'Short Description'), + 'extra_description' => Yii::t('i18ncontent', 'Extra Description'), 'meta_title' => Yii::t('i18ncontent', 'Meta Title'), 'meta_description' => Yii::t('i18ncontent', 'Meta Description'), 'meta_keywords' => Yii::t('i18ncontent', 'Meta Keywords'), @@ -78,6 +80,11 @@ public function getBody() return Html::decodeMediaItemUrls($this->body); } + public function getExtraDescription() + { + return Html::decodeMediaItemUrls($this->extra_description); + } + public function getShortDescription() { return Html::decodeMediaItemUrls($this->short_description); From abcf649e87e54b34b68e735efa3cc4fcb3fc2dc4 Mon Sep 17 00:00:00 2001 From: Saiat Kalbiev Date: Mon, 13 Nov 2017 13:16:17 +0400 Subject: [PATCH 7/7] Add input for extra_description --- views/article/_tab_content.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/views/article/_tab_content.php b/views/article/_tab_content.php index 70ba7f1..83e9f20 100644 --- a/views/article/_tab_content.php +++ b/views/article/_tab_content.php @@ -69,6 +69,26 @@ ] ) ?> +field($model, 'extra_description')->widget( + \yii\imperavi\Widget::className(), + [ + 'plugins' => ['table', 'fullscreen', 'fontcolor', 'video'], + 'htmlOptions' => [ + 'name' => "{$className}[$language][extra_description]", + 'value' => $model->getExtraDescription() + ], + 'options' => [ + 'minHeight' => 100, + 'maxHeight' => 200, + 'buttonSource' => true, + 'convertDivs' => false, + 'removeEmptyTags' => false, + 'replaceDivs' => false, + 'imageUpload' => Url::to(['upload-imperavi']) + ] + ] +) ?> + field($model, 'meta_title', [ 'inputOptions' => [ 'name' => "{$className}[$language][meta_title]"