Menu

Maslosoft Framework Logo Maslosoft Framework Documentation
Flexible Application Foundation


Enum Decorator

Enum decorator allow styling of elements based on value of field.

To setup enum decorator, there must be enumerable class created. This should extend from EnumBase class. To define enumerable values, create constants in this class.

To set values to CSS classes mapping, define static method cssClasses(). This should return array with keys of constant and value of CSS classes, ie:

/**
     * Get css class for message type
     * @return string[]
     */
public static function cssClasses()
{
    return [
        self::Standard => '',
        self::Success => 'btn-success',
        self::Notice => 'btn-info',
        self::Warning => 'btn-warning',
        self::Error => 'btn-danger',
        self::None => 'btn-none'
    ];
}

To apply this styling to model use @Decorator annotation. First param is decorator type second is enum class name. Class literals can be used here. Use statments can be used to shorten class names to make code more readable.

To render css styled radiobutton list - use form render with @FormRenderer annotation and EnumCss as type. Second param is enum class.

Example of using enum decorator and form renderer for grid row on Message class:

/**
     * // Type of message, be it success, notice, warning etc.
     * @Label('Type')
     *
     * @Renderer('Enum', MessageType)
     * @FormRenderer(EnumCss, MessageType)
     *
     * @Decorator(RowEnumCss, MessageType)
     * @Decorator(RowAction, 'view')
     *
     * @RequiredValidator
     *
     * @see EnumCss
     * @see RowAction
     * @see RowEnumCss
     * @see MessageType
     * @var enum
     */
public $type;