Skip to content

Commit

Permalink
Add migration to prevent language switch invalidation of block
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aaronrobertshaw authored and scruffian committed Jul 8, 2020
1 parent 95e75cb commit 58d11ef
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
3 changes: 2 additions & 1 deletion extensions/blocks/subscriptions/deprecated/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import classnames from 'classnames';
/**
* Internal dependencies
*/
import definedAttributes from './attributes';
import {
DEFAULT_BORDER_RADIUS_VALUE,
DEFAULT_BORDER_WEIGHT_VALUE,
Expand All @@ -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,
Expand Down Expand Up @@ -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 (
<div className={ getBlockClassName() }>
<RawHTML>
{ `
[jetpack_subscription_form
subscribe_placeholder="${ subscribePlaceholder }"
subscribe_placeholder="${ placeholderText }"
show_subscribers_total="${ showSubscribersTotal }"
button_on_newline="${ buttonOnNewLine }"
submit_button_text="${ submitButtonText }"
submit_button_text="${ buttonText }"
custom_background_emailfield_color="${ emailFieldBackgroundStyle }"
custom_background_button_color="${ buttonBackgroundStyle }"
custom_text_button_color="${ customTextColor }"
Expand Down
4 changes: 2 additions & 2 deletions extensions/blocks/subscriptions/deprecated/v3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Internal dependencies
*/
import attributes from './attributes';
import save from './save';
import getSubscriptionsShortcode from './get-subscriptions-shortcode';

export default {
attributes,
save,
save: ( { className, attrs } ) => getSubscriptionsShortcode( className, attrs ),
};
11 changes: 11 additions & 0 deletions extensions/blocks/subscriptions/deprecated/v4/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Internal dependencies
*/
import attributes from '../v3/attributes';
import getSubscriptionsShortcode from '../v3/get-subscriptions-shortcode';

export default {
attributes,
save: ( { className, attrs } ) =>
getSubscriptionsShortcode( className, attrs, 'check-text-defaults' ),
};

0 comments on commit 58d11ef

Please sign in to comment.