From 057e62ae86a0fa24287c2310d60371d63b6089b2 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Tue, 17 Aug 2021 15:43:23 +0200 Subject: [PATCH] Fetch title from core/latest-posts block type --- .../src/latest-posts/edit.native.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/block-library/src/latest-posts/edit.native.js b/packages/block-library/src/latest-posts/edit.native.js index 0aefc6b889cb91..08f1f5abe9b58c 100644 --- a/packages/block-library/src/latest-posts/edit.native.js +++ b/packages/block-library/src/latest-posts/edit.native.js @@ -9,8 +9,7 @@ import { isEmpty } from 'lodash'; */ import { Component } from '@wordpress/element'; import { compose, withPreferredColorScheme } from '@wordpress/compose'; -import { withDispatch } from '@wordpress/data'; -import { coreBlocks } from '@wordpress/block-library'; +import { withDispatch, withSelect } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { postList as icon } from '@wordpress/icons'; import { InspectorControls } from '@wordpress/block-editor'; @@ -22,6 +21,7 @@ import { RangeControl, QueryControls, } from '@wordpress/components'; +import { store as blocksStore } from '@wordpress/blocks'; /** * Internal dependencies @@ -189,14 +189,12 @@ class LatestPostsEdit extends Component { render() { const { + blockTitle, getStylesFromColorScheme, - name, openGeneralSidebar, isSelected, } = this.props; - const blockType = coreBlocks[ name ]; - const blockStyle = getStylesFromColorScheme( styles.latestPostBlock, styles.latestPostBlockDark @@ -221,9 +219,7 @@ class LatestPostsEdit extends Component { { isSelected && this.getInspectorControls() } - - { blockType.settings.title } - + { blockTitle } { __( 'CUSTOMIZE' ) } @@ -234,6 +230,12 @@ class LatestPostsEdit extends Component { } export default compose( [ + withSelect( ( select, { name } ) => { + const blockType = select( blocksStore ).getBlockType( name ); + return { + blockTitle: blockType?.title || name, + }; + } ), withDispatch( ( dispatch ) => { const { openGeneralSidebar } = dispatch( 'core/edit-post' );