Skip to content

Commit

Permalink
Merge pull request #21825 from Yoast/327-create-the-rest-of-the-scrip…
Browse files Browse the repository at this point in the history
…t-data-disabled-indexables-nonces-etc

Add dashboard configuration object.
  • Loading branch information
leonidasmi authored Nov 18, 2024
2 parents 56fbe7f + c154ab8 commit c8821a7
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 60 deletions.
4 changes: 2 additions & 2 deletions packages/js/src/general/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ domReady( () => {
} );
const isRtl = select( STORE_NAME ).selectPreference( "isRtl", false );

const contentTypes = get( window, "wpseoScriptData.contentTypes", [] );
const userName = get( window, "wpseoScriptData.dash.userName", "User" );
const contentTypes = get( window, "wpseoScriptData.dashboard.contentTypes", [] );
const userName = get( window, "wpseoScriptData.dashboard.displayName", "User" );

const router = createHashRouter(
createRoutesFromElements(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php


// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\Dashboard\Application\Configuration;

use Yoast\WP\SEO\Dashboard\Application\Content_Types\Content_Types_Repository;
use Yoast\WP\SEO\Editors\Application\Analysis_Features\Enabled_Analysis_Features_Repository;
use Yoast\WP\SEO\Editors\Framework\Keyphrase_Analysis;
use Yoast\WP\SEO\Editors\Framework\Readability_Analysis;
use Yoast\WP\SEO\Helpers\Indexable_Helper;
use Yoast\WP\SEO\Helpers\User_Helper;

/**
* Responsible for the dashboard configuration.
*/
class Dashboard_Configuration {

/**
* The content types repository.
*
* @var Content_Types_Repository $content_types_repository
*/
private $content_types_repository;

/**
* The indexable helper.
*
* @var Indexable_Helper $indexable_helper
*/
private $indexable_helper;

/**
* The user helper.
*
* @var User_Helper $user_helper
*/
private $user_helper;

/**
* The repository.
*
* @var Enabled_Analysis_Features_Repository
*/
private $enabled_analysis_features_repository;

/**
* The constructor.
*
* @param Content_Types_Repository $content_types_repository The content types repository.
* @param Indexable_Helper $indexable_helper The indexable helper
* repository.
* @param User_Helper $user_helper The user helper.
* @param Enabled_Analysis_Features_Repository $enabled_analysis_features_repository The analysis feature
* repository.
*/
public function __construct(
Content_Types_Repository $content_types_repository,
Indexable_Helper $indexable_helper,
User_Helper $user_helper,
Enabled_Analysis_Features_Repository $enabled_analysis_features_repository
) {
$this->content_types_repository = $content_types_repository;
$this->indexable_helper = $indexable_helper;
$this->user_helper = $user_helper;
$this->enabled_analysis_features_repository = $enabled_analysis_features_repository;
}

/**
* Returns a configuration
*
* @return array<string,array<string>>
*/
public function get_configuration(): array {
return [
'contentTypes' => $this->content_types_repository->get_content_types(),
'indexablesEnabled' => $this->indexable_helper->should_index_indexables(),
'displayName' => $this->user_helper->get_current_user_display_name(),
'enabledAnalysisFeatures' => $this->enabled_analysis_features_repository->get_features_by_keys(
[
Readability_Analysis::NAME,
Keyphrase_Analysis::NAME,
]
)->to_array(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ public function get_enabled_features(): Analysis_Features_List {
$this->enabled_analysis_features->add_feature( $analysis_feature );
}
}

return $this->enabled_analysis_features;
}

/**
* Returns the analysis list for the given names.
*
* @param array<string> $feature_names The feature names to include.
*
* @return Analysis_Features_List The analysis list.
*/
public function get_features_by_keys( array $feature_names ): Analysis_Features_List {
$enabled_analysis_features = new Analysis_Features_List();

foreach ( $this->plugin_features as $plugin_feature ) {
if ( \in_array( $plugin_feature->get_name(), $feature_names, true ) ) {
$analysis_feature = new Analysis_Feature( $plugin_feature->is_enabled(), $plugin_feature->get_name(), $plugin_feature->get_legacy_key() );
$enabled_analysis_features->add_feature( $analysis_feature );
}
}

return $enabled_analysis_features;
}
}
15 changes: 15 additions & 0 deletions src/editors/domain/analysis-features/analysis-features-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ public function parse_to_legacy_array(): array {
foreach ( $this->features as $feature ) {
$array = \array_merge( $array, $feature->to_legacy_array() );
}

return $array;
}

/**
* Parses the feature list to an array representation.
*
* @return array<string,bool> The list presented as a key value representation.
*/
public function to_array(): array {
$array = [];
foreach ( $this->features as $feature ) {
$array = \array_merge( $array, $feature->to_array() );
}

return $array;
}
}
4 changes: 3 additions & 1 deletion src/editors/framework/cornerstone-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class Cornerstone_Content implements Analysis_Feature_Interface {

public const NAME = 'cornerstoneContent';

/**
* The options helper.
*
Expand Down Expand Up @@ -41,7 +43,7 @@ public function is_enabled(): bool {
* @return string The name.
*/
public function get_name(): string {
return 'cornerstoneContent';
return self::NAME;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/editors/framework/inclusive-language-analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
class Inclusive_Language_Analysis implements Analysis_Feature_Interface {

public const NAME = 'inclusiveLanguageAnalysis';

/**
* The options helper.
*
Expand Down Expand Up @@ -102,7 +104,7 @@ private function is_current_version_supported(): bool {
* @return string The name.
*/
public function get_name(): string {
return 'inclusiveLanguageAnalysis';
return self::NAME;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/editors/framework/keyphrase-analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class Keyphrase_Analysis implements Analysis_Feature_Interface {

public const NAME = 'keyphraseAnalysis';

/**
* The options helper.
*
Expand Down Expand Up @@ -59,7 +61,7 @@ public function is_globally_enabled(): bool {
* @return string The name.
*/
public function get_name(): string {
return 'keyphraseAnalysis';
return self::NAME;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/editors/framework/previously-used-keyphrase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
class Previously_Used_Keyphrase implements Analysis_Feature_Interface {

public const NAME = 'previouslyUsedKeyphrase';

/**
* If this analysis is enabled.
*
Expand All @@ -29,7 +31,7 @@ public function is_enabled(): bool {
* @return string
*/
public function get_name(): string {
return 'previouslyUsedKeyphrase';
return self::NAME;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/editors/framework/readability-analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* This class describes the Readability analysis feature.
*/
class Readability_Analysis implements Analysis_Feature_Interface {
public const NAME = 'readabilityAnalysis';

/**
* The options helper.
Expand Down Expand Up @@ -59,7 +60,7 @@ private function is_globally_enabled(): bool {
* @return string The name.
*/
public function get_name(): string {
return 'readabilityAnalysis';
return self::NAME;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/editors/framework/word-form-recognition.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class Word_Form_Recognition implements Analysis_Feature_Interface {

public const NAME = 'wordFormRecognition';

/**
* The language helper.
*
Expand Down Expand Up @@ -41,7 +43,7 @@ public function is_enabled(): bool {
* @return string
*/
public function get_name(): string {
return 'wordFormRecognition';
return self::NAME;
}

/**
Expand Down
52 changes: 26 additions & 26 deletions src/general/user-interface/general-page-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Yoast\WP\SEO\Actions\Alert_Dismissal_Action;
use Yoast\WP\SEO\Conditionals\Admin\Non_Network_Admin_Conditional;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Dashboard\Application\Content_Types\Content_Types_Repository;
use Yoast\WP\SEO\Dashboard\Application\Configuration\Dashboard_Configuration;
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
use Yoast\WP\SEO\Helpers\Notification_Helper;
use Yoast\WP\SEO\Helpers\Product_Helper;
Expand All @@ -31,6 +31,13 @@ class General_Page_Integration implements Integration_Interface {
*/
protected $notification_helper;

/**
* The dashboard configuration.
*
* @var Dashboard_Configuration
*/
private $dashboard_configuration;

/**
* Holds the WPSEO_Admin_Asset_Manager.
*
Expand Down Expand Up @@ -73,24 +80,17 @@ class General_Page_Integration implements Integration_Interface {
*/
private $alert_dismissal_action;

/**
* The content types repository.
*
* @var Content_Types_Repository $content_types_repository
*/
private $content_types_repository;

/**
* Constructs Academy_Integration.
*
* @param WPSEO_Admin_Asset_Manager $asset_manager The WPSEO_Admin_Asset_Manager.
* @param Current_Page_Helper $current_page_helper The Current_Page_Helper.
* @param Product_Helper $product_helper The Product_Helper.
* @param Short_Link_Helper $shortlink_helper The Short_Link_Helper.
* @param Notification_Helper $notification_helper The Notification_Helper.
* @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action.
* @param Promotion_Manager $promotion_manager The promotion manager.
* @param Content_Types_Repository $content_types_repository The content types repository.
* @param WPSEO_Admin_Asset_Manager $asset_manager The WPSEO_Admin_Asset_Manager.
* @param Current_Page_Helper $current_page_helper The Current_Page_Helper.
* @param Product_Helper $product_helper The Product_Helper.
* @param Short_Link_Helper $shortlink_helper The Short_Link_Helper.
* @param Notification_Helper $notification_helper The Notification_Helper.
* @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action.
* @param Promotion_Manager $promotion_manager The promotion manager.
* @param Dashboard_Configuration $dashboard_configuration The dashboard configuration.
*/
public function __construct(
WPSEO_Admin_Asset_Manager $asset_manager,
Expand All @@ -100,16 +100,16 @@ public function __construct(
Notification_Helper $notification_helper,
Alert_Dismissal_Action $alert_dismissal_action,
Promotion_Manager $promotion_manager,
Content_Types_Repository $content_types_repository
Dashboard_Configuration $dashboard_configuration
) {
$this->asset_manager = $asset_manager;
$this->current_page_helper = $current_page_helper;
$this->product_helper = $product_helper;
$this->shortlink_helper = $shortlink_helper;
$this->notification_helper = $notification_helper;
$this->alert_dismissal_action = $alert_dismissal_action;
$this->promotion_manager = $promotion_manager;
$this->content_types_repository = $content_types_repository;
$this->asset_manager = $asset_manager;
$this->current_page_helper = $current_page_helper;
$this->product_helper = $product_helper;
$this->shortlink_helper = $shortlink_helper;
$this->notification_helper = $notification_helper;
$this->alert_dismissal_action = $alert_dismissal_action;
$this->promotion_manager = $promotion_manager;
$this->dashboard_configuration = $dashboard_configuration;
}

/**
Expand Down Expand Up @@ -213,7 +213,7 @@ private function get_script_data() {
'alerts' => $this->notification_helper->get_alerts(),
'currentPromotions' => $this->promotion_manager->get_current_promotions(),
'dismissedAlerts' => $this->alert_dismissal_action->all_dismissed(),
'contentTypes' => $this->content_types_repository->get_content_types(),
'dashboard' => $this->dashboard_configuration->get_configuration(),
];
}
}
14 changes: 14 additions & 0 deletions src/helpers/user-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ public function get_current_user_id() {
return \get_current_user_id();
}

/**
* Returns the current users display_name.
*
* @return string
*/
public function get_current_user_display_name(): string {
$user = \wp_get_current_user();
if ( $user && $user->display_name ) {
return $user->display_name;
}

return '';
}

/**
* Updates user meta field for a user.
*
Expand Down
Loading

0 comments on commit c8821a7

Please sign in to comment.