|
|
|
@ -42,12 +42,11 @@ class PageForm extends CompositeForm
|
|
|
|
|
public function rules(): array |
|
|
|
|
{ |
|
|
|
|
return [ |
|
|
|
|
[['title', 'slug'], 'required'], |
|
|
|
|
[['title'], 'required'], |
|
|
|
|
[['parentId'], 'integer'], |
|
|
|
|
[['title', 'slug'], 'string', 'max' => 255], |
|
|
|
|
[['content'], 'string'], |
|
|
|
|
['slug', SlugValidator::class], |
|
|
|
|
//[['slug'], 'unique', 'targetClass' => Page::class, 'filter' => $this->_page ? ['<>', 'id', $this->_page->id] : null] |
|
|
|
|
[['slug'], 'unique', 'targetClass' => Page::class, 'filter' => function (ActiveQuery $query) { |
|
|
|
|
if ($this->type != Page::TYPE_PUBLIC) { |
|
|
|
|
$query->andWhere($this->type . '=' . Page::TYPE_PUBLIC); |
|
|
|
@ -72,6 +71,12 @@ class PageForm extends CompositeForm
|
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function attributeHints() { |
|
|
|
|
return [ |
|
|
|
|
'slug' => Yii::t('page', 'SEO link will be generated automatically if not specified'), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function parentsList(): array |
|
|
|
|
{ |
|
|
|
|
return ArrayHelper::map(Page::find()->andWhere(['tree' => 1])->orderBy('lft')->asArray()->all(), 'id', function (array $page) { |
|
|
|
|