Problem/Motivation
When attempting to log a spam form submission, the form_id is missing from the message and the error "Warning: htmlspecialchars() expects parameter 1 to be string, array given in Drupal\Component\Utility\Html::escape() (line 424 of C:\wamp64\www\d8\web\core\lib\Drupal\Component\Utility\Html.php)" is generated.
Steps to reproduce
Enable logging. Use a browser tool to display the feed_me input element, add data to it, and submit it. Observe that the logged message is missing the form_id and the addition
Proposed resolution
In spamicide.module, spamicide_validate calls:
\Drupal::logger('spamicide')->notice(
t('%form_id post blocked by Spamicide module: their IP address is "%ipaddress".',
[
'%form_id' => $form['form_id'],
'%ipaddress' => Drupal::request()->getClientIp(),
])
);
$form['form_id'] is a form element. What is intended is $form['#form_id'] which is the string of the form id.
Furthermore, this isn't how messages should be logged. They should not be translated and the placeholders should be passed. The correct call should be (untested):
\Drupal::logger('spamicide')->notice(
'%form_id post blocked by Spamicide module: their IP address is "%ipaddress".',
[
'%form_id' => $form['#form_id'],
'%ipaddress' => Drupal::request()->getClientIp(),
]
);
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | spamicide-logger-3210110-1.patch | 1.07 KB | danchadwick |
Issue fork spamicide-3210110
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
danchadwick commentedHere's a patch. Still getting comfortable with the merge request workflow.
Comment #3
lamp5I can see that you removed t() function from your fix.
Comment #4
danchadwick commentedCorrect. Logger messages, including notice() should not be translated. Search core for 'notice(' and you'll see what I mean.
Comment #6
lamp5