johnnyxlemonade / admin-cms-page
Hierarchical localized CMS pages for Lemonade Admin.
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
Manage hierarchical, localized pages in Lemonade Admin. Pages share a tree and template key across locales. Each translation has its own content, SEO and publication state.
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-page:^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. Open <admin-base>/cms/pages to manage pages.
Page templates
The package supplies the default template. To add a template, tag a
PageTemplateDefinition service in a host provider.
use Lemonade\Cms\Page\Template\PageTemplateDefinition; use Lemonade\Framework\Container\ContainerBuilderInterface; use Lemonade\Framework\Core\ServiceProviderInterface; /** * Registruje vlastni sablony stranek host aplikace */ final readonly class PageTemplatesServiceProvider implements ServiceProviderInterface { /** * Prida sablonu uvodni stranky do nabidky balicku */ public function register(ContainerBuilderInterface $container): void { $container->singletonTagged( 'app.page.template.landing', new PageTemplateDefinition('landing', 'page_template.landing'), PageTemplateDefinition::class, ); } }
Register the provider and supply the label translation and public renderer.
For an existing custom registry, replace the host binding of
PageTemplateProviderInterface with tagged definitions. Duplicate keys are
rejected, and removed templates keep their stored keys.
Public pages
Inject PublishedPageReadModel. Public reads require an enabled locale, a published translation, a canonical route and a parent chain that reaches a non-deleted root. Each page follows its own publication schedule.
use Lemonade\Cms\Page\Public\PublishedPageReadModel; use Lemonade\Cms\Routing\Cms\CmsRoute; use Lemonade\Cms\Routing\Locale\PublicLocaleResolution; function pageData( PublishedPageReadModel $pages, CmsRoute $route, PublicLocaleResolution $locale, ): ?array { $page = $pages->record($route->getEntityId(), $locale); if ($page === null) { return null; } return [ 'page' => $page, 'parent' => $pages->parent($page, $locale), 'children' => $pages->children($page->getId(), $locale), 'ancestors' => $pages->ancestors($page, $locale), 'languageAlternatives' => $pages->languageAlternatives($page->getId(), $locale), 'thumbnail' => $page->getThumbnail(), 'gallery' => $page->getGallery(), 'attachments' => $page->getAttachments(), 'matchingPages' => $pages->search($locale, 'archive', limit: 20), ]; }
Use children(null, $locale) for root pages. For search results without media,
searchSummaries() provides the description and any additional body text needed
for ranking. Use links() for canonical links across locales by page ID or
template key, or languageAlternativeUrls() for the locale-to-URL map of a
single page. isPublicInAnyLocale() checks the same publication and hierarchy
conditions in an existence query, for example when checking a file's page owner.
Sitemap
Register the provider under config.sitemap.providers in the host's
Discovery.yaml. Select the templates the host can render.
use Lemonade\Admin\Localization\LanguageRegistry; use Lemonade\Cms\Page\Public\PublishedPageReadModel; use Lemonade\Cms\Routing\Locale\PublicLocaleResolution; use Lemonade\Framework\Discovery\Sitemap\SitemapProviderInterface; use Lemonade\Framework\Discovery\Sitemap\SitemapUrl; /** * Supplies host-rendered CMS pages to the framework sitemap */ final readonly class PublicPageSitemapProvider implements SitemapProviderInterface { /** * Receives the public page reader and configured languages */ public function __construct( private PublishedPageReadModel $pages, private LanguageRegistry $languages, ) {} /** * Yields sitemap URLs for templates rendered by this host * * @return iterable<SitemapUrl> */ public function urls(): iterable { $defaultLocale = $this->languages->publicLocaleSnapshot()->getDefaultLocale(); foreach ($this->languages->enabledLocales() as $language) { $locale = PublicLocaleResolution::route($defaultLocale, $language['code'], ''); foreach ($this->pages->sitemapEntries($locale) as $entry) { if (!in_array($entry->getTemplateKey(), ['default', 'article'], true)) { continue; } yield SitemapUrl::create($entry->getPublicUrl(), $entry->getUpdatedAt()); } } } }
Development
composer install composer qa