You are here

protected function UserFieldsEventSubscriber::getLoggableParameters in SAML Authentication 8.3

Same name and namespace in other branches
  1. 4.x modules/samlauth_user_fields/src/EventSubscriber/UserFieldsEventSubscriber.php \Drupal\samlauth_user_fields\EventSubscriber\UserFieldsEventSubscriber::getLoggableParameters()

Extracts proper message + arguments from a violation.

Parameters

\Symfony\Component\Validator\ConstraintViolation $violation: A violation object containing a message.

Return value

array Two-element array: message + context. The message is suitable for 'consumption' by a logger - specifically, Drupal's watchdog logger which wants an untranslated string + context passed.

1 call to UserFieldsEventSubscriber::getLoggableParameters()
UserFieldsEventSubscriber::validateAccountFieldValue in modules/samlauth_user_fields/src/EventSubscriber/UserFieldsEventSubscriber.php
Validates a value as being valid to set into a certain user account field.

File

modules/samlauth_user_fields/src/EventSubscriber/UserFieldsEventSubscriber.php, line 512

Class

UserFieldsEventSubscriber
Synchronizes SAML attributes into user fields / links new users during login.

Namespace

Drupal\samlauth_user_fields\EventSubscriber

Code

protected function getLoggableParameters(ConstraintViolation $violation) {
  $message = $violation
    ->getMessage();
  if ($message instanceof TranslatableMarkup && !$message instanceof PluralTranslatableMarkup) {
    return [
      $message
        ->getUntranslatedString(),
      $message
        ->getArguments(),
    ];
  }

  // If this is some other kind of object, it might be
  // - A PluralTranslatableMarkup object. We can't get to the 'count'
  //   parameter, which is important to know which message (for which
  //   plurality) to extract from the message template, which contains
  //   multiple messages. (Which we'd need to do with code copied from
  //   render() - if we had the count.) Even then, this would harm
  //   translatability - because translation systems usually translate the
  //   full message at once.
  // - A FormattableMarkup object. Unfortunately this has no way to get to
  //   the separate message and arguments.
  // - Some other object, whose message + context are likely still PSR-3
  //   style; if we knew how to get to the separate arguments, we'd still
  //   need to pass them through LogMessageParser::parseMessagePlaceholders.
  // The only thing we know / can assume is, it's convertable to a simple
  // string, so we'll just log the string (which will unfortunately be
  // translated already / have its context substituted already).
  return [
    (string) $message,
    [],
  ];
}