Set client-side interactivity data.
Description
Once in the browser, the state will be parsed and used to hydrate the client-side interactivity stores and the configuration will be available using a getConfig utility.
Parameters
$dataarrayrequired- Data to filter.
Source
public function filter_script_module_interactivity_data( array $data ): array {
if (
empty( $this->state_data ) &&
empty( $this->config_data ) &&
empty( $this->derived_state_closures )
) {
return $data;
}
$config = array();
foreach ( $this->config_data as $key => $value ) {
if ( ! empty( $value ) ) {
$config[ $key ] = $value;
}
}
if ( ! empty( $config ) ) {
$data['config'] = $config;
}
$state = array();
foreach ( $this->state_data as $key => $value ) {
if ( ! empty( $value ) ) {
$state[ $key ] = $value;
}
}
if ( ! empty( $state ) ) {
$data['state'] = $state;
}
$derived_props = array();
foreach ( $this->derived_state_closures as $key => $value ) {
if ( ! empty( $value ) ) {
$derived_props[ $key ] = $value;
}
}
if ( ! empty( $derived_props ) ) {
$data['derivedStateClosures'] = $derived_props;
}
return $data;
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.