diff --git a/core/modules/tracker/src/Plugin/Menu/UserTrackerTab.php b/core/modules/tracker/src/Plugin/Menu/UserTrackerTab.php index db0f2b4632..b2bea4accb 100644 --- a/core/modules/tracker/src/Plugin/Menu/UserTrackerTab.php +++ b/core/modules/tracker/src/Plugin/Menu/UserTrackerTab.php @@ -3,12 +3,15 @@ namespace Drupal\tracker\Plugin\Menu; use Drupal\Core\Menu\LocalTaskDefault; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Session\AccountInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides route parameters needed to link to the current user tracker tab. */ -class UserTrackerTab extends LocalTaskDefault { +class UserTrackerTab extends LocalTaskDefault implements ContainerFactoryPluginInterface { /** * Current user object. @@ -18,25 +21,39 @@ class UserTrackerTab extends LocalTaskDefault { protected $currentUser; /** - * Gets the current active user. + * Construct the UserTrackerTab object. * - * @todo: https://www.drupal.org/node/2105123 put this method in - * \Drupal\Core\Plugin\PluginBase instead. - * - * @return \Drupal\Core\Session\AccountInterface + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param array $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current user. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, AccountInterface $current_user) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->currentUser = $current_user; + } + + /** + * {@inheritdoc} */ - protected function currentUser() { - if (!$this->currentUser) { - $this->currentUser = \Drupal::currentUser(); - } - return $this->currentUser; + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('current_user') + ); } /** * {@inheritdoc} */ public function getRouteParameters(RouteMatchInterface $route_match) { - return ['user' => $this->currentUser()->Id()]; + return ['user' => $this->currentUser->id()]; } }