Browse Source

Frontend single language menu fix

master
Egorka 6 years ago
parent
commit
262a3fcf3f
  1. 114
      core/forms/menu/MenuItemForm.php

114
core/forms/menu/MenuItemForm.php

@ -9,76 +9,80 @@ use Yii;
class MenuItemForm extends LanguageDynamicModel
{
public $menu_id;
public $parent_id;
public $name;
public $title_attr;
public $target;
public $css;
public $style;
public $module;
public $url;
public $url_params;
public $parent_id;
public $name;
public $title_attr;
public $target;
public $css;
public $style;
public $module;
public $url;
public $url_params;
private $_menu;
public function __construct(MenuItem $menu = null, array $attributes = [], $config = [])
{
if ($menu) {
$this->menu_id = $menu->menu_id;
$this->parent_id = $menu->parent_id;
$this->target = $menu->target;
$this->css = $menu->css;
$this->style = $menu->style;
$this->module = $menu->module;
$this->url = $menu->url;
$this->menu_id = $menu->menu_id;
$this->parent_id = $menu->parent_id;
$this->target = $menu->target;
$this->css = $menu->css;
$this->style = $menu->style;
$this->module = $menu->module;
$this->url = $menu->url;
$this->url_params = $menu->url_params;
$this->_menu = $menu;
}
parent::__construct($menu, $attributes, $config);
if ($menu) {
foreach ( $menu->translations as $translate ) {
if ($translate->language == Yii::$app->params['backendDefaultLanguage']) {
$this->name = $translate->name;
$this->title_attr = $translate->title_attr;
}
else {
$this->{'name' . '_' . $translate->language} = $translate->name;
$this->{'title_attr' . '_' . $translate->language} = $translate->title_attr;
}
};
}
if ($menu) {
foreach ($menu->translations as $translate) {
if (!in_array($translate->language, $menu->translatedLanguages)) {
continue;
}
if ($translate->language == Yii::$app->params['backendDefaultLanguage']) {
$this->name = $translate->name;
$this->title_attr = $translate->title_attr;
} else {
$this->{'name' . '_' . $translate->language} = $translate->name;
$this->{'title_attr' . '_' . $translate->language} = $translate->title_attr;
}
};
}
}
public function rules(): array
{
return array_merge(
parent::rules(),
[
[['name', 'menu_id'], 'required'],
[['name', 'title_attr', 'css', 'style', 'module', 'url'], 'string', 'max' => 255],
[['target'], 'string', 'max' => 20],
['url_params', 'string'],
[['parent_id', 'menu_id'], 'integer'],
]
);
return array_merge(
parent::rules(),
[
[['name', 'menu_id'], 'required'],
[['name', 'title_attr', 'css', 'style', 'module', 'url'], 'string', 'max' => 255],
[['target'], 'string', 'max' => 20],
['url_params', 'string'],
[['parent_id', 'menu_id'], 'integer'],
]
);
}
public function attributeLabels() {
return array_merge(
parent::attributeLabels(),
[
'menu_id' => Yii::t('menu', 'Menu'),
'parent id' => Yii::t('menu', 'Parent menu item'),
'name' => Yii::t('menu', 'Name'),
'title_attr' => Yii::t('menu', 'Title attribute'),
'target' => Yii::t('menu', 'Target'),
'css' => Yii::t('menu', 'CSS Classes'),
'style' => Yii::t('menu', 'CSS Style'),
'module' => Yii::t('menu', 'Module'),
'url' => Yii::t('menu', 'Url'),
'url_params' => Yii::t('menu', 'Url Params'),
]
);
}
public function attributeLabels()
{
return array_merge(
parent::attributeLabels(),
[
'menu_id' => Yii::t('menu', 'Menu'),
'parent id' => Yii::t('menu', 'Parent menu item'),
'name' => Yii::t('menu', 'Name'),
'title_attr' => Yii::t('menu', 'Title attribute'),
'target' => Yii::t('menu', 'Target'),
'css' => Yii::t('menu', 'CSS Classes'),
'style' => Yii::t('menu', 'CSS Style'),
'module' => Yii::t('menu', 'Module'),
'url' => Yii::t('menu', 'Url'),
'url_params' => Yii::t('menu', 'Url Params'),
]
);
}
}

Loading…
Cancel
Save