Make WordPress Core


Ignore:
Timestamp:
07/29/2024 11:08:18 AM (6 months ago)
Author:
luisherranz
Message:

Interactivity API: Allow server derived state to appear in non-final position

In some cases, derived state returns an associative array. Directives may wish to continue to access properties of the associative array, when using the syntax state.arrayReturnedByClosure.property. This patch continues evaluating the path after the associative array has been returned by the Closure.

Props jonsurrell, luisherranz.

Fixes #61741.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php

    r58729 r58825  
    12981298    }
    12991299
    1300 
    13011300    /**
    13021301     * Tests the `evaluate` method for derived state functions that throw.
     
    13211320        $result = $this->evaluate( 'state.derivedThatThrows' );
    13221321        $this->assertNull( $result );
     1322    }
     1323
     1324    /**
     1325     * Tests the `evaluate` method for derived state intermediate values.
     1326     *
     1327     * @ticket 61741
     1328     *
     1329     * @covers ::evaluate
     1330     */
     1331    public function test_evaluate_derived_state_intermediate() {
     1332        $this->interactivity->state(
     1333            'myPlugin',
     1334            array(
     1335                'derivedState' => function () {
     1336                    return array( 'property' => 'value' );
     1337                },
     1338            )
     1339        );
     1340        $this->set_internal_context_stack();
     1341        $this->set_internal_namespace_stack( 'myPlugin' );
     1342
     1343        $result = $this->evaluate( 'state.derivedState.property' );
     1344        $this->assertSame( 'value', $result );
    13231345    }
    13241346
Note: See TracChangeset for help on using the changeset viewer.