66
77use HWP \Previews \Admin \Settings \Fields \Settings_Field_Collection ;
88use HWP \Previews \Preview \Parameter \Preview_Parameter_Registry ;
9+ use HWP \Previews \Preview \Post \Post_Editor_Service ;
910use HWP \Previews \Preview \Post \Post_Preview_Service ;
1011use HWP \Previews \Preview \Post \Post_Settings_Service ;
1112use HWP \Previews \Preview \Post \Post_Type_Service ;
12- use HWP \Previews \Preview \Post \Type \Contracts \Post_Types_Config_Interface ;
13- use HWP \Previews \Preview \Post \Type \Post_Types_Config_Registry ;
1413use HWP \Previews \Preview \Template \Template_Resolver_Service ;
1514use HWP \Previews \Preview \Url \Preview_Url_Resolver_Service ;
1615use WP_Post ;
1716use WP_REST_Response ;
1817
1918class Preview_Hooks {
20- /**
21- * Post types configuration.
22- *
23- * @var \HWP\Previews\Preview\Post\Type\Contracts\Post_Types_Config_Interface
24- */
25- protected Post_Types_Config_Interface $ types_config ;
26-
2719 /**
2820 * Post-settings service that provides access to post-settings.
2921 *
@@ -51,14 +43,6 @@ class Preview_Hooks {
5143 * Initializes the settings helper, post types and statuses configurations, and the preview link service.
5244 */
5345 public function __construct () {
54-
55- // @TODO - Refactor to use a factory or service locator pattern and analyze what is is actually needed.
56-
57- $ this ->types_config = apply_filters (
58- 'hwp_previews_hooks_post_type_config ' ,
59- Post_Types_Config_Registry::get_post_type_config ()
60- );
61-
6246 $ this ->post_preview_service = new Post_Preview_Service ();
6347 $ this ->post_settings_service = new Post_Settings_Service ();
6448 }
@@ -72,11 +56,15 @@ public function setup(): void {
7256 add_filter ( 'page_attributes_dropdown_pages_args ' , [ $ this , 'enable_post_statuses_as_parent ' ], 10 , 1 );
7357 add_filter ( 'quick_edit_dropdown_pages_args ' , [ $ this , 'enable_post_statuses_as_parent ' ], 10 , 1 );
7458
75- foreach ( $ this ->types_config ->get_post_types () as $ post_type ) {
76- if ( ! $ this ->types_config ->gutenberg_editor_enabled ( $ post_type ) ) {
59+ $ post_editor_service = new Post_Editor_Service ();
60+ $ post_types = $ this ->post_preview_service ->get_post_types ();
61+
62+ // Enable post-statuses as parent for the post-types specified in the post-types config.
63+ foreach ( $ post_types as $ post_type => $ label ) {
64+ if ( ! $ post_editor_service ->gutenberg_editor_enabled ( $ post_type ) ) {
7765 continue ;
7866 }
79- // @TODO - Add unit tests for this filter.
67+
8068 add_filter ( 'rest_ ' . $ post_type . '_query ' , [ $ this , 'enable_post_statuses_as_parent ' ], 10 , 1 );
8169 }
8270
@@ -91,13 +79,13 @@ public function setup(): void {
9179 * Hack Function that changes the preview link for draft articles,
9280 * this must be removed when properly fixed https://github.com/WordPress/gutenberg/issues/13998.
9381 */
94- foreach ( $ this -> types_config -> get_public_post_types () as $ key => $ label ) {
95- add_filter ( 'rest_prepare_ ' . $ key , [ $ this , 'filter_rest_prepare_link ' ], 10 , 2 );
82+ foreach ( $ post_types as $ post_type => $ label ) {
83+ add_filter ( 'rest_prepare_ ' . $ post_type , [ $ this , 'filter_rest_prepare_link ' ], 10 , 2 );
9684 }
9785 }
9886
9987 /**
100- * Enable post statuses as parent for the post types specified in the post types config.
88+ * Enable post- statuses as parent for the post types specified in the post types config.
10189 *
10290 * @param array<mixed> $args The arguments for the dropdown pages.
10391 *
0 commit comments