WP_REST_View_Config_Controller::get_form_layout_schema(): array

In this article

Returns the schema for a form layout object as a discriminated union.

Description

Each variant is discriminated by a single-value enum on its type property, matching the TypeScript Layout union in dataviews/src/types/dataform.ts.

Return

array Schema for a form layout object.

Source

protected function get_form_layout_schema() {
	return array(
		'oneOf' => array(
			// RegularLayout.
			array(
				'type'       => 'object',
				'properties' => array(
					'type'          => array(
						'type' => 'string',
						'enum' => array( 'regular' ),
					),
					'labelPosition' => array(
						'type' => 'string',
						'enum' => array( 'top', 'side', 'none' ),
					),
				),
			),
			// PanelLayout.
			array(
				'type'       => 'object',
				'properties' => array(
					'type'           => array(
						'type' => 'string',
						'enum' => array( 'panel' ),
					),
					'labelPosition'  => array(
						'type' => 'string',
						'enum' => array( 'top', 'side', 'none' ),
					),
					'openAs'         => array(
						'oneOf' => array(
							array(
								'type' => 'string',
								'enum' => array( 'dropdown', 'modal' ),
							),
							array(
								'type'       => 'object',
								'properties' => array(
									'type'        => array(
										'type' => 'string',
										'enum' => array( 'dropdown', 'modal' ),
									),
									'applyLabel'  => array(
										'type' => 'string',
									),
									'cancelLabel' => array(
										'type' => 'string',
									),
								),
							),
						),
					),
					'summary'        => array(
						'oneOf' => array(
							array( 'type' => 'string' ),
							array(
								'type'  => 'array',
								'items' => array(
									'type' => 'string',
								),
							),
						),
					),
					'editVisibility' => array(
						'type' => 'string',
						'enum' => array( 'always', 'on-hover' ),
					),
				),
			),
			// CardLayout.
			array(
				'type'       => 'object',
				'properties' => array(
					'type'          => array(
						'type' => 'string',
						'enum' => array( 'card' ),
					),
					'withHeader'    => array(
						'type' => 'boolean',
					),
					'isOpened'      => array(
						'type' => 'boolean',
					),
					'isCollapsible' => array(
						'type' => 'boolean',
					),
					'summary'       => array(
						'oneOf' => array(
							array( 'type' => 'string' ),
							array(
								'type'  => 'array',
								'items' => array(
									'oneOf' => array(
										array( 'type' => 'string' ),
										array(
											'type' => 'object',
											'properties' => array(
												'id' => array(
													'type' => 'string',
												),
												'visibility' => array(
													'type' => 'string',
													'enum' => array( 'always', 'when-collapsed' ),
												),
											),
										),
									),
								),
							),
						),
					),
				),
			),
			// RowLayout.
			array(
				'type'       => 'object',
				'properties' => array(
					'type'      => array(
						'type' => 'string',
						'enum' => array( 'row' ),
					),
					'alignment' => array(
						'type' => 'string',
						'enum' => array( 'start', 'center', 'end' ),
					),
					'styles'    => array(
						'type'                 => 'object',
						'additionalProperties' => array(
							'type'       => 'object',
							'properties' => array(
								'flex' => array(
									'type' => array( 'string', 'number' ),
								),
							),
						),
					),
				),
			),
			// DetailsLayout.
			array(
				'type'       => 'object',
				'properties' => array(
					'type'    => array(
						'type' => 'string',
						'enum' => array( 'details' ),
					),
					'summary' => array(
						'type' => 'string',
					),
				),
			),
		),
	);
}

Changelog

VersionDescription
7.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.