From 6427712512379ea13035f2a64a1cd6aba1e69453 Mon Sep 17 00:00:00 2001 From: Manop Kongoon Date: Fri, 27 Feb 2026 09:32:45 +0700 Subject: [PATCH] feat: add icon field to frontend menu --- CHANGELOG.md | 1 + .../views/menu-frontend/_form.php | 7 ++++-- .../views/menu-frontend/index.php | 4 ++- .../views/menu-frontend/view.php | 5 ++++ common/models/CmsMenuFrontend.php | 3 +++ ...icon_column_to_cms_menu_frontend_table.php | 25 +++++++++++++++++++ 6 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 console/migrations/m260227_023007_add_icon_column_to_cms_menu_frontend_table.php diff --git a/CHANGELOG.md b/CHANGELOG.md index e96e2c60..83deb07f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,3 +3,4 @@ - Fixed incorrect aggregation in monthly and yearly statistics. - Adjusted footer contact information font style for better readability. - Added frontend menu management system in administrator module (navbar and left menu positions). +- Added 'icon' support for frontend menu management. diff --git a/backend/modules/administrator/views/menu-frontend/_form.php b/backend/modules/administrator/views/menu-frontend/_form.php index 352921c8..dac4b174 100644 --- a/backend/modules/administrator/views/menu-frontend/_form.php +++ b/backend/modules/administrator/views/menu-frontend/_form.php @@ -15,10 +15,13 @@ use yii\helpers\ArrayHelper;
-
+
field($model, 'name')->textInput(['maxlength' => true]) ?>
-
+
+ field($model, 'icon')->textInput(['maxlength' => true, 'placeholder' => 'fa fa-home']) ?> +
+
field($model, 'link')->textInput(['maxlength' => true]) ?>
diff --git a/backend/modules/administrator/views/menu-frontend/index.php b/backend/modules/administrator/views/menu-frontend/index.php index e0602c23..31c0f204 100644 --- a/backend/modules/administrator/views/menu-frontend/index.php +++ b/backend/modules/administrator/views/menu-frontend/index.php @@ -28,8 +28,10 @@ $this->params['breadcrumbs'][] = $this->title; ['class' => 'yii\grid\SerialColumn'], [ 'attribute' => 'name', + 'format' => 'raw', 'value' => function ($model) { - return ($model->parent_id ? '— ' : '') . $model->name; + $icon = $model->icon ? Html::tag('i', '', ['class' => $model->icon]) . ' ' : ''; + return ($model->parent_id ? '— ' : '') . $icon . $model->name; } ], 'link', diff --git a/backend/modules/administrator/views/menu-frontend/view.php b/backend/modules/administrator/views/menu-frontend/view.php index 4ac1e2e7..fa3c489d 100644 --- a/backend/modules/administrator/views/menu-frontend/view.php +++ b/backend/modules/administrator/views/menu-frontend/view.php @@ -38,6 +38,11 @@ $this->params['breadcrumbs'][] = $this->title; 'value' => $model->parent ? $model->parent->name : '-- เป็นเมนูหลัก --', ], 'name', + [ + 'attribute' => 'icon', + 'format' => 'raw', + 'value' => $model->icon ? Html::tag('i', '', ['class' => $model->icon]) . ' (' . Html::encode($model->icon) . ')' : null, + ], 'link', [ 'attribute' => 'position', diff --git a/common/models/CmsMenuFrontend.php b/common/models/CmsMenuFrontend.php index 23f27f76..787fc4e8 100644 --- a/common/models/CmsMenuFrontend.php +++ b/common/models/CmsMenuFrontend.php @@ -11,6 +11,7 @@ use yii\behaviors\TimestampBehavior; * @property int $id * @property int|null $parent_id * @property string $name + * @property string|null $icon * @property string|null $link * @property string $position navbar, left_menu * @property int|null $sort_order @@ -50,6 +51,7 @@ class CmsMenuFrontend extends \yii\db\ActiveRecord [['parent_id', 'sort_order', 'status', 'created_at', 'updated_at'], 'integer'], [['name', 'position'], 'required'], [['name', 'link'], 'string', 'max' => 255], + [['icon'], 'string', 'max' => 100], [['position'], 'string', 'max' => 50], [['parent_id'], 'exist', 'skipOnError' => true, 'targetClass' => CmsMenuFrontend::class, 'targetAttribute' => ['parent_id' => 'id']], ]; @@ -64,6 +66,7 @@ class CmsMenuFrontend extends \yii\db\ActiveRecord 'id' => 'ID', 'parent_id' => 'เมนูหลัก', 'name' => 'ชื่อเมนู', + 'icon' => 'ไอคอน (เช่น fa fa-home)', 'link' => 'ลิงก์', 'position' => 'ตำแหน่ง', 'sort_order' => 'ลำดับ', diff --git a/console/migrations/m260227_023007_add_icon_column_to_cms_menu_frontend_table.php b/console/migrations/m260227_023007_add_icon_column_to_cms_menu_frontend_table.php new file mode 100644 index 00000000..f6606ce3 --- /dev/null +++ b/console/migrations/m260227_023007_add_icon_column_to_cms_menu_frontend_table.php @@ -0,0 +1,25 @@ +addColumn('{{%cms_menu_frontend}}', 'icon', $this->string(100)->after('name')); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('{{%cms_menu_frontend}}', 'icon'); + } +}