From 7fa9c2e13fb23e8fae796bb85b7916698ec14c23 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Thu, 12 Dec 2013 10:59:29 +0000
Subject: [PATCH] Issue #2144701 by Xano: Copy PluginBase's translation
 wrappers to ContextAwarePluginBase.

---
 .../Core/Condition/ConditionPluginBase.php    |  2 +-
 .../Core/Plugin/ContextAwarePluginBase.php    | 44 +++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
index f5bafbb55655..e583e412c6e7 100644
--- a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
+++ b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
@@ -35,7 +35,7 @@ public function isNegated() {
   public function buildForm(array $form, array &$form_state) {
     $form['negate'] = array(
       '#type' => 'checkbox',
-      '#title' => t('Negate the condition.'),
+      '#title' => $this->t('Negate the condition.'),
       '#default_value' => isset($this->configuration['negate']) ? $this->configuration['negate'] : FALSE,
     );
     return $form;
diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
index 86f75297c409..9f3fbf0f857f 100644
--- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
+++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
@@ -11,6 +11,7 @@
 use Drupal\Component\Plugin\Exception\PluginException;
 use Drupal\Core\Plugin\Context\Context;
 use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
+use Drupal\Core\StringTranslation\TranslationInterface;
 
 /**
  * Drupal specific class for plugins that use context.
@@ -54,4 +55,47 @@ public function setContextValue($name, $value) {
     return $this;
   }
 
+  /**
+   * The translation manager service.
+   *
+   * @var \Drupal\Core\StringTranslation\TranslationInterface
+   */
+  protected $translationManager;
+
+  /**
+   * Translates a string to the current language or to a given language.
+   *
+   * See the t() documentation for details.
+   */
+  protected function t($string, array $args = array(), array $options = array()) {
+    return $this->translationManager()->translate($string, $args, $options);
+  }
+
+  /**
+   * Gets the translation manager.
+   *
+   * @return \Drupal\Core\StringTranslation\TranslationInterface
+   *   The translation manager.
+   */
+  protected function translationManager() {
+    if (!$this->translationManager) {
+      $this->translationManager = \Drupal::translation();
+    }
+    return $this->translationManager;
+  }
+
+  /**
+   * Sets the translation manager for this plugin.
+   *
+   * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager
+   *   The translation manager.
+   *
+   * @return self
+   *   The plugin object.
+   */
+  public function setTranslationManager(TranslationInterface $translation_manager) {
+    $this->translationManager = $translation_manager;
+    return $this;
+  }
+
 }
-- 
GitLab