Skip to content

Commit

Permalink
Fix article publish_date bug after validation fail
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
keshikashviligio committed Jan 16, 2017
1 parent 84bdd15 commit 22c3d1f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions helpers/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
];
}

Expand Down
4 changes: 4 additions & 0 deletions models/TranslatableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 22c3d1f

Please sign in to comment.