Modül geliştirme

Bu sayfada
Bu geliştirici başvurusu şimdilik yalnızca İngilizcedir; kod örnekleri ve adlar iki dilde de aynıdır.

Modules (extensions) add features to IronCMS without touching the core. The system is WordPress-like in feel (drop a folder, declare a manifest, hook into the core) but uses PSR-4 namespaces for isolation and a versioned manifest for dependencies — so you get familiarity without the global-scope and collision problems.

Directory layout

Modules live under modules/ at the project root, namespaced by vendor:

text
modules/
└── Acme/
    └── Seo/
        ├── module.json          # manifest (required)
        ├── Module.php           # bootstrap class (required)
        ├── Config/
        │   └── Routes.php       # auto-discovered when "hasRoutes": true
        ├── Controllers/         # @permission docblocks feed RBAC
        ├── Database/
        │   └── Migrations/      # run on activate() when "hasMigrations": true
        ├── Views/               # namespaced views: Modules\Acme\Seo\Views
        └── public/              # published to public/modules/acme/seo when "providesAssets": true
  • Folder path must match the manifest namespace: Modules\Acme\Seo →

modules/Acme/Seo/.

  • The loader registers the module's PSR-4 namespace at runtime, so all classes

under it autoload normally.

The manifest — module.json

json
{
    "name": "acme/seo",
    "title": "SEO Pack",
    "description": "Meta tags, sitemaps and Open Graph for IronCMS.",
    "version": "1.0.0",
    "namespace": "Modules\\Acme\\Seo",
    "bootstrap": "Modules\\Acme\\Seo\\Module",
    "author": "Acme",
    "authorUrl": "https://acme.example",
    "license": "Commercial",
    "requires": {
        "php": ">=8.2",
        "ironcms": ">=1.0.0",
        "modules": {
            "acme/core": ">=1.1"
        }
    },
    "hasMigrations": true,
    "hasRoutes": true,
    "providesAssets": true,
    "icon": "<svg ...></svg>",
    "tags": ["seo", "marketing"]
}

Field reference

FieldRequiredTypeNotes
name✅stringvendor/slug, lowercase [a-z0-9-]. Unique identity.
title✅stringHuman-readable name shown in the admin.
version✅string (semver)MAJOR.MINOR.PATCH, e.g. 1.0.0.
namespace✅stringPSR-4 root; must start with Modules\.
bootstrapstring (FQCN)Class implementing ModuleInterface. Default: {namespace}\Module.
descriptionstringShort summary.
authorstring
authorUrlstring (URL)
licensestringe.g. MIT, Commercial.
requiresobjectDependency constraints (see below).
hasMigrationsboolModule ships Database/Migrations. Default false.
hasRoutesboolModule ships Config/Routes.php. Default false.
providesAssetsboolModule ships a public/ dir to publish. Default false.
iconstringInline SVG / asset path for the admin list.
tagsstring[]Free-form labels.

requires and version constraints

requires.php, requires.ironcms and each entry of requires.modules use a single constraint string. Supported syntax:

ConstraintMeaning
*, "", anyany version
1.2.3exact match
>=1.2, >1.2, <=1.2, <1.2, =1.2.3comparison
^1.2.3>=1.2.3 and <2.0.0 (compatible within the same major)

Ranges and || are intentionally not supported — keep requirements simple.

The bootstrap class & lifecycle

Extend App\Libraries\Modules\AbstractModule and override only what you need.

php
<?php

namespace Modules\Acme\Seo;

use App\Libraries\Modules\AbstractModule;

class Module extends AbstractModule
{
    /** Runs on every request while the module is enabled. */
    public function boot(): void
    {
        // Add a sidebar item (WordPress-style self-wiring).
        $this->addFilter('admin_menu', function (array $items) {
            $items[] = [
                'key'      => 'acme-seo',
                'title'    => 'Acme/Seo.menu.title',
                'route'    => 'acme_seo',
                'priority' => 75,
                'icon'     => $this->manifest()->icon,
            ];
            return $items;
        });

        // Inject something into the admin <head>.
        $this->addFilter('ironcms_admin_head', fn (string $head) => $head . '<!-- seo -->');
    }

    /** One-time, when the module is enabled. */
    public function activate(): void
    {
        // Migrations declared via "hasMigrations" are run by the loader.
        // Do any extra seeding here.
    }

    /** One-time, when the module is disabled. Keep user data. */
    public function deactivate(): void
    {
    }

    /** When the module is deleted. Drop tables/data here. */
    public function uninstall(): void
    {
    }
}
MethodWhen it runsUse for
boot()every request, module enabledregister hooks, filters, menu items, routes
activate()once, on enablemigrations, seed data, publish assets
deactivate()once, on disableunregister side-effects; keep user data
uninstall()on deletedrop tables, remove all module data

Helpers available from AbstractModule: $this->manifest(), $this->path('Views/x.php'), $this->addAction(...), $this->addFilter(...).

Database tables

A module that needs its own tables sets "hasMigrations": true and ships Database/Migrations/. The admin lifecycle then behaves like WordPress plugins:

Admin actionWhat happensData
Install (first enable)the module's migrations run (latest(), namespace-scoped), then activate()tables created
Enable (re-activate)the module boots againtables kept
Disablethe module stops booting (menu/routes/hooks removed)tables & data kept
Uninstalluninstall() runs, then the module's migration-tracking rows are clearedtables & data removed

Rules:

  • Drop your own tables in uninstall() (or your migration down()). The

loader does not auto-rollback: CI4's regress() works by global batch across all namespaces, so rolling back a single module is unsafe.

  • After uninstall the loader clears your module's rows from the migrations table

(scoped to your namespace) so a fresh install re-runs your migrations cleanly.

  • Keep migrations idempotent (CREATE TABLE IF NOT EXISTS) so

install → uninstall → reinstall cycles never error.

The admin Modules screen shows Install for a never-installed module and Enable once it is installed but disabled.

Hook catalog (core extension points)

Register these in boot(). The full action/filter API lives in app/Core.php (inAddAction / inAddFilter / inDoAction / inApplyFilters).

Filters (transform a value, must return it)

TagValuePurpose
admin_menuarray $itemsAdd/modify sidebar items (see Config\AdminMenu for the item shape).
ironcms_admin_headstring $htmlAppend markup to the admin <head>.
ironcms_admin_footerstring $htmlAppend markup before </body>.
ironcms_outputstring $htmlFinal transform of the full rendered page.

Actions (side effects, no return)

TagArgsPurpose
before_renderstring $view, array $dataRun before a view renders via inRender().
after_renderstring $viewRun after a view renders.

Modules may also define their own tags with inDoAction() / inApplyFilters() for other modules to extend.

Module settings

A module registers settings fields through the settings_fields filter. They appear automatically in the admin Settings screen (it is registry-driven) and are persisted to the key-value options store. Namespace your keys to avoid clashes:

php
public function boot(): void
{
    $this->addFilter('settings_fields', static function (array $fields) {
        $fields[] = [
            'key'     => 'module:acme/seo:api_key', // namespaced; ':' and '/' are POST-safe
            'group'   => 'modules',                  // a tab; an unknown group creates a new tab
            'type'    => 'text',                     // text|textarea|email|number|password|toggle|select
            'label'   => 'API Key',
            'default' => '',
            'rules'   => 'permit_empty',
        ];

        return $fields;
    });
}

Read or write the value anywhere with the global helpers:

php
$key = setting('module:acme/seo:api_key');         // registry default used when unset
setting_set('module:acme/seo:api_key', 'abc123');

Avoid . or spaces in keys — PHP rewrites those characters in POST field names.

Permissions

Admin controllers expose permissions through @permission docblocks; the core discovers them by reflection and wires them into RBAC:

php
/**
 * @permission {controller}_{method} Manage SEO settings
 */
public function index() { /* ... */ }

The loader extends this scan to enabled modules' controller directories, so a module's permissions appear in the Roles screen automatically.

Isolation & the module contract

Live in your own namespace.

  • Every module class is under Modules\Vendor\Slug — no global functions or

unprefixed classes.

  • All product-facing strings are English and go through lang()

(Modules/Acme/Seo language namespace). Turkish, if shipped, is a secondary locale only.

  • Never strip the brand guard: the rendered admin <title> must contain

"IronCMS" (enforced by inRender()).

Own your data — the data wall (enforced).

  • Declare your tables in dataSources(). The data capsule (admin export /

import) only ever reads or writes the tables you declared — never core or system tables. A capsule that references any other table is rejected; the raw SQL it carries is restricted to CREATE TABLE / INSERT INTO on your own (prefixed) tables; schema.sql / data.sql are SHA-256-verified against the manifest. There is no package signing — this structural wall is the guarantee.

  • So a module can never use a capsule to write users, settings, etc.

Read the core, extend via hooks — don't raw-write the core (contract).

  • Read core data through its models / services (users, settings, media, pages…).
  • Extend the core only through hooks and registries — admin_menu,

settings_fields, action_center_recommendations, TranslatableTypes, module_data_sources, …

  • Do not run raw UPDATE / INSERT against core tables. PHP can't be

sandboxed, so this is a contract (like WordPress), not a hard wall — but the data capsule and good-citizen hooks keep a well-behaved module out of core data.

Boot idempotently.

  • boot() runs once per request; the loader guards against a double-boot, but keep

your registrations safe to re-run (e.g. guard schema checks with a static flag).

Don't clash.

  • Namespace your routes and permissions. In dev / staging the loader logs a warning

when your module's permission name, or a route it registers, collides with the core or another module (it overrides silently otherwise).

Reference

  • Contract & manifest classes: app/Libraries/Modules/

(ModuleInterface, AbstractModule, ModuleManifest, ManifestValidator, VersionConstraint, ManifestException).

  • A working reference module ships in step 7.6 under modules/IronCms/Hello/.
↑ Başa dön