fabianmarz / lunar-content-pages
Content pages add-on for the Lunar 2 admin panel: block-based, translatable, nested pages with menus and a publish workflow.
Requires
- php: ^8.3
- lunarphp/core: ^2.0.0-beta.2
- lunarphp/panel: ^2.0.0-beta.2
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Block-based content pages for the Lunar 2 admin panel: translatable, nestable pages with publish workflow, navigation menus and a schema-driven block editor. A PHP declaration produces the insert-menu entry, the rendered inputs, the defaults and the validation rules, so most new block types need zero JavaScript.
The package covers the admin side only. Rendering pages on a storefront is up
to your application (Page::blocksFor() and Rendering\PageRenderer give you
the data) — see docs/consuming-the-api.md for the
read API: finding pages by localized path, render data shapes, menu trees and
exposing them as JSON. Media library and forms are separate add-ons; this
package works without them.
Compatibility: Lunar 2.0.0-beta.2 (lunarphp/core and lunarphp/panel
^2.0.0-beta.2), PHP 8.3+.
Screenshots
| Pages index | Schema-driven block editor | Insert menu |
|---|---|---|
![]() |
![]() |
![]() |
Installation
This is an add-on for the Lunar 2 admin panel, not a standalone app. It is published on Packagist:
composer require fabianmarz/lunar-content-pages php artisan migrate # pages, menus and navigation items php artisan lunar:panel:link # symlinks the compiled bundle into public/vendor/lunar-panel/content-pages
Lunar 2 itself is still beta, so your root composer.json needs
"minimum-stability": "beta" (or you must opt the lunar packages in
individually with @beta flags) for the dependencies to resolve.
ContentPagesServiceProvider is auto-discovered. It registers the panel
section, routes under /panel/content, translations (content-pages::pages.*)
and migrations. Pages and Menus appear under Content in the panel
navigation, gated by the content:manage-pages permission (seeded for the staff
guard by the migration). The frontend bundle ships prebuilt, so consumers need
no npm step.
Integration points
- Storefront URLs (optional). Bind
LunarContentPages\Contracts\StorefrontUrlResolverto turn page paths and catalog models into public URLs. Without a binding, pages expose no storefront link and menu items that point at pages or catalog records resolve to no URL (custom link items still work). - Custom blocks. Register from any service provider's
boot():BlockRegistry::register('partner', PartnerBlock::class). Built in: rich text, hero, image, call to action, gallery. Every block is optional and editor-ordered; the package imposes no fixed page structure. - Media (optional). Image fields use Lunar core's media handling. When the media library add-on is installed, its picker is offered in the editor.
- Forms (optional). The forms add-on registers its own block type on the registry. This package has no dependency on it.
- Disable switch.
CONTENT_PAGES_ENABLED=falsehides the editing UI (panel navigation, routes, editor bundle) without touching the data layer — models, rendering and storefront consumers keep working, so nothing is unpublished.
Adding a block (pure PHP)
A block is a plain PHP class in your application or add-on — you never edit
this package. Put it anywhere composer autoloads; in a Laravel app
app/ContentPages/Blocks/ is a good home:
namespace App\ContentPages\Blocks; use LunarContentPages\Blocks\Block; use LunarContentPages\Fields\Select; use LunarContentPages\Fields\Text; use LunarContentPages\Fields\Textarea; class QuoteBlock extends Block { public function label(): string { return 'Quote'; } public function icon(): string { return 'fileText'; } public function fields(): array { return [ Textarea::make('text', 'Quote') ->required() ->cols(2), Text::make('cite', 'Citation') ->cols(1) ->rules(['max:120']), Select::make('variant', 'Style') ->required() ->cols(1) ->options([ ['label' => 'Default', 'value' => 'default'], ['label' => 'Highlight', 'value' => 'highlight'], ]), ]; } }
Register it in any service provider's boot() — AppServiceProvider is fine:
use LunarContentPages\Blocks\BlockRegistry; public function boot(): void { BlockRegistry::register('quote', \App\ContentPages\Blocks\QuoteBlock::class); }
That is the whole job: the type appears in the insert menu, renders inputs,
seeds defaults and validates — no Vue changes. Registration is just a
class-string lookup, so the block class can live in the host app or in any
add-on package you control. (Inside this repository, src/Blocks/ is where
the built-in types live — treat those as examples, not the place for yours.)
icon must be one of the names in the panel Icon.vue's ICONS map (closed
set — fileText, image, link, type, flag, palette, …); unknown
names render nothing.
Field builder API
Field::make(key, label) starts every field; each method returns the field
for chaining:
| Method | Effect |
|---|---|
required() |
required vs nullable in derived rules; asterisk in the UI |
cols(int) |
Columns in the 2-column grid: 1 = half width, 2 = full (default) |
rules([]) |
Extra Laravel rules merged after the type's base |
default($v) |
Initial value for new blocks (falls back to the type's implicit default) |
config([]) |
Type-specific config shipped to the renderer |
options([]) |
Select only — options list, also feeds Rule::in |
fields([]) |
Repeater only — the sub-field schema every row repeats |
min(int) / max(int) |
Repeater only — row count bounds, also feed min:/max: rules |
Built-in field types
| Type | PHP class | Renders | Base rule | Notes |
|---|---|---|---|---|
text |
Fields\Text |
TextInput | string |
|
url |
Fields\Url |
TextInput (type=url) |
string |
|
number |
Fields\Number |
TextInput (type=number) |
numeric |
empty → null, else coerced to Number |
textarea |
Fields\Textarea |
Textarea | string |
|
select |
Fields\Select |
Select | Rule::in(options) |
options via ->options() |
toggle |
Fields\Toggle |
Toggle | boolean |
|
richtext |
Fields\RichText |
TipTap editor | string |
stores HTML |
media |
Fields\Media |
Media picker | integer, exists:media,id |
stores a media row id, renders as a resolved file array |
repeater |
Fields\Repeater |
Repeater | array (+min:/max:) |
ordered rows of sub-fields, nests |
Validation is derived as [required|nullable, <base>, ...custom rules] — the
cta type's ['required', 'string', 'max:255'] is a derived example.
Custom block editor (escape hatch)
When a block needs behavior a schema can't express (the built-in image block
needs a media picker), override editor() and keep verbatim
rules()/defaults():
class ImageBlock extends Block { public function label(): string { return 'Image'; } public function icon(): string { return 'image'; } public function editor(): ?string { return 'image'; } // component name, resolved in JS public function rules(): array { /* ... */ } public function defaults(): array { /* ... */ } }
The named component is resolved lazily at render time in two places: this
package's internal editors, then window.LunarContentPagesEditors. Consumers
register theirs from their own panel bundle — never by editing this
package:
// your add-on's resources/js/addon.js (or plain JS in the host app) import MyEditor from './components/MyEditor.vue'; window.LunarContentPagesEditors = window.LunarContentPagesEditors || {}; window.LunarContentPagesEditors.myeditor = MyEditor;
Because lookups happen when a block renders — not when bundles execute — the
script order of sibling add-ons doesn't matter. Ship the bundle the same way
this package does: compile it with @lunarphp/panel-vite-plugin (IIFE sharing
the panel's Vue instance) and register it in your service provider:
$this->app->make(PanelManager::class)->vite('my-addon', [ 'input' => 'resources/js/addon.js', 'hotFile' => null, 'buildDirectory' => 'vendor/lunar-panel/my-addon', ]);
Editor contract — see components/blocks/ImageBlock.vue for a full example:
defineProps<{ data: Record<string, unknown>; // block.data — write through v-model:data errors?: Record<string, string>; // { fieldKey: message }, already scoped to this block media: Record<number, MediaRef>; // resolved media for picker editors mediaUploadUrl?: string; mediaPickerUrl?: string | null; mediaLibraryUploadUrl?: string | null; }>(); defineEmits<{ 'update:data': [value: ...] }>();
Update via emit('update:data', {...props.data, alt: value}) — BlockEditor
binds v-model:data.
Adding a field type
A field type is two halves: a PHP Field subclass living in your app or
add-on (same as blocks — anywhere composer autoloads) that owns type(), base
rules and default; and a Vue renderer shipped in your own panel bundle (see
"Custom block editor" above for how add-ons compile and register bundles).
- Create the PHP side:
use LunarContentPages\Fields\Field; class Color extends Field { public function type(): string { return 'color'; } // baseRules() → ['string'] unless the type needs a different default. }
- Create a Vue component implementing the uniform contract:
<script setup lang="ts"> // the shape of a schema entry — copy this or re-declare it in your bundle: interface BlockField { key: string; type: string; label?: string; config?: Record<string, unknown>; } defineProps<{ field: BlockField; // the schema entry: key, type, label, config… modelValue?: unknown; // current data[field.key] invalid?: boolean; // a validation error exists for this key }>(); const emit = defineEmits<{ 'update:modelValue': [value: string] }>(); </script> <template> <!-- normalize your input's props/events onto the contract --> </template>
- Register the renderer from your own panel bundle, same mechanism as custom block editors — lazy lookup, so bundle order doesn't matter:
import ColorField from './components/ColorField.vue'; window.LunarContentPagesFieldTypes = window.LunarContentPagesFieldTypes || {}; window.LunarContentPagesFieldTypes.color = ColorField;
- Use it in any block:
Color::make('accent', 'Accent color').
(Inside this package the same lookups fall back to the internal fieldTypes
registry first — contributing a type to the package itself means registering
there instead of on the window object. fieldString() in
components/fields/types.ts is the shared unknown → string coercion for
text-like inputs.)
Storefront links on catalog pages
Product, brand and collection edit pages get a View page header button that
opens the record's default-language storefront URL. It appears only when the
host's StorefrontUrlResolver binding produces a URL for the record — so
which types are linkable, and which states have no public page, is entirely
host policy expressed through modelUrl() returning null (see
docs/consuming-the-api.md).
Further reading
- docs/consuming-the-api.md — the read API: finding pages by localized path, render data shapes, menu trees, JSON exposure.
- docs/developing.md — working on this package itself: dev setup, architecture, pages-index and slug internals, panel quirks.


