Skip to content

Commit

Permalink
Update to ensure created Page entities conform to object schema requi…
Browse files Browse the repository at this point in the history
…red by LinkControl
  • Loading branch information
getdave committed Feb 1, 2020
1 parent 2bc7d55 commit fb34fc3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { placeCaretAtHorizontalEdge } from '@wordpress/dom';
* Internal dependencies
*/
import { toolbarSubmenuIcon, itemSubmenuIcon } from './icons';
/* eslint-enable import/no-extraneous-dependencies */

function NavigationLinkEdit( {
attributes,
Expand Down Expand Up @@ -245,6 +244,14 @@ function NavigationLinkEdit( {
throw new TypeError( 'API response returned invalid entity.', entity );
}

const requiredEntityProps = ['id', 'title', 'link'];

const entityMissingProperty = requiredEntityProps.find(entityProp => !entity.hasOwnProperty(entityProp));

if (Boolean(entityMissingProperty)) {
throw new TypeError(`API response returned invalid entity. Missing required property "${entityMissingProperty}".`, entity);
}

return {
id: entity.id,
type,
Expand Down

0 comments on commit fb34fc3

Please sign in to comment.