Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Simplify inline module data handling. #11120

Description

@techanvil

Simplify inline module data handling.

Feature Description

As suggested by @aaemnnosttv on Slack, we should follow up on the work started in #10988 and simplify the implementation.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The Module_With_Inline_Data_Trait trait should be removed, while keeping the Module_With_Inline_Data interface.
  • The Modules::inline_modules_data() method should be updated to iterate over modules that implement the interface and collect their data.
  • Modules should return unkeyed data arrays from get_inline_data, with slug-based keying handled by the Modules class.

Implementation Brief

  • Remove the Module_With_Inline_Data_Trait trait from the following modules:
    • Ads.php
    • Analytics_4.php
    • Sign_In_With_Google.php
  • Update the get_inline_data() method in those classes to return the inline data directly, without keying it by the module slug.

For example, change this:

return array(
    self::MODULE_SLUG => $data,
);

to this:

return $data;
  • Update the inline_modules_data method in Modules.php to populate the inline data from modules that implement the Module_With_Inline_Data interface. Each module's inline data should be added to $modules_data, using the module's slug ($module::MODULE_SLUG) as the key and the data returned by $module->get_inline_data() as the value.
  • Delete the Module_With_Inline_Data_Trait.php file.

Test Coverage

  • Update the inline data related tests of the affected modules (Analytics_4Test.php, AdsTest.php, Sign_In_With_GoogleTest.php) to use the get_inline_data method directly instead of relying on the googlesitekit_inline_modules_data hook.
  • Add new tests to ModulesTest.php to cover the inline_modules_data method and verify that it correctly adds the inline_module_data of classes that implement the Module_With_Inline_Data interface

QA Brief

Note: I copied these steps from #10988, as the main check here is also just to ensure none of the data went missing.

  • Set up Site Kit with Analytics and Ads enabled.
  • Go to the Site Kit page.
  • Type _googlesitekitModulesData in the console.
    • The object should have an ads key, whose value is an object containing:
      • supportedConversionEvents: an array of supported conversion events.
        • As a sanity check, install WooCommerce. This array should contain WooCommerce-related events (add-to-cart, purchase).
    • The object should have an analytics-4 key, whose value is an object containing:
      • customDimensionsDataAvailable
      • isWebDataStreamUnavailable
      • resourceAvailabilityDates
      • tagIDMismatch
      • newEvents
      • lostEvents
      • newBadgeEvents
    • Without setting up Sign In With Google, the object should not have sign-in-with-google.
    • After setting up Sign In With Google, the object should have the sign-in-with-google key, whose value is an object containing:
      • isWooCommerceActive
      • isWooCommerceRegistrationEnabled

Changelog entry

  • Simplify inline module data handling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueGood first issue for new engineersP2Low priorityPHPTeam MIssues for Squad 2Type: EnhancementImprovement of an existing feature

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions