mutual_credit-5.0.x-dev/src/Plugin/views/argument_default/CurrentUserWallets.php
src/Plugin/views/argument_default/CurrentUserWallets.php
<?php namespace Drupal\mcapi\Plugin\views\argument_default; use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase; use Drupal\user\Entity\User; use Drupal\mcapi\Entity\Storage\WalletStorage; use Symfony\Component\DependencyInjection\ContainerInterface; /** * The fixed argument default handler. * * @ingroup views_argument_default_plugins * * @ViewsArgumentDefault( * id = "current_user_wallets", * title = @Translation("Wallets of the current user") * ) */ class CurrentUserWallets extends ArgumentDefaultPluginBase { private $currentUser; public function __construct(array $configuration, $plugin_id, $plugin_definition, $current_user) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->currentUser = $current_user; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('current_user') ); } /** * Return the default argument. */ public function getArgument() { $user = User::load($this->currentUser->id()); $ids = WalletStorage::walletsOf($user, FALSE); return implode('+', $ids); } }