summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php')
-rw-r--r--core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php7
1 files changed, 7 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php b/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php
index 8b4902a..82b76a0 100644
--- a/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php
+++ b/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php
@@ -72,9 +72,16 @@ class TranslatableMarkup extends FormattableMarkup {
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* (optional) The string translation service.
*
+ * @throws \InvalidArgumentException
+ * Exception thrown when $string is not a string.
+ *
* @see \Drupal\Component\Render\FormattableMarkup::placeholderFormat()
*/
public function __construct($string, array $arguments = array(), array $options = array(), TranslationInterface $string_translation = NULL) {
+ if (!is_string($string)) {
+ $message = $string instanceof TranslatableMarkup ? '$string ("' . $string->getUntranslatedString() . '") must be a string.' : '$string ("' . (string) $string . '") must be a string.';
+ throw new \InvalidArgumentException($message);
+ }
$this->string = $string;
$this->arguments = $arguments;
$this->options = $options;