class-wpml-gutenberg-integration-factory.php
2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
use function WPML\Container\make;
use function WPML\Container\share;
class WPML_Gutenberg_Integration_Factory {
/** @return \WPML\PB\Gutenberg\Integration_Composite */
public function create() {
$integrations = new WPML\PB\Gutenberg\Integration_Composite();
$mainIntegration = $this->create_gutenberg_integration();
share( [ $mainIntegration ] );
$integrations->add( $mainIntegration );
if ( $this->should_translate_reusable_blocks() ) {
$integrations->add(
make( '\WPML\PB\Gutenberg\ReusableBlocks\Integration' )
);
if ( is_admin() ) {
$integrations->add(
make( '\WPML\PB\Gutenberg\ReusableBlocks\AdminIntegration' )
);
}
}
if ( ! is_admin() ) {
$integrations->add(
make( \WPML\PB\Gutenberg\Widgets\Block\DisplayTranslation::class )
);
$integrations->add(
make( \WPML\PB\Gutenberg\Widgets\Block\Search::class )
);
$integrations->add(
make( \WPML\PB\Gutenberg\Navigation\Frontend::class )
);
$integrations->add(
make( \WPML\PB\Gutenberg\ConvertIdsInBlock\Hooks::class )
);
}
$integrations->add(
make( \WPML\PB\Gutenberg\Widgets\Block\RegisterStrings::class )
);
return $integrations;
}
/**
* @return WPML_Gutenberg_Integration
*/
public function create_gutenberg_integration() {
/**
* @var SitePress $sitepress
* @var wpdb $wpdb
*/
global $sitepress, $wpdb;
$config_option = new WPML_Gutenberg_Config_Option();
$strings_in_block = $this->create_strings_in_block( $config_option );
$string_factory = new WPML_ST_String_Factory( $wpdb );
$strings_registration = new WPML_Gutenberg_Strings_Registration(
$strings_in_block,
$string_factory,
new WPML_PB_Reuse_Translations( $string_factory ),
new WPML_PB_String_Translation( $wpdb ),
make( 'WPML_Translate_Link_Targets' ),
WPML\PB\TranslateLinks::getTranslatorForString( $string_factory, $sitepress->get_active_languages() )
);
return new WPML_Gutenberg_Integration(
$strings_in_block,
$config_option,
$strings_registration
);
}
private function create_strings_in_block( $config_option ) {
$string_parsers = [
new WPML\PB\Gutenberg\StringsInBlock\HTML( $config_option ),
new WPML\PB\Gutenberg\StringsInBlock\Attributes( $config_option ),
];
return new WPML\PB\Gutenberg\StringsInBlock\Collection( $string_parsers );
}
/** @return bool */
private function should_translate_reusable_blocks() {
/** @var SitePress $sitepress */
global $sitepress;
return $sitepress->is_translated_post_type(
WPML\PB\Gutenberg\ReusableBlocks\Translation::POST_TYPE
);
}
}