[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> class-wp-view-config-data.php (summary)

WP_View_Config_Data class

File Size: 625 lines (20 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_View_Config_Data:: (14 methods):
  __construct()
  get_config()
  set()
  update_properties()
  update_view_list_items()
  update_form_fields()
  check_version()
  extract_form_properties()
  deep_merge()
  merge_fields_by_identity()
  merge_field_in_tree()
  merge_field_item()
  reject_fields()
  field_identity()


Class: WP_View_Config_Data  - X-Ref

Holds an entity's view configuration while it is being built.

An instance of this class is what `get_entity_view_config_{$kind}_{$name}`
filter callbacks receive: a callback changes the configuration by calling
methods on the instance and returning it. The configuration has four
top-level keys — `default_view`, `default_layouts`, `view_list`, and
`form` — and there are two ways to contribute:

- The `update_*()` methods merge partial changes (patches) into what is
already there, each covering one part of the configuration:
`update_properties()` for `default_view`, `default_layouts`, and the
`form` settings other than its `fields`; `update_view_list_items()` for
the `view_list` entries, keyed by view `slug`; and `update_form_fields()`
for the `form` fields, keyed by field `id`. This is what plugins should
use: patches compose with core's configuration and with other plugins'.
- `set()` replaces a whole top-level key. It shouldn't be the default
choice — a callback using it stops inheriting core's future changes to
that key — but it's useful for cases like a post type that doesn't
want the default form at all.

Patches follow three shared rules: an associative array merges key by
key, a numerically indexed array replaces the current value wholesale,
and `null` deletes what it names — deleting a whole top-level key resets
it to its default. Each patch and each `set()` value also declares the
configuration schema version it was written against (currently 1), so a
future WordPress release that changes the configuration shape can migrate
existing patches forward instead of breaking them.

__construct( array $config )   X-Ref
Constructor.

param: array $config The base configuration to contribute to.

get_config()   X-Ref
Returns the current configuration array.

return: array The configuration.

set( $key, $value, int $version )   X-Ref
Replaces a whole top-level key with a new value.

It shouldn't be the default choice — a callback using it stops
inheriting core's future changes to that key — but it's useful for
cases like a post type that doesn't want the default form at all.

A value that declares an unsupported schema version is rejected and
does not replace anything.

param: string $key     The configuration key to replace.
param: mixed  $value   The new value.
param: int    $version The schema version the value was authored against.
return: WP_View_Config_Data The instance, for chaining.

update_properties( array $patch, int $version )   X-Ref
Merges a partial configuration into `default_view`, `default_layouts`,
and the `form` settings other than its `fields`.

An associative array merges key by key, a numerically indexed array
replaces the current value wholesale, and `null` deletes the key it
names; deleting a whole top-level key (any documented key, including
`view_list`) resets it to its default.

The keyed collections have dedicated methods and are rejected here: a
non-null `view_list` value must go through `update_view_list_items()`,
and a `fields` key inside a `form` value must go through
`update_form_fields()`.

A patch that declares an unsupported schema version is rejected and
does not merge.

param: array $patch   The partial configuration to merge.
param: int   $version The schema version the patch was authored against.
return: WP_View_Config_Data The instance, for chaining.

update_view_list_items( array $items, int $version )   X-Ref
Adds, updates, or removes `view_list` entries, keyed by view `slug`.

Each patch key names the `slug` of the view it targets: a matching view
merges in place and keeps its position (following the shared rules —
e.g. the view's `filters`, being numerically indexed, replace
wholesale), an unknown slug appends a new view to the end, and `null`
removes the view. The patch key is the identity: a `slug` property
inside the value is ignored. A `null` for a slug that is not found is a
silent no-op — the view may have been removed by another callback or
simply not apply to this entity.

A patch that declares an unsupported schema version is rejected and
does not merge.

param: array $items   The view patches, keyed by slug.
param: int   $version The schema version the patch was authored against.
return: WP_View_Config_Data The instance, for chaining.

update_form_fields( array $fields, int $version )   X-Ref
Adds, updates, or removes `form` fields, keyed by field `id`.

Each patch key names the `id` of the field it targets, and the field is
found wherever it lives — at the top level or nested inside a group's
`children`. Fields are visited in document order and a group is checked
before its own children, so when an id appears at both levels the group
wins. A matching field merges in place, an unknown id appends a new field
to the end of the top-level fields, and `null` removes the field. The
patch key is the identity: an `id` property inside the value is ignored.
A `null` for an id that is not found is a silent no-op — the field may
have been removed by another callback or simply not apply to this
entity.

Inside a field patch, `children` follows the shared rules: an associative
array merges into the group's children by id (appending unknown ones), a
numerically indexed array replaces the children wholesale, and `null`
deletes the key.

A patch that declares an unsupported schema version is rejected and
does not merge.

param: array $fields  The field patches, keyed by field id.
param: int   $version The schema version the patch was authored against.
return: WP_View_Config_Data The instance, for chaining.

check_version( int $version, $method )   X-Ref
Validates a declared patch version, reporting misuse against the given
public method.

param: int    $version The declared version.
param: string $method  The public method the patch was passed to.
return: bool Whether the declared version is a supported schema version.

extract_form_properties( $value )   X-Ref
Validates a `form` patch value for update_properties() and strips the
`fields` key, which is managed by update_form_fields().

param: mixed $value The incoming `form` patch value.
return: array|null The form properties to merge, or null when the value

deep_merge( $current, $incoming )   X-Ref
Recursively merges two values.

Associative arrays (maps) merge key by key and a null patch value deletes
the key; lists and scalars are replaced wholesale by the incoming value,
since lists without a defined identity cannot be merged member by member.

param: mixed $current  The current value.
param: mixed $incoming The incoming value.
return: mixed The merged value.

merge_fields_by_identity( array $current, array $patches )   X-Ref
Merges a map of field patches into a field list by identity.

Shared by the top-level `form` fields and a group's `children`: a `null`
value removes the matching field (recursing into children), a map value
merges into the matching field wherever it lives, and an unknown id
appends a new field to the end of this list. A `null` for an id that is
not found is a silent no-op.

param: array $current The current list of fields.
param: array $patches The field patches, keyed by field id.
return: array The merged list of fields.

merge_field_in_tree( array $fields, $id, array $value )   X-Ref
Merges a field patch into the field carrying the given identity, wherever
it lives in the tree.

Fields are visited in document order and a group is checked before its
own children, so when an id appears at both levels the group wins.

param: array  $fields The list of fields to search.
param: string $id     The identity of the field to patch.
param: array  $value  The field patch.
return: array|null The updated list, or null when the id was not found.

merge_field_item( $existing, $id, array $value )   X-Ref
Merges a field patch into an existing field.

A bare string reference is promoted to an array so the overrides apply.
The `children` key follows the same rules — a map merges into the
group's children by id, a list replaces them wholesale, and `null`
deletes the key — and every other key merges via deep_merge().

param: array|string $existing The existing field.
param: string       $id       The field identity.
param: array        $value    The field patch.
return: array|string The merged field.

reject_fields( array $fields, array $ids )   X-Ref
Returns a field list with the fields matching the given identities removed,
recursing into group children.

param: array    $fields The list of fields.
param: string[] $ids    The identities of the fields to remove.
return: array The list with the matching fields removed.

field_identity( $field )   X-Ref
Resolves the identity of a form field.

A bare string is its own identity; an object is identified by its `id`.

param: mixed $field The field.
return: string|null The identity, or null if it cannot be resolved.



Generated : Thu Jul 9 08:20:14 2026 Cross-referenced by PHPXref