beebmx/kirby-enum

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

Installs: 4

Dependents: 1

Suggesters: 0

Security: 0

Stars: 4

Watchers: 0

Forks: 0

Open Issues: 0

Type:kirby-plugin

1.0.1 2025-08-06 19:11 UTC

This package is auto-updated.

Last update: 2025-08-06 19:11:44 UTC


README

Build Status Total Downloads Latest Stable Version License

Kirby Enum

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

Kirby Courier 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

Kirby 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