From 0f90ee424b4304ba2fe9d0eda9665cba7994b745 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 21 Oct 2021 19:53:20 +0100 Subject: [PATCH 1/4] Read rest_namespace for REST API. --- packages/core-data/src/entities.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index 85f0cf5797f16..d526f973cbe2c 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -173,9 +173,10 @@ function* loadPostTypeEntities() { const isTemplate = [ 'wp_template', 'wp_template_part' ].includes( name ); + const namespace = postType?.rest_namespace ? postType.rest_namespace : 'wp/v2'; return { kind: 'postType', - baseURL: '/wp/v2/' + postType.rest_base, + baseURL: '/' + namespace + '/' + postType.rest_base, baseURLParams: { context: 'edit' }, name, label: postType.labels.singular_name, @@ -204,9 +205,10 @@ function* loadTaxonomyEntities() { path: '/wp/v2/taxonomies?context=edit', } ); return map( taxonomies, ( taxonomy, name ) => { + const namespace = taxonomy.rest_namespace ? taxonomy.rest_namespace : 'wp/v2'; return { kind: 'taxonomy', - baseURL: '/wp/v2/' + taxonomy.rest_base, + baseURL: '/' + namespace + '/' + taxonomy.rest_base, baseURLParams: { context: 'edit' }, name, label: taxonomy.labels.singular_name, From 1e9d0776fca6514258ec7dcb1d123d4dabf35b71 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 21 Oct 2021 20:00:08 +0100 Subject: [PATCH 2/4] Apply suggestions from code review --- packages/core-data/src/entities.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index d526f973cbe2c..0d7ecaca35f74 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -205,7 +205,7 @@ function* loadTaxonomyEntities() { path: '/wp/v2/taxonomies?context=edit', } ); return map( taxonomies, ( taxonomy, name ) => { - const namespace = taxonomy.rest_namespace ? taxonomy.rest_namespace : 'wp/v2'; + const namespace = taxonomy?.rest_namespace ? taxonomy.rest_namespace : 'wp/v2'; return { kind: 'taxonomy', baseURL: '/' + namespace + '/' + taxonomy.rest_base, From af842c635ae1e803aef8de92bdf25fae95eca228 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Fri, 22 Oct 2021 18:02:02 +0100 Subject: [PATCH 3/4] Fix lint --- packages/core-data/src/entities.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index d526f973cbe2c..3edadbd189516 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -173,7 +173,9 @@ function* loadPostTypeEntities() { const isTemplate = [ 'wp_template', 'wp_template_part' ].includes( name ); - const namespace = postType?.rest_namespace ? postType.rest_namespace : 'wp/v2'; + const namespace = postType?.rest_namespace + ? postType.rest_namespace + : 'wp/v2'; return { kind: 'postType', baseURL: '/' + namespace + '/' + postType.rest_base, @@ -205,7 +207,9 @@ function* loadTaxonomyEntities() { path: '/wp/v2/taxonomies?context=edit', } ); return map( taxonomies, ( taxonomy, name ) => { - const namespace = taxonomy.rest_namespace ? taxonomy.rest_namespace : 'wp/v2'; + const namespace = taxonomy.rest_namespace + ? taxonomy.rest_namespace + : 'wp/v2'; return { kind: 'taxonomy', baseURL: '/' + namespace + '/' + taxonomy.rest_base, From 2cf72680d743d4f13ebae35bbb7c93321c9a13c8 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 28 Oct 2021 20:40:15 +0100 Subject: [PATCH 4/4] Pascals feedback --- packages/core-data/src/entities.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index 261b40ae2b3a5..7e3f7a9d66efe 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -173,12 +173,10 @@ function* loadPostTypeEntities() { const isTemplate = [ 'wp_template', 'wp_template_part' ].includes( name ); - const namespace = postType?.rest_namespace - ? postType.rest_namespace - : 'wp/v2'; + const namespace = postType?.rest_namespace ?? 'wp/v2'; return { kind: 'postType', - baseURL: '/' + namespace + '/' + postType.rest_base, + baseURL: `/${ namespace }/${ postType.rest_base }`, baseURLParams: { context: 'edit' }, name, label: postType.labels.singular_name, @@ -207,12 +205,10 @@ function* loadTaxonomyEntities() { path: '/wp/v2/taxonomies?context=edit', } ); return map( taxonomies, ( taxonomy, name ) => { - const namespace = taxonomy?.rest_namespace - ? taxonomy.rest_namespace - : 'wp/v2'; + const namespace = taxonomy?.rest_namespace ?? 'wp/v2'; return { kind: 'taxonomy', - baseURL: '/' + namespace + '/' + taxonomy.rest_base, + baseURL: `/${ namespace }/${ taxonomy.rest_base }`, baseURLParams: { context: 'edit' }, name, label: taxonomy.labels.singular_name,