function RulesDebugLog::filterContext

Removes invalid placeholders from the given array.

As of Drupal 10, arrays that contain placeholder replacement strings for use by the core Drupal t() function may not contain any keys that aren't valid placeholders for the string being translated. That means we have to remove keys from these arrays before passing them to the t() function.

Parameters

array $context: An array containing placeholder replacements for use by t(), keyed by the placeholder.

Return value

array The context array, with invalid placeholders removed.

See also

\Drupal\Component\Render\FormattableMarkup::placeholderFormat()

2 calls to RulesDebugLog::filterContext()
RulesDebugLog::build in src/Logger/RulesDebugLog.php
Assembles the entire log into a render array.
RulesDebugLog::renderHelper in src/Logger/RulesDebugLog.php
Renders the log of one event invocation.

File

src/Logger/RulesDebugLog.php, line 256

Class

RulesDebugLog
Logger that stores Rules debug logs with the session service.

Namespace

Drupal\rules\Logger

Code

protected function filterContext(array $context = []) : array {
    // This implementation assumes that all valid placeholders start with a
    // punctuation character. In reality Drupal currently supports only '@',
    // '%', and ':', but testing for just those three is considerably slower
    // than using the built-in PHP ctype_punct() function. This will work to
    // remove all invalid placeholders added by the Rules module, but another
    // invalid placeholder added by a user might fall through and still cause
    // an error (as it should, to indicate the user has made an error).
    return array_filter($context, function ($key) {
        return ctype_punct($key[0]);
    }, ARRAY_FILTER_USE_KEY);
}