-
Notifications
You must be signed in to change notification settings - Fork 953
Expand file tree
/
Copy pathcontent-planner-integration.php
More file actions
86 lines (75 loc) · 2.25 KB
/
content-planner-integration.php
File metadata and controls
86 lines (75 loc) · 2.25 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
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
namespace Yoast\WP\SEO\AI\Content_Planner\User_Interface;
use WPSEO_Admin_Asset_Manager;
use Yoast\WP\SEO\AI\Content_Planner\Application\Content_Planner_Endpoints_Repository;
use Yoast\WP\SEO\Conditionals\AI_Conditional;
use Yoast\WP\SEO\Conditionals\AI_Editor_Conditional;
use Yoast\WP\SEO\Integrations\Integration_Interface;
/**
* Content_Planner_Integration class.
*/
class Content_Planner_Integration implements Integration_Interface {
/**
* Represents the admin asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
private $asset_manager;
/**
* The endpoints repository.
*
* @var Content_Planner_Endpoints_Repository
*/
private $endpoints_repository;
/**
* Returns the conditionals based in which this loadable should be active.
*
* @return array<string>
*/
public static function get_conditionals(): array {
return [ AI_Conditional::class, AI_Editor_Conditional::class ];
}
/**
* Constructs the class.
*
* @param WPSEO_Admin_Asset_Manager $asset_manager The admin asset manager.
* @param Content_Planner_Endpoints_Repository $endpoints_repository The endpoints repository.
*/
public function __construct(
WPSEO_Admin_Asset_Manager $asset_manager,
Content_Planner_Endpoints_Repository $endpoints_repository
) {
$this->asset_manager = $asset_manager;
$this->endpoints_repository = $endpoints_repository;
}
/**
* Initializes the integration.
*
* This is the place to register hooks and filters.
*
* @return void
*/
public function register_hooks() {
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
}
/**
* Returns the script data for the content planner.
*
* @return array<string, array<string>>
*/
public function get_script_data(): array {
return [
'endpoints' => $this->endpoints_repository->get_all_endpoints()->to_paths_array(),
];
}
/**
* Localizes the content planner script data onto the block-editor bundle,
* which lazy-loads the planner module on demand.
*
* @return void
*/
public function enqueue_assets() {
$this->asset_manager->localize_script( 'block-editor', 'wpseoContentPlanner', $this->get_script_data() );
}
}