Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move generic site data into self contained objects. #21368

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Feedback.
  • Loading branch information
thijsoo committed May 30, 2024
commit 0e183c6ceedc902f681e6be4e787ce8a15bc5acb
7 changes: 4 additions & 3 deletions admin/metabox/class-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,9 @@ public function enqueue() {
* @var $repo Website_Information_Repository
*/
$repo = YoastSEO()->classes->get( Website_Information_Repository::class );
$repo->get_post_site_information()->set_permalink( $this->get_permalink() );
$script_data = array_merge_recursive( $repo->get_post_site_information()->get_site_information(), $script_data );
$site_information = $repo->get_post_site_information();
$site_information->set_permalink( $this->get_permalink() );
$script_data = array_merge_recursive( $site_information->get_legacy_site_information(), $script_data );
if ( post_type_supports( get_post_type(), 'thumbnail' ) ) {
$asset_manager->enqueue_style( 'featured-image' );

Expand Down Expand Up @@ -1204,7 +1205,7 @@ protected function get_product_title() {
*
* @return string
*/
public function get_permalink() {
protected function get_permalink() {
$permalink = '';

if ( is_object( $this->get_metabox_post() ) ) {
Expand Down
5 changes: 3 additions & 2 deletions admin/taxonomy/class-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ public function admin_enqueue_scripts() {
* @var $repo Website_Information_Repository
*/
$repo = YoastSEO()->classes->get( Website_Information_Repository::class );
$repo->get_term_site_information()->set_term( get_term_by( 'id', $tag_id, $this::get_taxonomy() ) );
$script_data = array_merge_recursive( $repo->get_term_site_information()->get_site_information(), $script_data );
$term_information = $repo->get_term_site_information();
$term_information->set_term( get_term_by( 'id', $tag_id, $this::get_taxonomy() ) );
$script_data = array_merge_recursive( $term_information->get_site_information(), $script_data );

$asset_manager->localize_script( 'term-edit', 'wpseoScriptData', $script_data );
$asset_manager->enqueue_user_language_script();
Expand Down
21 changes: 0 additions & 21 deletions src/editors/domain/site/site-information-interface.php
thijsoo marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

20 changes: 4 additions & 16 deletions src/editors/framework/site/base-site-information.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@
/**
* The Base_Site_Information class.
*/
abstract class Base_Site_Information implements Site_Information_Interface {
abstract class Base_Site_Information {

/**
* The alert dismissal action.
*
* @var Alert_Dismissal_Action $alert_dismissal_action
*/
private $alert_dismissal_action;
protected $alert_dismissal_action;

/**
* The promotion manager.
*
* @var Promotion_Manager $promotion_manager
*/
private $promotion_manager;
protected $promotion_manager;

/**
* The short link helper.
*
* @var Short_Link_Helper $shortlink_helper
*/
private $short_link_helper;
protected $short_link_helper;

/**
* The wistia embed permission repository.
Expand Down Expand Up @@ -92,13 +92,7 @@ public function __construct(
* @return array<string|string,string[]>
*/
public function get_site_information(): array {
$dismissed_alerts = $this->alert_dismissal_action->all_dismissed();

return [
'dismissedAlerts' => $dismissed_alerts,
'currentPromotions' => $this->promotion_manager->get_current_promotions(),
'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ),
'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '',
'linkParams' => $this->short_link_helper->get_query_params(),
'pluginUrl' => \plugins_url( '', \WPSEO_FILE ),
'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( \get_current_user_id() ),
Expand All @@ -118,17 +112,11 @@ public function get_site_information(): array {
* @return array<string|string,string[]>
*/
public function get_legacy_site_information(): array {
$dismissed_alerts = $this->alert_dismissal_action->all_dismissed();

return [
'dismissedAlerts' => $dismissed_alerts,
'currentPromotions' => $this->promotion_manager->get_current_promotions(),
'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ),
'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '',
'linkParams' => $this->short_link_helper->get_query_params(),
'pluginUrl' => \plugins_url( '', \WPSEO_FILE ),
'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( \get_current_user_id() ),

'metabox' => [
'site_name' => $this->meta->for_current_page()->site_name,
'contentLocale' => \get_locale(),
Expand Down
13 changes: 13 additions & 0 deletions src/editors/framework/site/post-site-information.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ public function set_permalink( string $permalink ): void {
* @return array<string|string,string[]>
*/
public function get_legacy_site_information(): array {
$dismissed_alerts = $this->alert_dismissal_action->all_dismissed();

$data = [
'dismissedAlerts' => $dismissed_alerts,
'currentPromotions' => $this->promotion_manager->get_current_promotions(),
'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ),
'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '',

'metabox' => [
'search_url' => $this->search_url(),
'post_edit_url' => $this->edit_url(),
Expand All @@ -48,7 +55,13 @@ public function get_legacy_site_information(): array {
* @return array<string|string,string[]>
*/
public function get_site_information(): array {
$dismissed_alerts = $this->alert_dismissal_action->all_dismissed();

$data = [
'dismissedAlerts' => $dismissed_alerts,
'currentPromotions' => $this->promotion_manager->get_current_promotions(),
'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ),
'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '',
'search_url' => $this->search_url(),
'post_edit_url' => $this->edit_url(),
'base_url' => $this->base_url_for_js(),
Expand Down
25 changes: 13 additions & 12 deletions tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ protected function set_up() {
*/
public function test_legacy_site_information() {
$expected = [
'dismissedAlerts' => [
'the alert',
],
'currentPromotions' => [
'the promotion',
'another one',
],
'webinarIntroBlockEditorUrl' => 'https://expl.c',
'blackFridayBlockEditorUrl' => '',
'metabox' => [
'search_url' => 'https://example.org',
'post_edit_url' => 'https://example.org',
Expand All @@ -119,15 +128,6 @@ public function test_legacy_site_information() {
'isPremium' => true,
'siteIconUrl' => 'https://example.org',
],
'dismissedAlerts' => [
'the alert',
],
'currentPromotions' => [
'the promotion',
'another one',
],
'webinarIntroBlockEditorUrl' => 'https://expl.c',
'blackFridayBlockEditorUrl' => '',
'linkParams' => [
'param',
'param2',
Expand Down Expand Up @@ -157,9 +157,6 @@ public function test_legacy_site_information() {
*/
public function test_site_information() {
$expected = [
'search_url' => 'https://example.org',
'post_edit_url' => 'https://example.org',
'base_url' => 'https://example.org',

'dismissedAlerts' => [
'the alert',
Expand All @@ -170,6 +167,10 @@ public function test_site_information() {
],
'webinarIntroBlockEditorUrl' => 'https://expl.c',
'blackFridayBlockEditorUrl' => '',
'search_url' => 'https://example.org',
'post_edit_url' => 'https://example.org',
'base_url' => 'https://example.org',

'linkParams' => [
'param',
'param2',
Expand Down