johnnyxlemonade / admin-cms-content-types
Content type definitions for Lemonade CMS administration.
Package info
github.com/johnnyxlemonade/admin-cms-content-types
pkg:composer/johnnyxlemonade/admin-cms-content-types
Requires
- php: >=8.3
- johnnyxlemonade/admin-platform: ^1.0
- johnnyxlemonade/cms-core: ^1.0
- johnnyxlemonade/framework: ^1.0
- psr/http-message: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.3
- phpstan/phpstan-strict-rules: ^2.1
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Define custom content types in Lemonade Admin and manage their records through the standard editor and DataGrid. The host renders published content.
Features
- Visual layout with localized fields, validation and defaults.
- Text, rich text, numbers, dates, booleans, selects, media, relations and repeaters.
- Drafts, publication, SEO, ownership and audit history.
- Optional thumbnail, gallery, attachments, localized tags and canonical URLs.
Requirements
- PHP 8.3 or newer, tested on PHP 8.3–8.6.
- Lemonade Framework, Admin Platform and CMS Core
^1.0.
Installation
composer require johnnyxlemonade/admin-cms-content-types:^1.0
Composer discovers the module automatically. Run the host's migrations,
permission sync and Admin asset publication, then grant the module permissions
to the appropriate roles. For the Builder, grant cms.content-types.view and
cms.content-types.manage_definitions. Each type has separate record permissions.
Usage
Open <admin-base>/cms/content-types to define a type. Enabled types appear in
the Content menu. Enable media and tags per type. Turning off a capability
or archiving a field keeps its data. Localized URL prefixes apply to new paths.
Published records
Inject PublishedRecordReadModel and use
the PublicLocaleResolution from CMS routing. The type and field codes in these
examples come from the Builder.
$page = $records->collection( typeCode: 'publication', locale: $locale, filters: ['publisher' => 'Archive'], perPage: 12, sortBy: 'year', ); foreach ($page->getItems() as $record) { $title = $record->getTitle(); $year = $record->getField('year')->getValue(); $url = $record->getPublicUrl(); } $pagination = $page->getPagination('/publikace', query: ['publisher' => 'Archive']);
record() returns a visible record or null. A record can be public without a
canonical URL. Use related(), referencing() and references() for related
records and lightweight references. Use languageAlternatives() for published
translations with canonical URLs and sitemapEntries() for URLs and update times.
Use the optional recordIds filter on collection() to restrict the SQL count
and page to a set of eligible records. selectIds() accepts the same filter.
An empty list yields no records.
Lightweight listings
Use summaries() for text listings or search results. It reads the requested
scalar or repeater values without loading media or tags.
$matches = $records->summaries( 'publication', $locale, fields: ['perex'], search: $term, searchFields: ['perex', 'annotation'], searchRelations: ['workplace'], limit: 250, );
Pass a PublishedRecordProjection to items(), collection() or others()
to load selected fields and optionally the thumbnail. Field codes are validated
before the query, even for an empty result. Read only selected fields from a
projection. Use record() for the complete detail, including gallery,
attachments and tags. Complete records are reused within the request for the
same record, content language and default language.
$items = $records->items( typeCode: 'article', locale: $locale, projection: new PublishedRecordProjection(['summary'], thumbnail: true), limit: 3, );
Definition cache
Admin and public reads share a lazy definition snapshot within a request. With the file cache, installations use shared writable storage for the catalog and its lock. A cache hit checks definition IDs and revisions in one database query. Builder changes invalidate the catalog after commit. If invalidation fails, the application logs the error and the revision check rejects the old catalog on the next read. Write definitions through the Builder lifecycle so the revision changes in the same transaction as the definition.
Development
composer install composer qa