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'); + } + +} 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) { 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); 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 + ]); } } 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']); 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]" 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()