Search by

hryvinskyi / magento2-admin-setup-wizard

hryvinskyi

A setup-wizard frame for the Magento admin: scopes, settings with inheritance and deployment locks, a draft with review and save, and step plug-ins; a module builds its own wizard on it

Package info

github.com/hryvinskyi/magento2-admin-setup-wizard

Language:TypeScript

Type:magento2-module

pkg:composer/hryvinskyi/magento2-admin-setup-wizard

Statistics

Installs: 2

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-11-22 19:18 UTC

This package is auto-updated.

Last update: 2026-11-22 19:37:51 UTC


README

A setup-wizard frame for the Magento admin: scopes, settings with inheritance and deployment locks, a draft with review and save, and step plug-ins; a module builds its own wizard on it.

One installation holds several wizards. Everything is keyed by wizard id, and each declaration is checked only when its own wizard is asked for, so a wrong declaration of one wizard never stops another from opening.

Requirements and installation

PHP 8.1 or higher, hryvinskyi/magento2-admin-ui, psr/log and the platform's Backend, Config and Store modules (what composer.json and etc/module.xml declare).

composer require hryvinskyi/magento2-admin-setup-wizard
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush

The package has no settings, menu items or access rules of its own: each wizard brings them. Its admin route is hryvinskyi_setup_wizard (wizard/index, wizard/save, wizard/session).

Declaring a wizard

A module declares its wizard and its settings as data in its own global etc/di.xml (an area di.xml that names one of these arguments replaces the whole list in that area), and names Hryvinskyi_AdminSetupWizard in its module.xml sequence and composer.json.

<type name="Hryvinskyi\AdminSetupWizard\Model\Wizard\WizardDefinitions">
    <arguments>
        <argument name="definitions" xsi:type="array">
            <item name="my_wizard" xsi:type="array">
                <item name="title" xsi:type="string">Set up my feature</item>
                <item name="breadcrumbs" xsi:type="array">
                    <item name="stores" xsi:type="string">Stores</item>
                </item>
                <item name="icon" xsi:type="string">sliders</item>
                <item name="acl_resource" xsi:type="string">Vendor_Module::setup</item>
                <item name="menu_id" xsi:type="string">Vendor_Module::setup</item>
                <item name="config_section" xsi:type="string">my_section</item>
                <item name="close_route" xsi:type="string">adminhtml/dashboard/index</item>
                <item name="reach" xsi:type="string">store</item>
            </item>
        </argument>
    </arguments>
</type>
<type name="Hryvinskyi\AdminSetupWizard\Model\Setting\SettingDescriptors">
    <arguments>
        <argument name="descriptors" xsi:type="array">
            <item name="my_wizard" xsi:type="array">
                <item name="enabled" xsi:type="array">
                    <item name="path" xsi:type="string">my_section/general/enabled</item>
                    <item name="kind" xsi:type="string">flag</item>
                    <item name="step" xsi:type="string">basics</item>
                </item>
            </item>
        </argument>
    </arguments>
</type>
  • Definition (item name = the wizard id, ^[a-z][a-z0-9_]{0,31}$): title, acl_resource, menu_id, config_section, close_route are required; breadcrumbs, icon and reach (default, website or store, default store) are optional. The title and breadcrumbs are source phrases: declare them with translate="true" so the translation collector finds them; the wizard's page translates them when it prints them.
  • Setting (item name = the setting key): path (at least three segments), kind, step; optionally pattern (a PCRE pattern the browser can read too), case_insensitive, min, max. The label, options and reach come from the configuration page's own field for the path.
  • Kinds shipped: flag, choice, text, number, secret (a secret never leaves the server: the browser learns only whether one is set). A module adds a kind as an item of the kinds argument of Hryvinskyi\AdminSetupWizard\Model\Setting\SettingKinds, named after its code.
  • Field handlers: a setting stored under more than one path registers a Hryvinskyi\AdminSetupWizard\Api\SettingFieldsInterface under the fields argument of Hryvinskyi\AdminSetupWizard\Model\Setting\SettingFieldsPool, keyed by wizard id, then setting key.

Hryvinskyi\AdminSetupWizard\Api\WizardStateInterface::forWizard() returns the wizard's state as a plain array: the scopes the wizard offers and every setting the signed-in user may open, with its shipped value, the values stored scope by scope and the locks the deployment configuration sets. A setting fixed at the default scope is locked at every scope; one fixed for a website is locked at that website only.

The wizard's page

Every wizard is served from one admin page of this module: hryvinskyi_setup_wizard/wizard/index/id/<wizard id>. A module writes no controller, layout or template for its wizard; it adds a menu item that points at that route, under the wizard's access rule:

<add id="Vendor_Module::setup" title="Set up my feature" translate="title" module="Vendor_Module"
     parent="Magento_Backend::stores" resource="Vendor_Module::setup"
     action="hryvinskyi_setup_wizard/wizard/index/id/my_wizard"/>

An unknown wizard id is answered with the admin's "not found", a user without the wizard's access rule with its "denied". The page carries the definition's title, breadcrumbs and menu item, and opens at the website or store view its address names (website, store) when the wizard offers that scope.

The wizard is an island of the admin UI kit (hryvinskyi/magento2-admin-ui): the kit's page host prints its root, its loading line, the kit's part of its document and its page configuration (the document's page member), the import map and the module script, and links the kit's stylesheet before the wizard's. The wizard is drawn with the kit's parts and ships no copy of the kit or of Preact.

Contributing to a wizard's page

A step plug-in adds to one wizard's page through the contributions argument of Hryvinskyi\AdminSetupWizard\Model\Page\Contributions, keyed by wizard id, then by a name of the module's choice. Hryvinskyi\AdminSetupWizard\Model\Page\Contribution takes the five parts as data:

<virtualType name="VendorModuleWizardContribution" type="Hryvinskyi\AdminSetupWizard\Model\Page\Contribution">
    <arguments>
        <argument name="phrases" xsi:type="array">
            <item name="vendor.step.title" xsi:type="string" translate="true">Connection</item>
        </argument>
        <argument name="plugins" xsi:type="array">
            <item name="vendor_step" xsi:type="string">@vendor/module-wizard-step</item>
        </argument>
        <argument name="imports" xsi:type="array">
            <item name="@vendor/module-wizard-step" xsi:type="string">Vendor_Module::js/wizard/step.js</item>
        </argument>
        <argument name="styles" xsi:type="array">
            <item name="step" xsi:type="string">Vendor_Module::css/wizard-step.css</item>
        </argument>
    </arguments>
</virtualType>
<type name="Hryvinskyi\AdminSetupWizard\Model\Page\Contributions">
    <arguments>
        <argument name="contributions" xsi:type="array">
            <item name="my_wizard" xsi:type="array">
                <item name="vendor_module" xsi:type="object">VendorModuleWizardContribution</item>
            </item>
        </argument>
    </arguments>
</type>
  • Phrases: text keyed by phrase key, translated each time the page is built.
  • Plug-ins: plug-in id (^[a-z][a-z0-9_]{0,31}$) → the bare specifier the frame imports it by; some contribution to the same wizard must import that specifier.
  • Imports: bare specifier → the file id of a built module (Vendor_Module::path/file.js or .mjs).
  • Styles: stylesheet file ids, linked after the frame's own.
  • Extension data: plug-in id → plain JSON data for that plug-in alone; it is printed into the page, so never a secret.

Contributions add up; a key given twice with different values is a fault of that wizard's declaration and fails its page alone. The frame's own phrases, shared modules and stylesheet are on every wizard's page. The shared modules are the kit's four, which the page host maps on every island page (preact, preact/hooks, preact/jsx-runtime and @hryvinskyi/admin-ui), and @hryvinskyi/admin-setup-wizard, the SDK the frame and every plug-in import. A plug-in imports the kit's specifiers without declaring them; a contribution whose imports name one of them is a fault of that wizard's declaration.

Draft items: what a wizard saves besides settings

Rows of a module's own, such as a list of entries or a switch per category, are a draft item. The module implements Hryvinskyi\AdminSetupWizard\Api\DraftItemProviderInterface (an id, the access rule, its endpoints, its slice of state) and adds it to the draftItems argument of Hryvinskyi\AdminSetupWizard\Model\Item\DraftItems, keyed by wizard id, then item id, in its global etc/di.xml. The wizard hands the item's slice to the page only for a user the item's access rule allows, and gives the page the item's endpoints as full admin addresses with the session's secret key; settings are saved by the wizard, the item by its own endpoint.

The item's save endpoint checks its own access rule, takes a POST with a JSON body read through Api\Http\JsonBodyInterface (the form key travels in the query string), is safe to repeat, and answers through Api\Http\JsonAnswerInterface: a refused request is an InvalidWizardRequestException (400 {"error": reason}), anything else is logged and answered 500. A wrong registration fails its own wizard only.

In the browser a step plug-in registers its steps, requirements and draft items through the SDK (registerStep, registerRequirement, registerDraftItem) and may add review sections, the primary button's label, the saved panel and a header badge (registerReviewSection, registerSaveLabel, registerSavedPanel, registerHeaderBadge). An item with saveOrder: 'last' is sent after every other item, and only when the settings and every item before it were stored; otherwise its rows stay pending as held and a later save sends them.

Type-checking a step plug-in

A plug-in type-checks against the published declarations alone: the SDK's (frontend/setup-wizard/types/sdk/index.d.ts in this package) and the admin UI kit's (frontend/admin-ui/types/index.d.ts in hryvinskyi/magento2-admin-ui), which the SDK's declarations import. Its own tsconfig.json maps both specifiers, and the UI library's three entry points to its own installed copy, so the SDK, the kit and the plug-in see one Preact. A mapping lists one candidate per layout the packages may be installed in; the first that exists is used. For a workspace in frontend/<name>/ of a module:

{
    "compilerOptions": {
        "jsx": "react-jsx",
        "jsxImportSource": "preact",
        "paths": {
            "@hryvinskyi/admin-setup-wizard": [
                "../../../AdminSetupWizard/frontend/setup-wizard/types/sdk/index.d.ts",
                "../../../magento2-admin-setup-wizard/frontend/setup-wizard/types/sdk/index.d.ts",
                "../../../../../../vendor/hryvinskyi/magento2-admin-setup-wizard/frontend/setup-wizard/types/sdk/index.d.ts"
            ],
            "@hryvinskyi/admin-ui": [
                "../../../AdminUi/frontend/admin-ui/types/index.d.ts",
                "../../../magento2-admin-ui/frontend/admin-ui/types/index.d.ts",
                "../../../../../../vendor/hryvinskyi/magento2-admin-ui/frontend/admin-ui/types/index.d.ts"
            ],
            "preact": ["./node_modules/preact/src/index.d.ts"],
            "preact/hooks": ["./node_modules/preact/hooks/src/index.d.ts"],
            "preact/jsx-runtime": ["./node_modules/preact/jsx-runtime/src/index.d.ts"]
        }
    }
}

The candidates cover the packages checked out side by side under app/code/Hryvinskyi/, both installed by Composer under vendor/hryvinskyi/, and a module under app/code/ with the packages installed by Composer. The plug-in pins the same Preact version as the kit, since the page loads the kit's.

Translations

The frame's wording ships in en_US and 25 more locales: the official languages of the European Union, Norwegian Bokmål and Ukrainian. The translations are machine-made; have them read by a native speaker before a store relies on them.

Tests

  • Unit: vendor/bin/phpunit -c app/code/Hryvinskyi/AdminSetupWizard/phpunit.xml.dist.
  • Integration: the platform's harness in dev/tests/integration.
  • The browser frame and SDK: frontend/setup-wizard/ (npm run check, npm test, npm run build, npm run verify-build, which checks that the committed view/adminhtml/web/js/wizard/sdk.js and wizard.js match their sources).