8000 feat: sections shown as tabs by Klehm · Pull Request #103 · Klehm/content-blocks-project · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CLAUDE.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ content_blocks:
sidebar_left: { label: 'Barre latérale + contenu', columns: [4, 8] }
# Same columns, shown one at a time; the editor names each tab.
tabs: { label: 'Onglets', columns: [4, 4, 4], display: tabs }
# Looks of sections shown as tabs, besides underline / pills / cards.
# `steps` draws its tab with a host template, reading a host field
# (App\ContentBlocks\Form\TabBadgeExtension).
tab_styles:
steps:
label: 'Étapes numérotées'
css_class: 'demo-steps'
fields: []
template: 'content_blocks/tab_steps.html.twig'

# Groups of the add-block picker. Listed ones come first: Text keeps its
# label, then a host group taking two kit blocks out of their own groups.
Expand Down
58 changes: 58 additions & 0 deletions apps/content-blocks-sandbox/migrations/Version20261203120000.php
8 10BC8
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Section tab titles and subtitles in other languages: the side table
* `klehm/content-blocks-i18n` keeps a section's translated settings in.
*
* Copy this into your own project when you upgrade the i18n package. Same two
* invariants as the column table: `ON DELETE CASCADE` on `section_id`, and one
* row per section per language through the unique index.
*
* @see docs/internals/i18n.md#section-tabs-are-translated-beside-the-section
*/
final class Version20261203120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add cb_section_translation for klehm/content-blocks-i18n.';
}

public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
CREATE TABLE cb_section_translation (
id INT AUTO_INCREMENT NOT NULL,
section_id INT NOT NULL,
locale VARCHAR(16) NOT NULL,
draft_values JSON DEFAULT NULL,
draft_digests JSON DEFAULT NULL,
published_values JSON DEFAULT NULL,
published_digests JSON DEFAULT NULL,
updated_at DATETIME NOT NULL,
INDEX IDX_855C4C9DD823E37A (section_id),
INDEX cb_section_translation_locale (locale),
UNIQUE INDEX cb_section_translation_unique (section_id, locale),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
SQL);

$this->addSql(<<<'SQL'
ALTER TABLE cb_section_translation
ADD CONSTRAINT FK_855C4C9DD823E37A
FOREIGN KEY (section_id) REFERENCES cb_section (id)
ON DELETE CASCADE
SQL);
}

public function down(Schema $schema): void
{
$this->addSql('DROP TABLE cb_section_translation');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\ContentBlocks\Form;

use ContentBlocks\Form\Type\SectionSettingsType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

/**
* Reference example: a host's own tab field, in the core's Tab panel, shown
* only for the `steps` style that draws it (config/packages/content_blocks.yaml).
*
* Its value lands in the section's settings; the style's template reads it
* as `tab.settings.tabBadge`.
*/
final class TabBadgeExtension extends AbstractTypeExtension
{
public static function getExtendedTypes(): iterable
{
return [SectionSettingsType::class];
}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('tabBadge', TextType::class, [
'label' => 'app.tab_badge',
'translation_domain' => 'messages',
'required' => false,
'attr' => ['maxlength' => 20, 'placeholder' => 'app.tab_badge_placeholder'],
'cb_panel' => SectionSettingsType::PANEL_TAB,
'row_attr' => ['data-cb-condition' => SectionSettingsType::tabStyleCondition(['steps'])],
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{# The `steps` tab style (config/packages/content_blocks.yaml): a numbered
step, its title and the host's own badge field. #}
<span class="demo-step__number" aria-hidden="true">{{ n }}</span>
<span class="cb-section-tabs__text">
<span class="cb-section-tabs__title">{{ tab.title ?? ('Étape ' ~ n) }}</span>
{%- if tab.settings.tabBadge ?? null %}<span class="demo-step__badge">{{ tab.settings.tabBadge }}</span>{% endif -%}
</span>
20 changes: 20 additions & 0 deletions apps/content-blocks-sandbox/templates/page/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
color: #1f2330;
}
/* The host's `steps` tab style. */
.demo-steps .cb-section-tabs__tab,
.demo-steps .cb-section-tabs__header { gap: 0.6rem; }
.demo-step__number {
display: inline-grid;
place-items: center;
width: 1.75rem;
height: 1.75rem;
border-radius: 50%;
background: #e5e7eb;
font-weight: 700;
}
.demo-step__badge {
align-self: flex-start;
margin-top: 0.2rem;
padding: 0 0.5rem;
border-radius: 999px;
background: #fde68a;
font-size: 0.75rem;
}
article {
max-width: 1100px;
margin: 0 auto;
Expand Down
8 changes: 8 additions & 0 deletions apps/content-blocks-sandbox/translations/messages.en.xlf
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
<source>app.builder.translate_title</source>
<target>Open the translation workbench in a new tab</target>
</trans-unit>
<trans-unit id="tab_badge">
<source>app.tab_badge</source>
<target>Badge</target>
</trans-unit>
<trans-unit id="tab_badge_placeholder">
<source>app.tab_badge_placeholder</source>
<target>e.g. New</target>
</trans-unit>
<trans-unit id="ornament.panel">
<source>app.ornament.panel</source>
<target>Ornaments</target>
Expand Down
8 changes: 8 additions & 0 deletions apps/content-blocks-sandbox/translations/messages.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
<source>app.builder.translate_title</source>
<target>Ouvrir l'atelier de traduction dans un nouvel onglet</target>
</trans-unit>
<trans-unit id="tab_badge">
<source>app.tab_badge</source>
<target>Badge</target>
</trans-unit>
<trans-unit id="tab_badge_placeholder">
<source>app.tab_badge_placeholder</source>
<target>ex. Nouveau</target>
</trans-unit>
<trans-unit id="ornament.panel">
<source>app.ornament.panel</source>
<target>Ornements</target>
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default defineConfig({
{ text: 'Headless rendering (JSON)', link: '/guide/headless' },
{ text: 'Styling', link: '/guide/styling' },
{ text: 'Laying out sidebar fields', link: '/guide/sidebar-fields' },
{ text: 'Sections as tabs', link: '/guide/section-tabs' },
{ text: 'Simplifying the builder', link: '/guide/builder-structure' },
{ text: 'Security', link: '/guide/security' },
{ text: 'Mounting the routes', link: '/guide/routing' },
Expand Down
16 changes: 9 additions & 7 deletions docs/guide/backward-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ ContentBlocks follows [semantic versioning](https://semver.org/). From `1.0.0`,

These are the extension surface: implement them, alias them, decorate them. Their method signatures are frozen, and so is the meaning of what they return.

**Core** (`klehm/content-blocks`), 48 interfaces:
**Core** (`klehm/content-blocks`), 51 interfaces:

| Area | Interfaces |
|---|---|
| Access, preview, pickers | `AccessCheckerInterface`, `ContentAreaUrlResolverInterface`, `ContentAreaProviderInterface`, `SectionTemplateManagerInterface`, `AssetReportViewerInterface` |
| Blocks | `BlockTypeInterface`, `BlockPreviewHintInterface`, `BlockPurposeInterface`, `BlockAssetsInterface`, `PreviewDependentInterface`, `BlockDataDefaultsProviderInterface`, `BlockDecoratorInterface`, `BlockFormExtensionInterface`, `TranslatableFieldsInterface` |
| Sections and columns | `SectionDecoratorInterface`, `SectionSettingsDefaultsProviderInterface`, `SectionStyleProviderInterface`, `SectionClonerInterface`, `BlockCloneObserverInterface`, `ColumnCloneObserverInterface` |
| Rendering | `BlockRendererInterface`, `BlockDataResolverInterface`, `AreaBlocksInterface`, `EntrypointResolverInterface`, `ColumnSettingsResolverInterface`, `ImageUrlResolverInterface`, `ContentAreaNormalizerInterface`, `BlockJsonNormalizerInterface` |
| Sections and columns | `SectionDecoratorInterface`, `SectionSettingsDefaultsProviderInterface`, `SectionStyleProviderInterface`, `SectionClonerInterface`, `BlockCloneObserverInterface`, `ColumnCloneObserverInterface`, `SectionCloneObserverInterface`, `TabStyleProviderInterface` |
| Rendering | `BlockRendererInterface`, `BlockDataResolverInterface`, `AreaBlocksInterface`, `EntrypointResolverInterface`, `ColumnSettingsResolverInterface`, `SectionSettingsResolverInterface`, `ImageUrlResolverInterface`, `ContentAreaNormalizerInterface`, `BlockJsonNormalizerInterface` |
| Content and publishing | `ContentManipulatorInterface`, `ContentAreaPublisherInterface`, `UnpublishedChangesProviderInterface`, `LocaleDraftsProviderInterface` |
| Builder UI | `BuilderActionProviderInterface`, `BuilderShellExtensionInterface`, `BuilderStructureResolverInterface`, `UiIconProviderInterface`, `ColorPaletteProviderInterface` |
| Storage and assets | `FileStorageInterface`, `AssetInventoryInterface`, `AssetResolverInterface`, `AssetReferenceProviderInterface`, `MediaLibraryInterface` |
Expand All @@ -39,13 +39,13 @@ These are the extension surface: implement them, alias them, decorate them. Thei
- **Form types**:
- `ContentAreaType` and its options (`enable_replace`, `enable_import_export`, `enable_import`, `enable_export`, `enable_public_link`, `topbar_actions`).
- `PaletteColorType`, `ImageUploadType`, `VideoUploadType`, as fields for your own blocks, with `ImageUploadType`'s `accept` and `cb_alt_field` options.
- `BlockFormType`, `SectionSettingsType` and `StylingType` as **targets of a form type extension**, with their `TAB_*` and `PANEL_*` constants. The fields they hold are not frozen: a field may move, but a key you add keeps working.
- `BlockFormType`, `SectionSettingsType` and `StylingType` as **targets of a form type extension**, with their `TAB_*` and `PANEL_*` constants, and `SectionSettingsType::tabStyleCondition()`. The fields they hold are not frozen: a field may move, but a key you add keeps working.
- **The sidebar form options.** `cb_ai` (and the `data-cb-ai="off"` attribute) on every form type, `cb_group`, `cb_panel`, `cb_help_tooltip` and `cb_panels_exclusive` on every form type; `cb_icons`, `cb_icon_layout`, `cb_icon_columns` and `cb_icon_labels` on `ChoiceType`; `cb_open_entries` on `LiveCollectionType`. Also the **names of the shipped UI icons** they refer to ([Laying out sidebar fields](./sidebar-fields.md)): a name may gain a better drawing, but it is not renamed or removed.
- **Value objects your implementation builds or reads.** Their public properties and named constructors are frozen:
- rendering: `RenderContext` (with `isPreview()` / `isPublic()`), `RenderMode`, `BlockView`, `ResolvedImage`, `BlockPreviewHint`, `BlockAssets`, `BlockDecoration`, `SectionDecoration`
- publishing: `PublishContext`, `LocaleDraft`
- AI: `TextRequest`, `AltTextRequest`, `ContentRequest`, `GenerationResult`, and the `AiAction` constants
- builder UI and styling: `BuilderAction`, `BuilderShellFragment`, `BuilderStructure` (its `SECTIONS_*` constants and `can*()` / `showsSections()` reads), `PaletteColor`, `SectionStyle`
- builder UI and styling: `BuilderAction`, `BuilderShellFragment`, `BuilderStructure` (its `SECTIONS_*` constants and `can*()` / `showsSections()` reads), `PaletteColor`, `SectionStyle`, `TabStyle` (with its `FIELD_*` constants)
- storage: `StoredAsset`
- translation: the kit's `RichTextEditorView`; i18n's `TranslationRequest`, `TranslationOutcome`, `TranslationJob` and `FieldStatus`
- **Values you read but do not build.** `ImportResult`, `InstantiationResult`, `SectionTemplateSnapshot`, and the transfer helpers `AssetTokenizer` and `AssetRewriter` handed to a `ContentAreaTransferExtensionInterface`. Their public reads are frozen; their constructors are `@internal`, so the package can add fields to them.
Expand All @@ -54,7 +54,7 @@ These are the extension surface: implement them, alias them, decorate them. Thei
- **Exceptions you throw or catch.** `ContentBlocksAccessDeniedException` (a 403), `GenerationRefusedException` and its `reason` codes, `IncompatibleContentVersionException`, `ImportRefusedException`, `UnsupportedTemplateFormatException`, `IncompatibleTemplateException`, `ContentManipulationException` and its `reason` codes.
- **`FormSchemaMapper::is()`**, which a `FieldSchemaContributorInterface` calls to recognise its field type.
- **`ContentBlocks\Testing\CrossRequestStateScanner`**, for pointing the [worker-mode](./worker-mode.md) check at your own code.
- **The entities** and their public accessors: `ContentArea`, `Section`, `Column`, `Block`, `SectionTemplate`, and i18n's `BlockTranslation` and `ColumnTranslation`. The exception is the setters of **published state**, which carry `@internal`. `publish()` is the only writer of a published field, so code building content writes the draft and calls `publish()`.
- **The entities** and their public accessors: `ContentArea`, `Section`, `Column`, `Block`, `SectionTemplate`, and i18n's `BlockTranslation`, `ColumnTranslation` and `SectionTranslation`. The exception is the setters of **published state**, which carry `@internal`. `publish()` is the only writer of a published field, so code building content writes the draft and calls `publish()`.

### Configuration

Expand Down Expand Up @@ -101,6 +101,7 @@ For `content-blocks:assets:gc`, the *shape* of the safety design is part of the
- builder shell: `cb_shell_topbar_left_end`, `cb_shell_topbar_right_start`, `cb_shell_topbar_right_end`, `cb_shell_end`
- workbench: `cb_wb_head`, `cb_wb_topbar_left_end`, `cb_wb_topbar_right_start`, `cb_wb_topbar_right_end`, `cb_wb_end`
- **A block view's variables.** A view receives `data`, `block_id`, `block` (`BlockView`: `id`, `type`) and `context` (`RenderContext`, its mode always set); later versions may pass more, never less.
- **A tab template's variables** ([Sections as tabs](./section-tabs.md#the-tab-template)): `tab` (`title`, `subtitle`, `icon`, `settings`), `section`, `n` and `style`; later versions may pass more, never less.

### Front-end

Expand Down Expand Up @@ -131,11 +132,12 @@ The other `cb:*` events are internal choreography between the preview overlay, t

### Storage

- **The eight table names and their columns**: `cb_content_area`, `cb_section`, `cb_column`, `cb_block`, `cb_section_template`, `cb_action_log`, and i18n's `cb_block_translation` and `cb_column_translation`. Hosts write migrations against these.
- **The nine table names and their columns**: `cb_content_area`, `cb_section`, `cb_column`, `cb_block`, `cb_section_template`, `cb_action_log`, and i18n's `cb_block_translation`, `cb_column_translation` and `cb_section_translation`. Hosts write migrations against these.
- **Conventions in stored data**, which are contracts even though they are not code:
- the `cb_translatable` field tag
- the `_id` key on collection entries
- the reserved `_` prefix in `Block.data`
- the section settings of a [tab](./section-tabs.md): `tab`, `tabTitle`, `tabSubtitle`, `tabIcon`, `tabStyle`, `tabNewGroup`
- the names of the kit's icon set, since a stored `icon` block holds the name

### Behaviour
Expand Down
6 changes: 5 additions & 1 deletion docs/guide/headless.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ With `klehm/content-blocks-i18n` installed, the locale works exactly as on the H
"accordion": { "single": false, "collapsed": false },
"slider": null,
"order": { "tablet": null, "mobile": null },
"tab": null,
"tabGroup": null,
"settings": { "styleName": "boxed", "styling": { "backgroundColor": "#f5f5f5" } },
"columns": [
{
Expand Down Expand Up @@ -103,7 +105,9 @@ With `klehm/content-blocks-i18n` installed, the locale works exactly as on the H
| `locale` | The locale the tree was rendered in: the one you passed, else the request's. |
| `contentVersion` | The area's [content version](./content-versioning.md) stamp, `null` before versioning. |
| `sections[].anchor` | The section's [anchor](./host-services.md#section-anchors-and-links-to-a-tab), checked like the HTML render checks it; `null` without one. Unlike the HTML, two sections may carry the same one. |
| `sections[].display` | The display per viewport, already resolved (`grid`, `tabs`, `accordion`, `slider`): tablet and mobile inherit from above and can only get more compact. |
| `sections[].display` | The display per viewport, already resolved (`grid`, `tabs`, `accordion`, `slider`): tablet and mobile inherit from above and can only get more compact, except a [tab](./section-tabs.md) on a phone, which stacks its own tabs or accordion as a `grid`. |
| `sections[].tab` | `{title, subtitle, icon, style}` when the section is shown as a [tab](./section-tabs.md), else `null`. `icon` is the stored path; `style` is set on a group's first tab only, `null` meaning the first style offered. |
| `sections[].tabGroup` | The id of the group's first section, the same for every tab of a group, computed by the rule the HTML render groups them with; `null` for a section that is not a tab, and always `null` from `normalizeSection()`, which cannot see the sections around it. |
| `sections[].accordion` / `slider` | The options of that display, `null` when no viewport uses it. `slider.perView` is the slides shown at once per viewport, `slider.peek` whether the next slide shows at the edge. |
| `sections[].settings` | The settings the HTML render reads: the style preset merged underneath, values equal to their default left out. |
| `columns[].span` | The width on the 12-unit grid, from `preset`. `width` is the custom weight from the *Column widths* field, `null` for equal widths. |
Expand Down
Loading
0