Processes the interactivity directives contained within the HTML content and updates the markup accordingly.
Description
It needs the context and namespace stacks to be passed by reference, and it returns null if the HTML contains unbalanced tags.
Parameters
$htmlstringrequired- The HTML content to process.
$context_stackarrayrequired- The reference to the array used to keep track of contexts during processing.
$namespace_stackarrayrequired- The reference to the array used to manage namespaces during processing.
Source
$data['i18n']['loading'] = __( 'Loading page, please wait.' );
$data['i18n']['loaded'] = __( 'Page Loaded.' );
return $data;
}
/**
* Set client-side interactivity data.
*
* 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.
*
* @since 6.7.0
* @since 6.9.0 Serializes derived state props accessed during directive processing.
*
* @param array $data Data to filter.
* @return array Data for the Interactivity API script module.
*/
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;
}
/**
* Returns the latest value on the context stack with the passed namespace.
*
* When the namespace is omitted, it uses the current namespace on the
* namespace stack during a `process_directives` call.
*
* @since 6.6.0
*
* @param string $store_namespace Optional. The unique store namespace identifier.
*/
public function get_context( ?string $store_namespace = null ): array {
if ( null === $this->context_stack ) {
_doing_it_wrong(
__METHOD__,
__( 'The context can only be read during directive processing.' ),
'6.6.0'
);
return array();
}
if ( ! $store_namespace ) {
if ( null !== $store_namespace ) {
_doing_it_wrong(
__METHOD__,
__( 'The namespace should be a non-empty string.' ),
'6.6.0'
);
return array();
}
$store_namespace = end( $this->namespace_stack );
}
$context = end( $this->context_stack );
return ( $store_namespace && $context && isset( $context[ $store_namespace ] ) )
? $context[ $store_namespace ]
: array();
}
/**
* Returns an array representation of the current element being processed.
*
* The returned array contains a copy of the element attributes.
*
* @since 6.7.0
*
* @return array{attributes: array<string, string|bool>}|null Current element.
*/
public function get_element(): ?array {
if ( null === $this->current_element ) {
_doing_it_wrong(
__METHOD__,
Changelog
| Version | Description |
|---|---|
| 6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.