From 80e6f4120a3bcf1c79032b1a6b67dc662fa3979d Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 9 Apr 2019 13:14:17 +0200 Subject: [PATCH] Refactor edit to set the default value for download button label --- packages/block-library/src/file/block.json | 3 +-- packages/block-library/src/file/edit.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/file/block.json b/packages/block-library/src/file/block.json index 693fecc342161..0c36a06aa9a55 100644 --- a/packages/block-library/src/file/block.json +++ b/packages/block-library/src/file/block.json @@ -32,8 +32,7 @@ "downloadButtonText": { "type": "string", "source": "html", - "selector": "a[download]", - "default": "Download" + "selector": "a[download]" } } } diff --git a/packages/block-library/src/file/edit.js b/packages/block-library/src/file/edit.js index 3ce7211eceb85..9aa76977cc2ce 100644 --- a/packages/block-library/src/file/edit.js +++ b/packages/block-library/src/file/edit.js @@ -29,7 +29,7 @@ import { } from '@wordpress/block-editor'; import { mediaUpload } from '@wordpress/editor'; import { Component, Fragment } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; +import { __, _x } from '@wordpress/i18n'; /** * Internal dependencies @@ -55,8 +55,8 @@ class FileEdit extends Component { } componentDidMount() { - const { attributes, noticeOperations } = this.props; - const { href } = attributes; + const { attributes, noticeOperations, setAttributes } = this.props; + const { downloadButtonText, href } = attributes; // Upload a file drag-and-dropped into the editor if ( isBlobURL( href ) ) { @@ -73,6 +73,12 @@ class FileEdit extends Component { revokeBlobURL( href ); } + + if ( downloadButtonText === undefined ) { + setAttributes( { + downloadButtonText: _x( 'Download', 'button label' ), + } ); + } } componentDidUpdate( prevProps ) {