PHPackages                             beebmx/kirby-enum - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. beebmx/kirby-enum

ActiveKirby-plugin[Utility &amp; Helpers](/categories/utility)

beebmx/kirby-enum
=================

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

1.0.3(8mo ago)7771MITPHPCI passing

Since Aug 5Pushed 8mo agoCompare

[ Source](https://github.com/beebmx/kirby-enum)[ Packagist](https://packagist.org/packages/beebmx/kirby-enum)[ RSS](/packages/beebmx-kirby-enum/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (5)Used By (1)

[![Build Status](https://camo.githubusercontent.com/fa86c49eb350cb4baa4f4ba6c3c4d20e941f100b74b53880ccd3fd3beb98d56a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f626565626d782f6b697262792d656e756d2f74657374732e796d6c3f6272616e63683d6d61696e)](https://github.com/beebmx/kirby-enum/actions)[![Total Downloads](https://camo.githubusercontent.com/a350cc23c55d14cf798049cdac886b14987e9b885c4d4020616ba6ed5318ab18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626565626d782f6b697262792d656e756d)](https://packagist.org/packages/beebmx/kirby-enum)[![Latest Stable Version](https://camo.githubusercontent.com/5e098e72247a56c525d271a7687c217a63e1d9eb91c6263f0a7092289e3a0262/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626565626d782f6b697262792d656e756d)](https://packagist.org/packages/beebmx/kirby-enum)[![License](https://camo.githubusercontent.com/d31d6a1f84bdc9065295aae36a84ad3caaa460b0761641726e1401aefbbcb57e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626565626d782f6b697262792d656e756d)](https://packagist.org/packages/beebmx/kirby-enum)

Enum for Kirby
==============

[](#enum-for-kirby)

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

[![Enum example](/.github/assets/banner.jpg)](/.github/assets/banner.jpg)

---

Overview
--------

[](#overview)

- [1. Installation](#installation)
- [2. Field properties](#field-properties)
- [3. Usage in templates](#usage-in-templates)
- [4. License](#license)
- [5. Credits](#credits)

Installation
------------

[](#installation)

### Download

[](#download)

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

### Composer

[](#composer)

```
composer require beebmx/kirby-enum

```

Field properties
----------------

[](#field-properties)

NameTypeDefaultDescriptionasstring`select`Set the field you want to display and manipulate the enum data.enumstring`null`Set the namespace of the `enum` to populate the field.### Example

[](#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

[](#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:

- [Checkboxes](https://getkirby.com/docs/reference/panel/fields/checkboxes)
- [Multiselect](https://getkirby.com/docs/reference/panel/fields/multiselect)
- [Radio](https://getkirby.com/docs/reference/panel/fields/radio)
- [Select](https://getkirby.com/docs/reference/panel/fields/select)
- [Tags](https://getkirby.com/docs/reference/panel/fields/tags)
- [Toggles](https://getkirby.com/docs/reference/panel/fields/toggles)

Note

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

### Labels

[](#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
------------------

[](#usage-in-templates)

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

```
