Make WordPress Core

Changeset 63434


Ignore:
Timestamp:
09/02/2026 02:32:15 PM (less than one hour ago)
Author:
oandregal
Message:

View Config: set summary fields.

Props oandregal, ntsekouras, jorgefilipecosta, gigitux.
Part of #65981.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/view-config.php

    r63355 r63434  
    7777                                'id'       => 'status',
    7878                                'label'    => __( 'Status' ),
     79                                'layout'   => array(
     80                                        'type'    => 'panel',
     81                                        'summary' => 'status',
     82                                ),
    7983                                'children' => array(
    8084                                        array(
     
    97101                                'id'       => 'discussion',
    98102                                'label'    => __( 'Discussion' ),
     103                                'layout'   => array(
     104                                        'type'    => 'panel',
     105                                        'summary' => 'discussion',
     106                                ),
    99107                                'children' => array(
    100108                                        array(
  • trunk/tests/phpunit/tests/view-config.php

    r62970 r63434  
    7676
    7777        /**
     78         * Returns the form field with the given id from a view configuration.
     79         *
     80         * @param array  $config The view configuration.
     81         * @param string $id     The form field id.
     82         * @return array|null The form field, or null when absent.
     83         */
     84        private function get_form_field( $config, $id ) {
     85                foreach ( $config['form']['fields'] as $field ) {
     86                        if ( is_array( $field ) && isset( $field['id'] ) && $id === $field['id'] ) {
     87                                return $field;
     88                        }
     89                }
     90                return null;
     91        }
     92
     93        /**
     94         * The `status` and `discussion` groups of the default post type form declare
     95         * their panel summary explicitly, for built-in and custom post types alike.
     96         *
     97         * @ticket 65981
     98         *
     99         * @dataProvider data_default_form_post_types
     100         *
     101         * @param string $post_type The post type.
     102         */
     103        public function test_default_form_groups_declare_summary( $post_type ) {
     104                if ( ! post_type_exists( $post_type ) ) {
     105                        register_post_type( $post_type );
     106                }
     107
     108                $config = wp_get_entity_view_config( 'postType', $post_type );
     109
     110                foreach ( array( 'status', 'discussion' ) as $group ) {
     111                        $field = $this->get_form_field( $config, $group );
     112                        $this->assertNotNull( $field, "The `{$group}` group is present." );
     113                        $this->assertNotEmpty( $field['children'], "The `{$group}` group keeps its children." );
     114                        $this->assertSame(
     115                                array(
     116                                        'type'    => 'panel',
     117                                        'summary' => $group,
     118                                ),
     119                                $field['layout'],
     120                                "The `{$group}` group summary is explicit."
     121                        );
     122                }
     123
     124                if ( 'page' !== $post_type && 'post' !== $post_type ) {
     125                        unregister_post_type( $post_type );
     126                }
     127        }
     128
     129        /**
     130         * Data provider.
     131         *
     132         * @return array[]
     133         */
     134        public function data_default_form_post_types() {
     135                return array(
     136                        'page'             => array( 'page' ),
     137                        'post'             => array( 'post' ),
     138                        'custom post type' => array( 'summaries_cpt' ),
     139                );
     140        }
     141
     142        /**
    78143         * The default configuration exposes the documented shape for an unknown entity.
    79144         */
Note: See TracChangeset for help on using the changeset viewer.