woocommerce/plugins/woocommerce-blocks/src/Assets.php

96 lines
2.8 KiB
PHP
Raw Normal View History

<?php
namespace Automattic\WooCommerce\Blocks;
use Automattic\WooCommerce\Blocks\Package;
use Automattic\WooCommerce\Blocks\Assets\Api as AssetApi;
/**
* Assets class.
*
* @deprecated 5.0.0 This class will be removed in a future release. This has been replaced by AssetsController.
* @internal
*/
class Assets {
/**
* Initialize class features on init.
Implement PHP DI container and refactor. Also implements new Asset data interface for extendable settings passed to js. (https://github.com/woocommerce/woocommerce-blocks/pull/956) * Add dependency injection container for blocks * Add new Pacakge and Bootstrap classes. - Bootstrap for bootstrapping the plugin. - Package will replace `src/Package` and added as a dependency for any classes needing package info. * Introduce AssetsDataRegistry for managing asset data * refactor existing classes to use new DIC and Asset Data Registry - this is the bare minimum needed to make this pull viable. - further refactors will be done in more atomic smaller pulls for easier review. * add new settings handling and export `@woocommerce/settings` as an alias to wc.wcSettings - the export is exposed php side on the `wc-settings` handle. * Remove unnecessary concatenation * Fix typos and improve doc blocks * fix php linting issue * Use better escaping function. * improve jsdoc spacing * improve test assertion * use fully qualified class names in bootstrap * improve comment block to account for dynamic version string replace on build * handle exceptions a bit differently * correct dependency reference in webpack config * remove blank lines * fix doc block comment alignment * Various doc/grammar/spacing fixes from code review. Co-Authored-By: Albert Juhé Lluveras <contact@albertjuhe.com> * improve naming, documentation and logic of filter callbacks While this is intended for sanitization/validation, the callback ultimately provides flexibility for filtering the value before returning or setting in state so `filter` is a better name for this.
2019-09-23 18:07:13 +00:00
*
* @since 2.5.0
* @deprecated 5.0.0
*/
public static function init() {
_deprecated_function( 'Assets::init', '5.0.0' );
}
/**
* Register block scripts & styles.
Implement PHP DI container and refactor. Also implements new Asset data interface for extendable settings passed to js. (https://github.com/woocommerce/woocommerce-blocks/pull/956) * Add dependency injection container for blocks * Add new Pacakge and Bootstrap classes. - Bootstrap for bootstrapping the plugin. - Package will replace `src/Package` and added as a dependency for any classes needing package info. * Introduce AssetsDataRegistry for managing asset data * refactor existing classes to use new DIC and Asset Data Registry - this is the bare minimum needed to make this pull viable. - further refactors will be done in more atomic smaller pulls for easier review. * add new settings handling and export `@woocommerce/settings` as an alias to wc.wcSettings - the export is exposed php side on the `wc-settings` handle. * Remove unnecessary concatenation * Fix typos and improve doc blocks * fix php linting issue * Use better escaping function. * improve jsdoc spacing * improve test assertion * use fully qualified class names in bootstrap * improve comment block to account for dynamic version string replace on build * handle exceptions a bit differently * correct dependency reference in webpack config * remove blank lines * fix doc block comment alignment * Various doc/grammar/spacing fixes from code review. Co-Authored-By: Albert Juhé Lluveras <contact@albertjuhe.com> * improve naming, documentation and logic of filter callbacks While this is intended for sanitization/validation, the callback ultimately provides flexibility for filtering the value before returning or setting in state so `filter` is a better name for this.
2019-09-23 18:07:13 +00:00
*
* @since 2.5.0
* @deprecated 5.0.0
*/
public static function register_assets() {
_deprecated_function( 'Assets::register_assets', '5.0.0' );
}
/**
* Register the vendors style file. We need to do it after the other files
* because we need to check if `wp-edit-post` has been enqueued.
*
* @deprecated 5.0.0
*/
public static function enqueue_scripts() {
_deprecated_function( 'Assets::enqueue_scripts', '5.0.0' );
}
/**
* Add body classes.
*
* @deprecated 5.0.0
* @param array $classes Array of CSS classnames.
* @return array Modified array of CSS classnames.
*/
public static function add_theme_body_class( $classes = [] ) {
_deprecated_function( 'Assets::add_theme_body_class', '5.0.0' );
return $classes;
}
/**
* Add theme class to admin body.
*
* @deprecated 5.0.0
* @param array $classes String with the CSS classnames.
* @return array Modified string of CSS classnames.
*/
public static function add_theme_admin_body_class( $classes = '' ) {
_deprecated_function( 'Assets::add_theme_admin_body_class', '5.0.0' );
return $classes;
}
/**
* Adds a redirect field to the login form so blocks can redirect users after login.
*
* @deprecated 5.0.0
*/
public static function redirect_to_field() {
_deprecated_function( 'Assets::redirect_to_field', '5.0.0' );
}
/**
* Queues a block script in the frontend.
*
* @since 2.3.0
* @since 2.6.0 Changed $name to $script_name and added $handle argument.
* @since 2.9.0 Made it so scripts are not loaded in admin pages.
* @deprecated 4.5.0 Block types register the scripts themselves.
*
Add Cart totals to Cart block (https://github.com/woocommerce/woocommerce-blocks/pull/1411) * Add Cart totals to Cart block * Accessibility improvements * Load vendors styles separately * Use same shipping placeholders for cart and checkout * Refactor how we import @wordpress/components styles so only panel styles are imported * Remove style-loader from vendors styles build process * Add htmlFor attribute to TotalsCouponCodeInput * Update totalItems shape to match API * Fix wrong total items shape using numbers instead of strings * Rename wc-blocks classes to wc-block * Remove unnecessary parseInt() * Add radix to parseInt() * Rename totalRows to totalRowsConfig * Move placeholder content out of the component * Use Card component for cart's sidebar (https://github.com/woocommerce/woocommerce-blocks/pull/1423) * Use Card component for cart's sidebar * Split RadioControl component * No need to use Label in RadioControlOption * Remove no longer valid @todo comment * Use 'checked' prop instead of 'selected' in RadioControlOption * Rename wc-blocks classes to wc-block * Rename wc-blocks classes to wc-block (II) * Make sure radio control ids are unique using withComponentId * Load PanelBody and PanelRow from last version of @wordpress/components * Create vendors-frontend.js file * Load wordpress-component instead of @wordpress/components from <Button> component * Only load 'withRestApiHydration' HOC * Make vendors-frontend a dependency of cart-frontend script * Revert "Only load 'withRestApiHydration' HOC" This reverts commit 9f9b9759a98047b26e7d8f04189ffe78c1d5bb06. * Fix fieldset background
2020-01-10 14:37:27 +00:00
* @param string $script_name Name of the script used to identify the file inside build folder.
* @param string $handle Optional. Provided if the handle should be different than the script name. `wc-` prefix automatically added.
* @param array $dependencies Optional. An array of registered script handles this script depends on. Default empty array.
*/
Add Cart totals to Cart block (https://github.com/woocommerce/woocommerce-blocks/pull/1411) * Add Cart totals to Cart block * Accessibility improvements * Load vendors styles separately * Use same shipping placeholders for cart and checkout * Refactor how we import @wordpress/components styles so only panel styles are imported * Remove style-loader from vendors styles build process * Add htmlFor attribute to TotalsCouponCodeInput * Update totalItems shape to match API * Fix wrong total items shape using numbers instead of strings * Rename wc-blocks classes to wc-block * Remove unnecessary parseInt() * Add radix to parseInt() * Rename totalRows to totalRowsConfig * Move placeholder content out of the component * Use Card component for cart's sidebar (https://github.com/woocommerce/woocommerce-blocks/pull/1423) * Use Card component for cart's sidebar * Split RadioControl component * No need to use Label in RadioControlOption * Remove no longer valid @todo comment * Use 'checked' prop instead of 'selected' in RadioControlOption * Rename wc-blocks classes to wc-block * Rename wc-blocks classes to wc-block (II) * Make sure radio control ids are unique using withComponentId * Load PanelBody and PanelRow from last version of @wordpress/components * Create vendors-frontend.js file * Load wordpress-component instead of @wordpress/components from <Button> component * Only load 'withRestApiHydration' HOC * Make vendors-frontend a dependency of cart-frontend script * Revert "Only load 'withRestApiHydration' HOC" This reverts commit 9f9b9759a98047b26e7d8f04189ffe78c1d5bb06. * Fix fieldset background
2020-01-10 14:37:27 +00:00
public static function register_block_script( $script_name, $handle = '', $dependencies = [] ) {
_deprecated_function( 'register_block_script', '4.5.0' );
$asset_api = Package::container()->get( AssetApi::class );
$asset_api->register_block_script( $script_name, $handle, $dependencies );
}
}