Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodeholic committed Nov 23, 2017
2 parents 9e1445d + abcf649 commit 59f8014
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use yii\db\Migration;

/**
* Class m171113_085608_add_extra_description_to_article_translation
*/
class m171113_085608_add_extra_description_to_article_translation extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$this->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');
}

}
5 changes: 5 additions & 0 deletions models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion models/ArticleTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
];
Expand All @@ -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'),
Expand All @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @property string $body
* @property PageTranslation[] $translations
* @property PageTranslation $activeTranslation
* @property PageTranslation $defaultTranslation
*/
class Page extends TranslatableModel
{
Expand Down Expand Up @@ -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
]);
}
}
3 changes: 3 additions & 0 deletions models/TranslatableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
20 changes: 20 additions & 0 deletions views/article/_tab_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@
]
) ?>

<?php echo $form->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'])
]
]
) ?>

<?php echo $form->field($model, 'meta_title', [
'inputOptions' => [
'name' => "{$className}[$language][meta_title]"
Expand Down
3 changes: 2 additions & 1 deletion widgets/DbText.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace centigen\i18ncontent\widgets;

use centigen\i18ncontent\helpers\Html;
use centigen\i18ncontent\models\WidgetText;
use yii\base\Widget;
use Yii;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 59f8014

Please sign in to comment.