From 58d11ef414a76deb11453110ac68ba9ec026c471 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 8 Jul 2020 09:24:48 +1000 Subject: [PATCH] Add migration to prevent language switch invalidation of block When a block is created in English and the site switched to a second langauge before the block is migrated, the block will be deemed invalid. This change will attempt to fall back to English defaults for the placeholder text in the saved shortcode that causes the invalidation. This will not change migrated attributes only the generated content from the deprecated block save function. It also will only cover blocks first created in English and using default text. If the block was created in a second language, there is no means to determine the language and therefore the default text for that translation to fall back to. --- .../blocks/subscriptions/deprecated/index.js | 3 ++- ...save.js => get-subscriptions-shortcode.js} | 19 ++++++++++++++++--- .../subscriptions/deprecated/v3/index.js | 4 ++-- .../subscriptions/deprecated/v4/index.js | 11 +++++++++++ 4 files changed, 31 insertions(+), 6 deletions(-) rename extensions/blocks/subscriptions/deprecated/v3/{save.js => get-subscriptions-shortcode.js} (84%) create mode 100644 extensions/blocks/subscriptions/deprecated/v4/index.js diff --git a/extensions/blocks/subscriptions/deprecated/index.js b/extensions/blocks/subscriptions/deprecated/index.js index 6ff5ce78ec7ee..c511e4f787de8 100644 --- a/extensions/blocks/subscriptions/deprecated/index.js +++ b/extensions/blocks/subscriptions/deprecated/index.js @@ -5,5 +5,6 @@ import deprecatedV1 from './v1'; import deprecatedV2 from './v2'; import deprecatedV3 from './v3'; +import deprecatedV4 from './v4'; -export default [ deprecatedV1, deprecatedV2, deprecatedV3 ]; +export default [ deprecatedV1, deprecatedV2, deprecatedV3, deprecatedV4 ]; diff --git a/extensions/blocks/subscriptions/deprecated/v3/save.js b/extensions/blocks/subscriptions/deprecated/v3/get-subscriptions-shortcode.js similarity index 84% rename from extensions/blocks/subscriptions/deprecated/v3/save.js rename to extensions/blocks/subscriptions/deprecated/v3/get-subscriptions-shortcode.js index 27481d37731ee..c35ac192eb7a3 100644 --- a/extensions/blocks/subscriptions/deprecated/v3/save.js +++ b/extensions/blocks/subscriptions/deprecated/v3/get-subscriptions-shortcode.js @@ -12,6 +12,7 @@ import classnames from 'classnames'; /** * Internal dependencies */ +import definedAttributes from './attributes'; import { DEFAULT_BORDER_RADIUS_VALUE, DEFAULT_BORDER_WEIGHT_VALUE, @@ -20,7 +21,7 @@ import { DEFAULT_FONTSIZE_VALUE, } from '../../constants'; -export default function Save( { className, attributes } ) { +export default function getSubscriptionsShortcode( className, attributes, checkTextDefaults = null ) { const { subscribePlaceholder, showSubscribersTotal, @@ -102,15 +103,27 @@ export default function Save( { className, attributes } ) { ); }; + let placeholderText = subscribePlaceholder; + let buttonText = submitButtonText; + + if ( 'check-text-defaults' === checkTextDefaults ) { + placeholderText = subscribePlaceholder === definedAttributes.subscribePlaceholder.default + ? 'Enter your email address' + : subscribePlaceholder; + buttonText = submitButtonText === definedAttributes.submitButtonText.default + ? 'Sign Up' + : submitButtonText; + } + return (