Skip to Content
Module developmentInterface

What modules and themes add to Studio

A data source for code blocks, ready-made looks for a module's block, a game site template and how a module's page behaves in Studio.

By the end the module has an example_top data source that blocks with an HTML template read live rows from, and its own site template in the "New page" dialog. A theme can add ready-made looks to the module's block. The module's block itself is covered in Blocks and zones for Studio.

What goes where

Studio reads palettes, fonts and decor packs from theme folders, not from a registry: DecorRegistry, FontRegistry and PresetRegistry have no registration method, so there is nothing to call from boot(). A module adds four things to Studio, and a theme adds one.

WhatWho brings itWhere it is covered
a block in the block listmoduleBlocks and zones for Studio
a data source for code blocksmodulebelow
a game site templatemodulebelow
how the module page behaves in the editormodulebelow
ready-made block looksthemebelow
palettes, fonts, decor packsthemeTheme parameters

Data source

A block with an HTML template, which the owner writes on the Code tab or gets from the FluteAi module, repeats {{#items}}…{{/items}} for each row. The rows come from the "Data source" field, which holds the source key and parameters, for example example_top sort=name limit=6. A module provides such a source with a ComponentSource class.

app/Modules/Example/Studio/TopSource.php
<?php

declare(strict_types = 1);

namespace Flute\Modules\Example\Studio;

use Flute\Core\Modules\Studio\Components\Data\ComponentSource;
use Flute\Modules\Example\Services\Leaderboard;

final class TopSource implements ComponentSource
{
    public function __construct(
        private readonly Leaderboard $leaderboard,
    ) {
    }

    public function key(): string
    {
        return 'example_top';
    }

    public function label(): string
    {
        return (string) __('example.studio.top');
    }

    public function description(): string
    {
        return 'rows: title (player name), text (score), image (avatar), link (profile)';
    }

    public function params(): array
    {
        return ['sort' => 'score | name'];
    }

    public function fields(): array
    {
        return ['title', 'text', 'image', 'link'];
    }

    public function rows(array $params, int $limit): array
    {
        $sort = ( $params['sort'] ?? 'score' ) === 'name' ? 'name' : 'score';

        return array_map(
            static fn(array $row): array => [
                'title' => (string) $row['name'],
                'text' => (string) $row['score'],
                'image' => (string) $row['avatar'],
                'link' => (string) $row['url'],
            ],
            $this->leaderboard->top($limit, $sort),
        );
    }
}

Register the source by class name in the provider's boot(), and the container builds the object:

use Flute\Core\Surfaces\SurfaceKeys;
use Flute\Core\Surfaces\SurfaceRegistry;
use Flute\Modules\Example\Studio\TopSource;

$container->get(SurfaceRegistry::class)->add(SurfaceKeys::STUDIO_COMPONENT_SOURCE, TopSource::class);

The Clans module's clan ranking and the Achievements module's leaders are wired this way. How the owner writes a block template is covered in Code in Studio.

How it works

A key is lowercase Latin letters, digits and _. When a key is taken, the source registered first wins, and the core registers its own sources (servers, site_stats and others) before modules. The FluteAi module reads description(), params() and fields() when it builds a block, so write them in English on one line.

rows() receives only the parameters declared in params(), and the core clamps limit to 1–12. From the answer the core keeps array rows with fields named like title or image_2 and scalar values, and cuts strings to 300 characters. The result is cached for 45 seconds per parameter set and language, and an empty answer for 10 seconds. An exception from rows() goes to the sections log as studio.component_source.failed, and the block shows the items the owner filled in by hand.

The rows end up in the page cache for guests. Return public data only: no emails, IPs, tokens or RCON passwords.

Ready-made block looks

A theme can style a module's block in advance. The file lives in the theme's presets/blocks/<folder>/<name>.json, and the type field ties it to the block. The owner sees these looks in the "Ready-made looks" group of the block list and on the Look tab.

app/Themes/nightfall/presets/blocks/example.top/compact.json
{
    "key": "example.top.compact",
    "version": "1.0.0",
    "type": "example.top",
    "label": "nightfall.looks.example_top_compact",
    "layout": { "width": "narrow", "rhythm": "s" },
    "style": { "surface": "soft", "radius": "l", "titleScale": "m" },
    "settings": { "limit": "3" }
}
GroupAxisValues
layoutwidthnarrow, normal, wide, full
layoutrhythms, m, l, xl
layoutmedianone, top, side, background
layoutalignstart, center
stylesurfacenone, soft, accent
styleradiuss, m, l
styletitleScalem, l, xl
styledividernone, line, slope
styleeffectnone, reveal

A look with no axis at all doesn't load. Only the axes the block returns from axes() count.

settings holds at most 40 keys, with values as strings, the way Studio stores them. label goes through __(), so either a translation key or plain text works. A child theme sees its parent's looks.

Game site template

The templates in "New page" → "From a template" and in the game choice during installation are Resources/starters/<key>.json files. A module adds its folder in boot():

use Flute\Core\Modules\Studio\Starters\StarterCatalog;

$container->get(StarterCatalog::class)->addDirectory(dirname(__DIR__) . '/Resources/starters');

A file with a new key adds a template. A file with the key of a core template (cs2, rust, minecraft and others) replaces it entirely, so start from the file in app/Core/Modules/Studio/Resources/starters/ and edit it.

The key in the file must match the file name. When two modules replace the same template, the higher priority wins. The shared pages from the core's _base.json are added to every template unless the template replaces a page with the same role.

Put a block into a template with a condition, so the template still works without the module:

{ "type": "example.top", "needs": "block:example.top", "settings": { "title": { "ru": "Лучшие игроки", "en": "Top players" } } }

needs takes block:<type>, source:<key> and store, a leading ! inverts the condition, and every condition in a list must hold. Texts are {ru, en} pairs, and other languages get the English one. The Wipes module puts its wipe countdown block into the Rust template this way.

A module page in Studio

Studio opens a module page drawn by a controller as a "Built-in section": the owner changes wording, adds their own blocks and opens the module settings. The owner's side is shown in Module pages. A few things depend on the module's markup.

Studio takes the tallest child of <main> as the content area and draws the places for own blocks between its direct children. Keep the parts of the page as siblings inside one wrapper, and give each part its own heading: the picker names the place after it, "After “Top players”". Each place is remembered by the element's features (tag, id, classes, attributes), so the ids and data-* attributes of the parts must not change from request to request. State classes such as is-active and attributes such as data-state are ignored.

The page name in the editor's top bar comes from <title> up to " — ". The "Section settings" link appears when module.json sets settings and the viewer is an administrator. Zones from ModuleZones::register() are listed on the Page tab too.

Reference

MethodWhat it does
SurfaceRegistry::add(SurfaceKeys::STUDIO_COMPONENT_SOURCE, string $class)registers a data source, the container builds the class
ComponentSource::rows(array $params, int $limit): arrayrows as list<array<string, scalar>>, at most $limit
ComponentSource::params(): arrayparameter name → its meaning on one line, don't list limit
StarterCatalog::addDirectory(string $directory): voidadds a folder of site templates

Common mistakes

Message or symptomCause
Studio preset '<file>' rejected: Block preset '<key>' carries no known axis. in the loglayout and style hold no known axis
... declares an unusable block type '<type>'. in the logtype has capital letters or a space
the theme's look doesn't show for the blocktype differs from the block's key()
the look applies only in partthe axis is not in the block's axes() and is skipped
the code block shows only the items typed in by handthe core already owns the source key, rows() throws, or it returned an empty list
the module's template doesn't appearthe key in the file differs from the file name, or there is no pages array

Further reading

On this page