You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If an array value is empty toPlaceholders function does not clear the value in placeholder and leaves the previous value.
Step to reproduce
here is the result:
here is my code for the reproducing issue: $item = $object->toArray(); echo "<pre>Object Data: {$item['ends_at']} <br>"; $modx->toPlaceholders( $object, 'subscription'); echo "placeholder: {$modx->getPlaceholder( 'subscription.ends_at' )}</pre>";
Expected behavior
the function should clear the placeholder if the value is NULL or empty.
$modx->toPlaceholders() isn't scoped to any particular row or item, so that's going to remember a previous value if you don't set a new one.
Can you use var_dump() to confirm that $item['ends_at'] is a literal null? Looking at the code, it should still overwrite the previous value if it is provided an empty string '', but null isn't a scalar value so is indeed ignored.
Alternatively, consider rewriting your code to use $modx->getChunk($tpl, $item). That does scope placeholders to only be processed within that specific chunk.
Hi Mark!
Thank you for the answer.
Indeed the ["ends_at"]=>NULL . I get these values from the database.
So is there no way to add checking null value in the toPlaceholders function? Just creating my own checking of values?
I've resolved this issue by adding the following code before toPlaceholders, but maybe it will be useful to add this checking to the function to avoid unexpected results.
Bug report
Summary
If an array value is empty toPlaceholders function does not clear the value in placeholder and leaves the previous value.
Step to reproduce
here is the result:
here is my code for the reproducing issue:
$item = $object->toArray(); echo "<pre>Object Data: {$item['ends_at']} <br>"; $modx->toPlaceholders( $object, 'subscription'); echo "placeholder: {$modx->getPlaceholder( 'subscription.ends_at' )}</pre>";
Expected behavior
the function should clear the placeholder if the value is NULL or empty.
Environment
MODX Revolution 3.0.1-pl (traditional)
PHP Version 8.0.25
Ubuntu FPM/FastCGI
paas2.fra.modxcloud.com
10.3.34-MariaDB-0ubuntu0.20.04.1
The text was updated successfully, but these errors were encountered: