public function generateCode()
{
if ($this->isRoot()) {
$this->setAttribute("code", null);
} else {
$filter = new FilterSeoPageName();
$filter->maxLength = \Yii::$app->cms->tree_max_code_length;
$this->code = $filter->filter($this->name);
$matches = [];
//Роутинг элементов нужно исключить
if (preg_match('/(?<id>\\d+)\\-(?<code>\\S+)$/i', $this->code, $matches)) {
$this->code = "s" . $this->code;
}
if (!$this->isValidCode()) {
$this->code = $filter->filter($this->code . "-" . substr(md5(uniqid() . time()), 0, 4));
if (!$this->isValidCode()) {
$this->generateCode();
}
}
}
return $this;
}