Skip to content

feat(cms): replace homepage latest-pages category text input with a channel-scoped selector #536

@jbourdin

Description

@jbourdin

Bug / UX issue

In the homepage block editor, the category for a latestPages block is a free-form <TextInput> with placeholder "news". Editors must know the exact category name and type it manually. Typos silently produce an empty block (because HomepageRenderer::resolveLatestPages does a case-insensitive name match, and a miss returns no pages).

Current code

assets/components/BlockEditModal.tsx:185-201:

<TextInput
    label={label('categorySlug')}
    value={(editedBlock.categorySlug as string) ?? ''}
    onChange={(event) => updateBlock('categorySlug', event.currentTarget.value || null)}
    placeholder="news"
/>

src/Service/HomepageRenderer.php:185-215 resolves the category by case-insensitive English-name match — fragile if the category is renamed.

Fix

  1. Add an admin endpoint that returns categories for the current channel (use existing MenuCategoryRepository::findAllOrdered($channel)).
  2. Replace the <TextInput> with a Mantine <Select> (or <Autocomplete>) populated from that endpoint.
  3. Store the category ID (or stable slug) in the block payload instead of the display name; update HomepageRenderer::resolveLatestPages to look up by ID/slug instead of name match.
  4. Add a migration step to rewrite existing latestPages blocks to the new identifier.

Files

  • assets/components/BlockEditModal.tsx:185-201
  • src/Service/HomepageRenderer.php:185-215
  • src/Entity/MenuCategory.php (channel relation already exists, lines 42-44)
  • New admin controller endpoint (e.g. AdminHomepageController or a dedicated AdminMenuCategoryController)

Verification

  1. Open the homepage block editor; the category field shows a dropdown of channel categories.
  2. Select a category; save; reload the page editor — selection persists.
  3. Render the homepage; the block shows pages from the selected category.
  4. Renaming a category does not break the block (because we store the ID, not the name).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions