-
Notifications
You must be signed in to change notification settings - Fork 219
Create AssetsController and BlockTypesController (replaces Assets.php and Library.php) #4094
Conversation
Co-Authored-By: Bartosz Budzanowski <17271089+budzanowski@users.noreply.github.com>
Remove fix to load our stylesheets after editor CSS. See ...Remove fix to load our stylesheets after editor CSS. See #3068 and #3898 for the rationale of this fix. It should be no github.com/WordPress/gutenberg/issues/20797). https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b14625accbc66e08516a8608e38530da9007dfef/src/AssetsController.php#L87-L100🚀 This comment was generated by the automations bot based on a
|
* @param string|array $classes Array or string of CSS classnames. | ||
* @return string|array Modified classnames. | ||
*/ | ||
public function add_theme_body_class( $classes ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note I combined the 2 functions into one which handles $classes based on type instead of 2 functions for similar logic.
add_action( 'init', array( __CLASS__, 'register_blocks' ) ); | ||
add_action( 'init', array( __CLASS__, 'define_tables' ) ); | ||
protected function init() { | ||
add_action( 'init', array( $this, 'register_blocks' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, we don't need to define tables any more now that the stock table is in core.
* @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. | ||
*/ | ||
public function register_block_script( $script_name, $handle = '', $dependencies = [] ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note; I removed these as they have been deprecated for several versions and are not being used internally.
Size Change: +2.5 kB (0%) Total Size: 1.15 MB
ℹ️ View Unchanged
|
Just a quick note that I think we should still leave the classes in place with any public method and add depecrated calls/comment blocks. Once this is deployed to WooCommerce core in one version with the deprecations, the next release of blocks after that could remove the classes altogether (which will land in the next WooCommerce core release). Some rationale here is that there are some deploy scenarios for WooCommerce core in some environments where fatals could be introduced so we have stagger actual class removal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code wise this looks good, thanks Mike!
I have a few items for you to look as inline comments that I'm interested in your take on. I also have this comment I made earlier that I think should be addressed.
@nerrad thanks, changes made. Just waiting on tests :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good, just a minor note about the unnecessary imports in the deprecated Library class.
Good to go after tests are 🟢 and you're happy with your own testing of this.
src/Library.php
Outdated
use Automattic\WooCommerce\Blocks\BlockTypes\AtomicBlock; | ||
use Automattic\WooCommerce\Blocks\Package; | ||
use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry; | ||
use Automattic\WooCommerce\Blocks\Assets\Api as AssetApi; | ||
use Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably don't need all these imports now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore this, it was an artifact of the commits I was viewing and how the changes were being shown, I see they don't actually exist in the file.
Refactors Assets and Library with dependency injection. Closes #3875 and fixes #3868
I've marked this as in need of a dev note since we're removing classes, however, they are internal so unlikely to be used directly. cc @nerrad
Will add inline notes for other changes.
How to test the changes in this Pull Request:
General smoke test to ensure classes are still loaded. Check all block types are registered and existing blocks load within admin and frontend.
Dev Note
Changelog