Make WordPress Core


Ignore:
Timestamp:
12/13/2018 08:22:06 PM (6 years ago)
Author:
desrosj
Message:

Block Editor: Add helper functions for displaying the editor.

use_block_editor_for_post() and use_block_editor_for_post_type() determine if the block editor should be loaded.

get_block_categories() and get_block_editor_server_block_settings() provide data be included while the block editor is loading.

Props pento.

Merges [43762] to trunk.

See #45110.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tests/phpunit/tests/admin/includesPost.php

    r43571 r44122  
    751751    }
    752752
     753    function test_use_block_editor_for_post() {
     754        $this->assertFalse( use_block_editor_for_post( -1 ) );
     755        $bogus_post_id = $this->factory()->post->create(
     756            array(
     757                'post_type' => 'bogus',
     758            )
     759        );
     760        $this->assertFalse( use_block_editor_for_post( $bogus_post_id ) );
     761
     762        register_post_type(
     763            'restless',
     764            array(
     765                'show_in_rest' => false,
     766            )
     767        );
     768        $restless_post_id = $this->factory()->post->create(
     769            array(
     770                'post_type' => 'restless',
     771            )
     772        );
     773        $this->assertFalse( use_block_editor_for_post( $restless_post_id ) );
     774
     775        $generic_post_id = $this->factory()->post->create();
     776
     777        add_filter( 'use_block_editor_for_post', '__return_false' );
     778        $this->assertFalse( use_block_editor_for_post( $generic_post_id ) );
     779        remove_filter( 'use_block_editor_for_post', '__return_false' );
     780
     781        add_filter( 'use_block_editor_for_post', '__return_true' );
     782        $this->assertTrue( use_block_editor_for_post( $restless_post_id ) );
     783        remove_filter( 'use_block_editor_for_post', '__return_true' );
     784    }
     785
     786    function test_get_block_editor_server_block_settings() {
     787        $name     = 'core/test';
     788        $settings = array(
     789            'icon'            => 'text',
     790            'render_callback' => 'foo',
     791        );
     792
     793        register_block_type( $name, $settings );
     794
     795        $blocks = get_block_editor_server_block_settings();
     796
     797        unregister_block_type( $name );
     798
     799        $this->assertArrayHasKey( $name, $blocks );
     800        $this->assertSame( array( 'icon' => 'text' ), $blocks[ $name ] );
     801    }
    753802}
Note: See TracChangeset for help on using the changeset viewer.