fetchFieldData ( objectFetchID = null ) {
		const { setAttributes } = this.props;
		const base_rest_path    = '/wp-museum/v1/';
		const objectID          = objectFetchID ? objectFetchID : this.props.attributes.objectID;
		
		if ( objectID != null ) {
			const object_path = base_rest_path + 'all/' + objectID;
			const that = this; //There's probably a more elegant way to do this.
			apiFetch( { path: object_path } ).then( result => {
				that.setState( { object_data: result } );
				setAttributes( {
					title     : result['post_title'],
					excerpt   : result['excerpt'],
					objectURL : result['link']
				} );
				apiFetch(
					{ path: base_rest_path + 
							result.post_type +
							'/fields'
					}
				).then( result => {
					const { fields }      = that.props.attributes;
					const { object_data } = that.state;
					let newFields         = {};
					let fieldData         = {};
					for ( let key in result ) {
						if ( typeof ( fields[key] ) === 'undefined') {
							newFields[key] = false;
						} else {
							newFields[key] = fields[key];
						}
						let content = '';
						if ( result[key]['type'] === 'tinyint' ) {
							if ( object_data[ result[key]['slug'] ] === 1 ) {
								content = 'Yes';
							} else {
								content = 'No';
							}
						} else {
							content = object_data[ result[key]['slug'] ];
						}
						fieldData[key] = {
							name    : result[key]['name'],
							content : content
						}
					}
					setAttributes( {
						catID     : object_data[ object_data[ 'cat_field' ] ],
						fields    : newFields,
						fieldData : fieldData
					} );
				} );
			} );
		}
	}
/**
	 * Fetches object data from WordPress REST api.
	 *
	 * If objectFetchID is set, then fetch that object. Otherwise use the
	 * objectID set in the block attributes. This function takes an
	 * objectFetchID so that you don't need to wait for setAttributes to fire
	 * before fetching data from the API, which would introduce additional
	 * update lag.
	 *
	 * @param {number} objectFetchID WordPress post_id of object.
	 */
Fetches object data from WordPress REST api.
If objectFetchID is set, then fetch that object. Otherwise use the
objectID set in the block attributes. This function takes an
objectFetchID so that you don't need to wait for setAttributes to fire
before fetching data from the API, which would introduce additional
update lag.


Fetches object data from WordPress REST api . If objectFetchID is set then fetch that object . Otherwise use the objectID set in the block attributes . This function takes an objectFetchID so that you don ' t need to wait for setAttributes to fire before fetching data from the API which would introduce additional update lag .
fetchFieldData ( objectFetchID = null ) {
		const { setAttributes } = this.props;
		const base_rest_path    = '/wp-museum/v1/';
		const objectID          = objectFetchID ? objectFetchID : this.props.attributes.objectID;
		if ( objectID != null ) {
			const object_path = base_rest_path + 'all/' + objectID;
			const that = this; 
			apiFetch( { path: object_path } ).then( result => {
				that.setState( { object_data: result } );
				setAttributes( {
					title     : result['post_title'],
					excerpt   : result['excerpt'],
					objectURL : result['link']
				} );
				apiFetch(
					{ path: base_rest_path + 
							result.post_type +
							'/fields'
					}
				).then( result => {
					const { fields }      = that.props.attributes;
					const { object_data } = that.state;
					let newFields         = {};
					let fieldData         = {};
					for ( let key in result ) {
						if ( typeof ( fields[key] ) === 'undefined') {
							newFields[key] = false;
						} else {
							newFields[key] = fields[key];
						}
						let content = '';
						if ( result[key]['type'] === 'tinyint' ) {
							if ( object_data[ result[key]['slug'] ] === 1 ) {
								content = 'Yes';
							} else {
								content = 'No';
							}
						} else {
							content = object_data[ result[key]['slug'] ];
						}
						fieldData[key] = {
							name    : result[key]['name'],
							content : content
						}
					}
					setAttributes( {
						catID     : object_data[ object_data[ 'cat_field' ] ],
						fields    : newFields,
						fieldData : fieldData
					} );
				} );
			} );
		}
	}
fetchFieldData ( objectFetchID = null ) { const { setAttributes } = this . props ; const base_rest_path = '/wp-museum/v1/' ; const objectID = objectFetchID ? objectFetchID : this . props . attributes . objectID ; if ( objectID != null ) { const object_path = base_rest_path + 'all/' + objectID ; const that = this ; apiFetch ( { path : object_path } ) . then ( result => { that . setState ( { object_data : result } ) ; setAttributes ( { title : result [ 'post_title' ] , excerpt : result [ 'excerpt' ] , objectURL : result [ 'link' ] } ) ; apiFetch ( { path : base_rest_path + result . post_type + '/fields' } ) . then ( result => { const { fields } = that . props . attributes ; const { object_data } = that . state ; let newFields = { } ; let fieldData = { } ; for ( let key in result ) { if ( typeof ( fields [ key ] ) === 'undefined' ) { newFields [ key ] = false ; } else { newFields [ key ] = fields [ key ] ; } let content = '' ; if ( result [ key ] [ 'type' ] === 'tinyint' ) { if ( object_data [ result [ key ] [ 'slug' ] ] === 1 ) { content = 'Yes' ; } else { content = 'No' ; } } else { content = object_data [ result [ key ] [ 'slug' ] ] ; } fieldData [ key ] = { name : result [ key ] [ 'name' ] , content : content } } setAttributes ( { catID : object_data [ object_data [ 'cat_field' ] ] , fields : newFields , fieldData : fieldData } ) ; } ) ; } ) ; } }
Fetches object data from WordPress REST api.
Fetches object data from WordPress REST api .
//There's probably a more elegant way to do this.