Skip to content

Commit

Permalink
Blog Subscription Widget: deprecate widget and transform to block (#2…
Browse files Browse the repository at this point in the history
…1184)

* [not verified] Blog Subscription Widget: Added transform to block

* [not verified] Remove widget from Legacy block
  • Loading branch information
arcangelini authored Oct 19, 2021
1 parent d357636 commit 9cc4ab2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: compat

Subscription Widget: removed from Legacy Widget block and added transform
23 changes: 23 additions & 0 deletions projects/plugins/jetpack/extensions/blocks/subscriptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { __, _x } from '@wordpress/i18n';
import { Rect, Path, SVG } from '@wordpress/components';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -58,6 +59,28 @@ export const settings = {
attributes,
edit,
save,
transforms: {
from: [
{
type: 'block',
isMultiBlock: false,
blocks: [ 'core/legacy-widget' ],
isMatch: ( { idBase, instance } ) => {
if ( ! instance?.raw ) {
return false;
}
return idBase === 'blog_subscription';
},
transform: ( { instance } ) => {
return createBlock( 'jetpack/subscriptions', {
showSubscribersTotal: instance.raw.show_subscribers_total,
submitButtonText: instance.raw.subscribe_button,
subscribePlaceholder: instance.raw.subscribe_placeholder,
} );
},
},
],
},
example: {
attributes: {},
},
Expand Down
18 changes: 18 additions & 0 deletions projects/plugins/jetpack/modules/subscriptions/views.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

class Jetpack_Subscriptions_Widget extends WP_Widget {

const ID_BASE = 'blog_subscription';

static $instance_count = 0;

/**
* @var array When printing the submit button, what tags are allowed
*/
Expand Down Expand Up @@ -32,6 +36,7 @@ function __construct() {
'classname' => 'widget_blog_subscription jetpack_subscription_widget',
'description' => __( 'Add an email signup form to allow people to subscribe to your blog.', 'jetpack' ),
'customize_selective_refresh' => true,
'show_instance_in_rest' => true,
);

$name = self::is_jetpack() ?
Expand All @@ -54,6 +59,19 @@ function __construct() {
) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
}

add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) );
}

/**
* Remove Social Icons widget from Legacy Widget block.
*
* @param array $widget_types Widget type data.
* This only applies to new blocks being added.
*/
public function hide_widget_in_block_editor( $widget_types ) {
$widget_types[] = self::ID_BASE;
return $widget_types;
}

/**
Expand Down

0 comments on commit 9cc4ab2

Please sign in to comment.