PluginProbe
Flexible Subscriptions / trunk
Flexible Subscriptions vtrunk
1.8.5 1.8.4 1.8.3 1.8.2 1.8.1 1.8.0 1.7.19 1.7.18 1.7.17 1.7.16 1.7.15 1.7.14 1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 All 62 releases
flexible-subscriptions / src / Blocks / Integration.php

Integration.php in Flexible Subscriptions trunk, at src/Blocks/Integration.php

100 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3
4 namespace WPDesk\FlexibleSubscriptions\Blocks;
5
6 use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface;
7 use WPDesk\FlexibleSubscriptions\HookProvider\Product\ChangeAddButtonText;
8 use WPDesk\FlexibleSubscriptions\Vendor\WPDesk\Init\Plugin\Plugin;
9
10 class Integration implements IntegrationInterface {
11
12 /**
13 * @var Plugin
14 */
15 private $plugin;
16
17 /**
18 * @var ChangeAddButtonText
19 */
20 private $button_text_provider;
21
22 public function __construct( Plugin $plugin, ChangeAddButtonText $button_text_provider ) {
23 $this->plugin = $plugin;
24 $this->button_text_provider = $button_text_provider;
25 }
26
27 /**
28 * The name of the integration.
29 *
30 * @return string
31 */
32 public function get_name(): string {
33 return 'flexible-subscriptions';
34 }
35
36 /**
37 * When called, initializes the integration.
38 */
39 public function initialize(): void {
40 $script_path = 'dist/index.js';
41 $style_path = 'dist/index.css';
42 $script_asset_path = $this->plugin->get_path( 'assets/dist/index.asset.php' );
43 $script_asset = file_exists( $script_asset_path )
44 ? require $script_asset_path
45 : [
46 'dependencies' => [],
47 'version' => $this->plugin->get_version(),
48 ];
49
50 wp_register_script(
51 'fsb-blocks-integration',
52 $this->plugin->get_url( 'assets/dist/index.js' ),
53 $script_asset['dependencies'],
54 $script_asset['version'],
55 true
56 );
57
58 wp_register_style(
59 'fsb-blocks-integration',
60 $this->plugin->get_url( 'assets/dist/style-index.css' ),
61 [],
62 $script_asset['version']
63 );
64
65 wp_set_script_translations(
66 'fsb-blocks-integration',
67 'flexible-subscriptions',
68 );
69 }
70
71 /**
72 * Returns an array of script handles to enqueue in the frontend context.
73 *
74 * @return string[]
75 */
76 public function get_script_handles(): array {
77 return [ 'fsb-blocks-integration' ];
78 }
79
80 /**
81 * Returns an array of script handles to enqueue in the editor context.
82 *
83 * @return string[]
84 */
85 public function get_editor_script_handles(): array {
86 return [ 'fsb-blocks-integration' ];
87 }
88
89 /**
90 * An array of key, value pairs of data made available to the block on the client side.
91 *
92 * @return array
93 */
94 public function get_script_data(): array {
95 return [
96 'place_order_override' => $this->button_text_provider->__invoke( null ),
97 ];
98 }
99 }
100