Commit 7fa9c2e1 authored by catch's avatar catch

Issue #2144701 by Xano: Copy PluginBase's translation wrappers to ContextAwarePluginBase.

parent 6add3e8a
...@@ -35,7 +35,7 @@ public function isNegated() { ...@@ -35,7 +35,7 @@ public function isNegated() {
public function buildForm(array $form, array &$form_state) { public function buildForm(array $form, array &$form_state) {
$form['negate'] = array( $form['negate'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Negate the condition.'), '#title' => $this->t('Negate the condition.'),
'#default_value' => isset($this->configuration['negate']) ? $this->configuration['negate'] : FALSE, '#default_value' => isset($this->configuration['negate']) ? $this->configuration['negate'] : FALSE,
); );
return $form; return $form;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\Context;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
/** /**
* Drupal specific class for plugins that use context. * Drupal specific class for plugins that use context.
...@@ -54,4 +55,47 @@ public function setContextValue($name, $value) { ...@@ -54,4 +55,47 @@ public function setContextValue($name, $value) {
return $this; 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;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment