name = $name; $category->slug = $slug; $category->title = $title; $category->description = $description; $category->sort = $sort; $category->meta = $meta; return $category; } public function edit($name, $slug, $title, $description, $sort, Meta $meta): void { $this->name = $name; $this->slug = $slug; $this->title = $title; $this->description = $description; $this->sort = $sort; $this->meta = $meta; } public function attributeLabels() { return [ 'id' => Yii::t('blog', 'ID'), 'name' => Yii::t('blog', 'Name'), 'slug' => Yii::t('blog', 'SEO link'), 'sort' => Yii::t('blog', 'Sort'), 'title' => Yii::t('blog', 'Title'), 'description' => Yii::t('blog', 'Description'), 'meta.title' => Yii::t('blog', 'Meta Title'), 'meta.description' => Yii::t('blog', 'Meta Description'), 'meta.keywords' => Yii::t('blog', 'Meta Keywords'), ]; } public function getSeoTitle(): string { return $this->meta->title ?: $this->getHeadingTile(); } public function getHeadingTile(): string { return $this->title ?: $this->name; } public function getPostsCount(): int { return BlogPost::find()->where(['category_id' => $this->id])->count('*'); } public static function tableName(): string { return '{{%blog_categories}}'; } public function behaviors(): array { return [ MetaBehavior::class, [ 'class' => SluggableBehavior::class, 'attribute' => 'title', 'ensureUnique' => true, 'preserveNonEmptyValues' => true, ], ]; } }