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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ afterEach(async () => {
});

describe('core-data-shim entity registry', () => {
it('registers the five V1 entities by default', () => {
it('registers the V1 site-editor + G3 cms-framework entities by default', () => {
const names = DEFAULT_ENTITIES.map((entity) => `${entity.kind}|${entity.name}`);

expect(names).toEqual([
Expand All @@ -98,6 +98,12 @@ describe('core-data-shim entity registry', () => {
'postType|wp_navigation',
'postType|wp_block',
'root|globalStyles',
// G3 cms-framework Post + Page (plan 12 §4.4) — declared
// unconditionally; the matching `/visual-editor/api/{posts,
// pages}/{id}` endpoints come from the resource map and
// resolve to null when cms-framework isn't installed.
'postType|post',
'postType|page',
]);
});

Expand All @@ -111,10 +117,39 @@ describe('core-data-shim entity registry', () => {
'postType|wp_navigation',
'postType|wp_block',
'root|globalStyles',
'postType|post',
'postType|page',
]),
);
});

it('the G3 post + page entities resolve to /posts and /pages baseURLs', () => {
const post = DEFAULT_ENTITIES.find(
(entity) => entity.kind === 'postType' && entity.name === 'post',
);
const page = DEFAULT_ENTITIES.find(
(entity) => entity.kind === 'postType' && entity.name === 'page',
);

expect(post).toMatchObject({
kind: 'postType',
name: 'post',
baseURL: '/posts',
key: 'id',
label: 'Post',
plural: 'posts',
});

expect(page).toMatchObject({
kind: 'postType',
name: 'page',
baseURL: '/pages',
key: 'id',
label: 'Page',
plural: 'pages',
});
});

it('addEntities registers custom entities alongside defaults', () => {
coreDispatch().addEntities([
{
Expand Down
22 changes: 22 additions & 0 deletions resources/js/visual-editor/vendor/core-data-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,28 @@ export const DEFAULT_ENTITIES: readonly EntityConfig[] = Object.freeze([
label: 'Global Styles',
plural: 'globalStyles',
},
// G3 cms-framework entities — see plan 12 §4.4. Always declared so
// `core/post-*` blocks can resolve via `useEntityRecord('postType',
// 'post', id)` regardless of whether cms-framework is installed.
// When the package is absent the matching `/visual-editor/api/{posts,
// pages}/{id}` endpoints are unrouted and the resolver returns `null`
// — no different from any other entity that hasn't been seeded yet.
{
kind: 'postType',
name: 'post',
baseURL: '/posts',
key: 'id',
label: 'Post',
plural: 'posts',
},
{
kind: 'postType',
name: 'page',
baseURL: '/pages',
key: 'id',
label: 'Page',
plural: 'pages',
},
]);

// ---------------------------------------------------------------------------
Expand Down