Commit e85462dd authored by catch's avatar catch
Browse files

Issue #2807743 by alexpott, catch, kiamlaluno, neclimdul, xjm: Switch from...

Issue #2807743 by alexpott, catch, kiamlaluno, neclimdul, xjm: Switch from deprecation notice to warning for non-standard placeholders in FormattableMarkup::placeholderFormat()
parent 65e52585
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -149,6 +149,10 @@ function error_displayable($error = NULL) {
function _drupal_log_error($error, $fatal = FALSE) {
  $is_installer = InstallerKernel::installationAttempted();

  // Remove 'severity_level' as is not a valid replacement for t().
  $severity = $error['severity_level'];
  unset($error['severity_level']);

  // Backtrace array is not a valid replacement value for t().
  $backtrace = $error['backtrace'];
  unset($error['backtrace']);
@@ -166,8 +170,10 @@ function _drupal_log_error($error, $fatal = FALSE) {
  // installer.
  if (\Drupal::hasService('logger.factory')) {
    try {
      // Provide the PHP backtrace to logger implementations.
      \Drupal::logger('php')->log($error['severity_level'], '%type: @message in %function (line %line of %file) @backtrace_string.', $error + ['backtrace' => $backtrace]);
      // Provide the PHP backtrace to logger implementations. Add
      // 'severity_level' to the context to maintain BC and allow logging
      // implementations to use it.
      \Drupal::logger('php')->log($severity, '%type: @message in %function (line %line of %file) @backtrace_string.', $error + ['backtrace' => $backtrace, 'severity_level' => $severity]);
    }
    catch (\Exception $e) {
      // We can't log, for example because the database connection is not
+1 −0
Original line number Diff line number Diff line
@@ -232,6 +232,7 @@ function update_do_one($module, $number, $dependency_map, &$context) {

      $variables = Error::decodeException($e);
      unset($variables['backtrace']);
      unset($variables['severity_level']);
      $ret['#abort'] = ['success' => FALSE, 'query' => t('%type: @message in %function (line %line of %file).', $variables)];
    }
  }
+5 −10
Original line number Diff line number Diff line
@@ -231,17 +231,12 @@ protected static function placeholderFormat($string, array $args) {
          break;

        default:
          // We do not trigger an error for placeholder that start with an
          // alphabetic character.
          // @todo https://www.drupal.org/node/2807743 Change to an exception
          //   and always throw regardless of the first character.
          if (!ctype_alpha($key[0])) {
            // We trigger an error as we may want to introduce new placeholders
            // in the future without breaking backward compatibility.
            trigger_error('Invalid placeholder (' . $key . ') in string: ' . $string, E_USER_ERROR);
          // Deprecate support for random variables that won't be replaced.
          if (ctype_alpha($key[0]) && strpos($string, $key) === FALSE) {
            @trigger_error(sprintf('Support for keys without a placeholder prefix is deprecated in Drupal 9.1.0 and will be removed in Drupal 10.0.0. Invalid placeholder (%s) with string: "%s"', $key, $string), E_USER_DEPRECATED);
          }
          elseif (strpos($string, $key) !== FALSE) {
            trigger_error('Invalid placeholder (' . $key . ') in string: ' . $string, E_USER_DEPRECATED);
          else {
            trigger_error(sprintf('Invalid placeholder (%s) with string: "%s"', $key, $string), E_USER_WARNING);
          }
          // No replacement possible therefore we can discard the argument.
          unset($args[$key]);
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public function onException(ExceptionEvent $event) {
      $error = $this->simplifyFileInError($error);

      unset($error['backtrace']);
      unset($error['severity_level']);

      if (!$this->isErrorLevelVerbose()) {
        // Without verbose logging, use a simple message.
+3 −1
Original line number Diff line number Diff line
@@ -63,7 +63,9 @@ public function testMessages() {
      if (!isset($entry['variables'])) {
        continue;
      }
      $this->assertEqual($view->style_plugin->getField($index, 'message'), new FormattableMarkup($entry['message'], $entry['variables']));
      $message_vars = $entry['variables'];
      unset($message_vars['link']);
      $this->assertEqual($view->style_plugin->getField($index, 'message'), new FormattableMarkup($entry['message'], $message_vars));
      $link_field = $view->style_plugin->getField($index, 'link');
      // The 3rd entry contains some unsafe markup that needs to get filtered.
      if ($index == 2) {
Loading