Skip to content

useCmsState() ​

WARNING

Single File Component (SFC) support for Administration extensions is experimental. It is available since Shopware 6.7.16.0. The APIs described on this page can still change without a deprecation. Try it out and tell us what you find, but do not ship an extension built on it to customers or to the Shopware Store until the API is declared stable (planned for 6.9).

ts
import { useCmsState } from 'shopware:composables';

function useCmsState(): {
    cmsPageState: ComputedRef<CmsPageStore>;
    selectedBlock: WritableComputedRef<Entity<'cms_block'> | null>;
    selectedSection: WritableComputedRef<Entity<'cms_section'> | null>;
    currentDeviceView: ComputedRef<string>;
    isSystemDefaultLanguage: ComputedRef<boolean>;
    category: ComputedRef<ContentEntity<'category'> | null>;
    product: ComputedRef<ContentEntity<'product'> | null>;
    landingPage: ComputedRef<ContentEntity<'landing_page'> | null>;
    contentEntity: ComputedRef<ContentEntity | null>;
    inheritedSlotConfig: ComputedRef<SlotConfigMap | null>;
    getSlotConfigForLanguage: (languageId?: string | null) => SlotConfigMap | null;
};

The CMS editor state a block, section or config panel works against: what is selected, which device view is being previewed, and which entity the layout is being edited on.

selectedBlock and selectedSection are writable - assigning one selects it, the same way the store action does:

ts
const { selectedBlock, currentDeviceView } = useCmsState();

function select(): void {
    selectedBlock.value = props.block;
}

contentEntity resolves to the category, product or landing page the layout belongs to, decided by the current route. The three are also available individually, and each reads null rather than throwing when its detail module is not loaded.

inheritedSlotConfig is the slot config of the parent language merged field by field with the current one, which is what makes a partly translated layout inherit the rest instead of shadowing it.

Replaces the cms-state mixin.

Was this page helpful?
UnsatisfiedSatisfied
Be the first to vote!
0.0 / 5  (0 votes)