Skip to content

Commit

Permalink
Backports for 5.6 Beta 2 (#26442)
Browse files Browse the repository at this point in the history
* Fix drop zone indicators for non blocks (#25986)

* Remove isDraggingBlocks check

* Clean up drag and drop data if the user presses escape when dragging

* Add comment to ensure avoidance of dragend

* Switch to using dragend

* Fix archives block render function (#26309)

* Code block: preserve indentation on paste (#26347)

* Turn off autocomplete for token input. (#26427)

* Fix parent post selector: ensure initial value available, search performed, all results shown. (#26397)

Co-authored-by: Nik Tsekouras <[email protected]>

* [RNMobile] Fix CI issues during `npm ci` (#26455)

* Run mobile tests on master

* Debug CI

* Revert "Debug CI"

This reverts commit dec1ebe.

* Update react-native-screens ref, pin @react-navigation/native version

* Pin @react-navigation/core,router versions

* Fix composer test failures due to invalid lock (#26472)

* Fix gallery block undo issue (#26377)

* Mark change in attributes when gallery mounts as not persistant

* Fix typo

* Fix package lock changes

* Fix some Twenty Twenty One related e2e test failures (#26341)

* Account for unknown number of controls in block inspector

* Ensure selection is on-screen by using a group block instead of cover, which takes up less space on screen

* Fix typewriter test

* Use correct name for patterns test

* Revert change to .wp-env.json

* Fix multi-entity side editor saving test

* Remove blank line

* insert paragraph instead of tempalte part (#26371)

* Fix autosave e2e tests (#26416)

* Update how block to render is tracked (#26356)

Co-authored-by: Daniel Richards <[email protected]>
Co-authored-by: Riad Benguella <[email protected]>
Co-authored-by: Ella van Durpe <[email protected]>
Co-authored-by: Adam Silverstein <[email protected]>
Co-authored-by: Nik Tsekouras <[email protected]>
Co-authored-by: Ceyhun Ozugur <[email protected]>
Co-authored-by: Marcus Kazmierczak <[email protected]>
Co-authored-by: Addison Stavlo <[email protected]>
Co-authored-by: O André <[email protected]>
  • Loading branch information
10 people authored Oct 27, 2020
1 parent 68a2e6d commit 16b8b04
Show file tree
Hide file tree
Showing 29 changed files with 325 additions and 947 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rnmobile-android-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
paths-ignore:
- '**.md'
push:
branches: [master]
paths-ignore:
- '**.md'

jobs:
test:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/rnmobile-ios-runner.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: React Native E2E Tests (iOS)

on:
pull_request:
paths-ignore:
- '**.md'
push:
branches: [master]
paths-ignore:
- '**.md'

jobs:
test:
Expand Down
4 changes: 3 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"core": "WordPress/WordPress",
"plugins": [ "." ],
"plugins": [
"."
],
"env": {
"tests": {
"mappings": {
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"issues": "https://github.com/WordPress/gutenberg/issues"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.6",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"squizlabs/php_codesniffer": "^3.5",
"phpcompatibility/php-compatibility": "^9.3",
"wp-coding-standards/wpcs": "^2.2",
Expand All @@ -23,6 +23,6 @@
},
"scripts": {
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "phpcs --standard=phpcs.xml.dist"
"lint": "phpcs --standard=phpcs.xml.dist --runtime-set ignore_warnings_on_exit 1"
}
}
78 changes: 45 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 36 additions & 6 deletions lib/class-wp-block-supports.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class WP_Block_Supports {
*/
private $block_supports = array();

/**
* Tracks the current block to be rendered.
*
* @var array
*/
public static $block_to_render = null;

/**
* Container for the main instance of the class.
*
Expand Down Expand Up @@ -67,13 +74,12 @@ public function register( $block_support_name, $block_support_config ) {
* Generates an array of HTML attributes, such as classes, by applying to
* the given block all of the features that the block supports.
*
* @param array $parsed_block Block as parsed from content.
* @return array Array of HTML attributes.
*/
public function apply_block_supports( $parsed_block ) {
$block_attributes = $parsed_block['attrs'];
public function apply_block_supports() {
$block_attributes = self::$block_to_render['attrs'];
$block_type = WP_Block_Type_Registry::get_instance()->get_registered(
$parsed_block['blockName']
self::$block_to_render['blockName']
);

// If no render_callback, assume styles have been previously handled.
Expand Down Expand Up @@ -144,8 +150,7 @@ private function register_attributes() {
* @return string String of HTML classes.
*/
function get_block_wrapper_attributes( $extra_attributes = array() ) {
global $current_parsed_block;
$new_attributes = WP_Block_Supports::get_instance()->apply_block_supports( $current_parsed_block );
$new_attributes = WP_Block_Supports::get_instance()->apply_block_supports();

if ( empty( $new_attributes ) && empty( $extra_attributes ) ) {
return '';
Expand Down Expand Up @@ -191,4 +196,29 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) {
return implode( ' ', $normalized_attributes );
}

/**
* Callback hooked to the register_block_type_args filter.
*
* This hooks into block registration to wrap the render_callback
* of dynamic blocks with a closure that keeps track of the
* current block to be rendered.
*
* @param array $args Block attributes.
* @return array Block attributes.
*/
function wp_block_supports_track_block_to_render( $args ) {
if ( null !== $args['render_callback'] ) {
$block_render_callback = $args['render_callback'];
$args['render_callback'] = function( $attributes, $content, $block ) use ( $block_render_callback ) {
$parent_block = WP_Block_Supports::$block_to_render;
WP_Block_Supports::$block_to_render = $block->parsed_block;
$result = $block_render_callback( $attributes, $content, $block );
WP_Block_Supports::$block_to_render = $parent_block;
return $result;
};
}
return $args;
}

add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 );
add_filter( 'register_block_type_args', 'wp_block_supports_track_block_to_render' );
12 changes: 3 additions & 9 deletions lib/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ public function __get( $name ) {
*/
public function render( $options = array() ) {
global $post;
global $current_parsed_block;
$options = array_replace(
array(
'dynamic' => true,
Expand All @@ -217,14 +216,9 @@ public function render( $options = array() ) {
if ( ! $options['dynamic'] || empty( $this->block_type->skip_inner_blocks ) ) {
$index = 0;
foreach ( $this->inner_content as $chunk ) {
if ( is_string( $chunk ) ) {
$block_content .= $chunk;
} else {
$parent_parsed_block = $current_parsed_block;
$current_parsed_block = $this->inner_blocks[ $index ]->parsed_block;
$block_content .= $this->inner_blocks[ $index++ ]->render();
$current_parsed_block = $parent_parsed_block;
}
$block_content .= is_string( $chunk ) ?
$chunk :
$this->inner_blocks[ $index++ ]->render();
}
}

Expand Down
Loading

0 comments on commit 16b8b04

Please sign in to comment.