beebmx/kirby-enum 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

beebmx/kirby-enum

最新稳定版本:1.0.3

Composer 安装命令:

composer require beebmx/kirby-enum

包简介

Enum adds the ability to display and set enumeration content in the panel.

README 文档

README

Build Status Total Downloads Latest Stable Version License

Enum for Kirby

Enum adds the ability to display and set enumeration content in the panel.

Enum example

Overview

Installation

Download

Download and copy this repository to /site/plugins/kirby-enum.

Composer

composer require beebmx/kirby-enum

Field properties

Name Type Default Description
as string select Set the field you want to display and manipulate the enum data.
enum string null Set the namespace of the enum to populate the field.

Example

fields:
  enum:
    label: Status
    type: enum
    enum: App\Enums\Status

Note

When you reference an enum it must be a fully qualified class name, should be available with a namespace.

An enum class can be defined like this:

namespace App\Enums;

enum Status: string
{
    case Inactive = 'inactive';
    case Active = 'active';
    case Archived = 'archived';
}

Displaying field

When you use an enum field, it's just a wrapper around some Kirby fields. By default, it will display the value as a select field, but you can change this behavior by setting the as property in your blueprint:

fields:
  enum:
    label: Status
    type: enum
    enum: App\Enums\Status
    as: radio

Here's the list of the available options for the enum field:

Note

You can set fields properties of every field to customize the behavior of the enum field.

Labels

By default, the text displayed in the options will be the name of the enum case, but you can customize this by implementing HasLabel interface in your enum class:

namespace App\Enums;

use Beebmx\KirbyEnum\Contracts\HasLabel;

enum Network: string implements HasLabel
{
    case Facebook = 'facebook';
    case Instagram = 'instagram';
    case TikTok = 'tiktok';
    case Mastodon = 'mastodon';

    public function toLabel(): string
    {
        return match ($this) {
            self::Facebook => 'Facebook network',
            self::Instagram => 'Instagram network',
            self::TikTok => 'TikTok network',
            self::Mastodon => 'Mastodon network',
        };
    }
}

Usage in templates

Enum comes with a convenient field method to retrieve the proper enum case in your templates.

<?php

$status = $page->enum()->toEnum();

$status->value; // 'active'
$status->name; // 'Active'

If you have implemented custom methods in your enum class, you can call them as well:

<?php

$network = $page->network()->toEnum();

$network->toIcon();

License

Licensed under the MIT.

Credits

统计信息

  • 总下载量: 64
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-05