Search by

johnnyxlemonade / admin-cms-page

johnnyxlemonade

Hierarchical localized CMS pages for Lemonade Admin.

Package info

github.com/johnnyxlemonade/admin-cms-page

pkg:composer/johnnyxlemonade/admin-cms-page

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-12-03 13:52 UTC

This package is auto-updated.

Last update: 2026-12-03 13:54:17 UTC


README

Tests PHP 8.3–8.6 PHPStan License

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

License

Apache License 2.0