reaterThanOrEqual', 'before', 'after', ), ), 'value' => array(), 'isLocked' => array( 'type' => 'boolean', ), ), ), ), 'sort' => array( 'type' => 'object', 'properties' => array( 'field' => array( 'type' => 'string', ), 'direction' => array( 'type' => 'string', 'enum' => array( 'asc', 'desc' ), ), ), ), 'perPage' => array( 'type' => 'integer', ), 'fields' => array( 'type' => 'array', 'items' => array( 'type' => 'string', ), ), 'titleField' => array( 'type' => 'string', ), 'mediaField' => array( 'type' => 'string', ), 'descriptionField' => array( 'type' => 'string', ), 'showTitle' => array( 'type' => 'boolean', ), 'showMedia' => array( 'type' => 'boolean', ), 'showDescription' => array( 'type' => 'boolean', ), 'showLevels' => array( 'type' => 'boolean', ), 'groupBy' => array( 'type' => 'object', 'properties' => array( 'field' => array( 'type' => 'string', ), 'direction' => array( 'type' => 'string', 'enum' => array( 'asc', 'desc' ), ), 'showLabel' => array( 'type' => 'boolean', 'default' => true, ), ), ), 'infiniteScrollEnabled' => array( 'type' => 'boolean', ), ); } /** * Returns the schema for the ColumnStyle type. * * @since 7.1.0 * * @return array Schema for a column style object. */ protected function get_column_style_schema() { return array( 'type' => 'object', 'properties' => array( 'width' => array( 'type' => array( 'string', 'number' ), ), 'maxWidth' => array( 'type' => array( 'string', 'number' ), ), 'minWidth' => array( 'type' => array( 'string', 'number' ), ), 'align' => array( 'type' => 'string', 'enum' => array( 'start', 'center', 'end' ), ), ), ); } /** * Returns the layout schema for table-type views (ViewTable, ViewPickerTable). * * @since 7.1.0 * * @return array Schema for a table layout object. */ protected function get_table_layout_schema() { return array( 'type' => 'object', 'properties' => array( 'styles' => array( 'type' => 'object', 'additionalProperties' => $this->get_column_style_schema(), ), 'density' => array( 'type' => 'string', 'enum' => array( 'compact', 'balanced', 'comfortable' ), ), 'enableMoving' => array( 'type' => 'boolean', ), ), ); } /** * Returns the layout schema for list-type views (ViewList, ViewActivity). * * @since 7.1.0 * * @return array Schema for a list layout object. */ protected function get_list_layout_schema() { return array( 'type' => 'object', 'properties' => array( 'density' => array( 'type' => 'string', 'enum' => array( 'compact', 'balanced', 'comfortable' ), ), ), ); } /** * Returns a combined layout schema that accepts properties from all view types. * * This is useful for contexts where the view type is not known ahead of time * (e.g. the `view` override in a view list item), so all possible layout * properties must be accepted. * * @since 7.1.0 * * @return array Schema for a combined layout object. */ protected function get_combined_layout_schema() { return array( 'type' => 'object', 'properties' => array_merge( $this->get_table_layout_schema()['properties'], $this->get_grid_layout_schema()['properties'], $this->get_list_layout_schema()['properties'] ), ); } /** * Returns the layout schema for grid-type views (ViewGrid, ViewPickerGrid). * * @since 7.1.0 * * @return array Schema for a grid layout object. */ protected function get_grid_layout_schema() { return array( 'type' => 'object', 'properties' => array( 'badgeFields' => array( 'type' => 'array', 'items' => array( 'type' => 'string', ), ), 'previewSize' => array( 'type' => 'number', ), 'density' => array( 'type' => 'string', 'enum' => array( 'compact', 'balanced', 'comfortable' ), ), ), ); } /** * Returns the schema for a form layout object as a discriminated union. * * Each variant is discriminated by a single-value enum on its `type` property, * matching the TypeScript Layout union in dataviews/src/types/dataform.ts. * * @since 7.1.0 * * @return array Schema for a form layout object. */ 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', ), ), ), ), ); } /** * Returns the schema for a form field item (string or object). * * @since 7.1.0 * * @return array Schema for a form field. */ protected function get_form_field_schema() { return array( 'oneOf' => array( array( 'type' => 'string' ), array( 'type' => 'object', 'properties' => array( 'id' => array( 'type' => 'string', ), 'label' => array( 'type' => 'string', ), 'description' => array( 'type' => 'string', ), 'layout' => $this->get_form_layout_schema(), 'children' => array( 'type' => 'array', 'items' => array( 'oneOf' => array( array( 'type' => 'string' ), // This object can have the shape of a form field itself, // allowing for recursive nesting of form fields. // There's no easy way to codify this recursion via the JSON Schema draft-04 // supported by the REST API. array( 'type' => 'object' ), ), ), ), ), ), ), ); } /** * Returns the schema for the form configuration object. * * @since 7.1.0 * * @return array Schema properties for the form configuration. */ protected function get_form_schema() { return array( 'layout' => $this->get_form_layout_schema(), 'fields' => array( 'type' => 'array', 'items' => $this->get_form_field_schema(), ), ); } }