diff --git a/core/lib/Drupal/Core/Plugin/PluginBase.php b/core/lib/Drupal/Core/Plugin/PluginBase.php index 03f952a..b957185 100644 --- a/core/lib/Drupal/Core/Plugin/PluginBase.php +++ b/core/lib/Drupal/Core/Plugin/PluginBase.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Plugin; use Drupal\Component\Plugin\PluginBase as ComponentPluginBase; +use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\TranslationInterface; /** @@ -23,6 +24,39 @@ protected $translationManager; /** + * Current user object. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + + /** + * Gets the current active user. + * + * @return \Drupal\Core\Session\AccountInterface + */ + public function currentUser() { + if (!$this->currentUser) { + $this->currentUser = \Drupal::currentUser(); + } + return $this->currentUser; + } + + /** + * Sets the current active user. + * + * @param \Drupal\Core\Session\AccountInterface $user + * The current user. + * + * @return self + * The plugin object. + */ + public function setCurrentUser(AccountInterface $user) { + $this->currentUser = $user; + return $this; + } + + /** * Translates a string to the current language or to a given language. * * See the t() documentation for details.