From d7033d538ed874e203c74bb3998c41c9c1d600e2 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 8 Aug 2017 17:10:21 +0100 Subject: [PATCH] Gallery Block: Fix inserting a gallery --- blocks/library/gallery/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/blocks/library/gallery/index.js b/blocks/library/gallery/index.js index c4eba4657bfc28..a558a6412f7d99 100644 --- a/blocks/library/gallery/index.js +++ b/blocks/library/gallery/index.js @@ -59,7 +59,6 @@ const editMediaLibrary = ( attributes, setAttributes ) => { }; function defaultColumnsNumber( attributes ) { - attributes.images = attributes.images || []; return Math.min( 3, attributes.images.length ); } @@ -68,6 +67,10 @@ registerBlockType( 'core/gallery', { icon: 'format-gallery', category: 'common', + defaultAttributes: { + images: [], + }, + getEditWrapperProps( attributes ) { const { align } = attributes; if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) { @@ -76,7 +79,7 @@ registerBlockType( 'core/gallery', { }, edit( { attributes, setAttributes, focus, className } ) { - const { images = [], columns = defaultColumnsNumber( attributes ), align = 'none' } = attributes; + const { images, columns = defaultColumnsNumber( attributes ), align = 'none' } = attributes; const setLinkTo = ( value ) => setAttributes( { linkTo: value } ); const setColumnsNumber = ( event ) => setAttributes( { columns: event.target.value } ); const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } );