/** * Generate url from the name * * @return bool */ public function beforeValidate() { $this->url = $this->url ? $this->url : LittleBigHelper::slug($this->name); return parent::beforeValidate(); }
/** * @param UploadedFile $file * * @return string */ public function generateFileName($file) { return uniqid() . '_' . LittleBigHelper::slug($file->baseName, '_') . '.' . $file->extension; }
/** * Make sure that only 1 main page exists * * @param bool $insert * * @return bool */ public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($this->type == static::TYPE_TEXT) { $this->slug = LittleBigHelper::slug($this->slug ? $this->slug : $this->name); } if ($this->is_main == 1 && ($insert || $this->oldAttributes['is_main'] == 0)) { ContentPage::updateAll(['is_main' => 0]); $this->active = 1; } return true; } return false; }