You are here

private function SwiftMailer::getApplicableFormat in Swift Mailer 8

Returns the applicable format.

Parameters

array $message: The message for which the applicable format is to be determined.

Return value

string A string being the applicable format.

3 calls to SwiftMailer::getApplicableFormat()
SwiftMailer::format in src/Plugin/Mail/SwiftMailer.php
Formats a message composed by drupal_mail().
SwiftMailer::mail in src/Plugin/Mail/SwiftMailer.php
Sends a message composed by drupal_mail().
SwiftMailer::massageMessageBody in src/Plugin/Mail/SwiftMailer.php
Massages the message body into the format expected for rendering.

File

src/Plugin/Mail/SwiftMailer.php, line 456

Class

SwiftMailer
Provides a 'Swift Mailer' plugin to send emails.

Namespace

Drupal\swiftmailer\Plugin\Mail

Code

private function getApplicableFormat($message) {

  // Get the configured default format.
  $default_format = $this->config['message']['format'];

  // Get whether the provided format is to be respected.
  $respect_format = $this->config['message']['respect_format'];

  // Check if a format has been provided particularly for this message. If
  // that is the case, then apply that format instead of the default format.
  $applicable_format = !empty($message['params']['format']) ? $message['params']['format'] : $default_format;

  // Check if the provided format is to be respected, and if a format has been
  // set through the header "Content-Type". If that is the case, the apply the
  // format provided. This will override any format which may have been set
  // through $message['params']['format'].
  if ($respect_format && !empty($message['headers']['Content-Type'])) {
    $format = $message['headers']['Content-Type'];
    if (preg_match('/.*\\;/U', $format, $matches)) {
      $applicable_format = trim(substr($matches[0], 0, -1));
    }
    else {
      $applicable_format = $message['headers']['Content-Type'];
    }
  }
  return $applicable_format;
}