Commit f22264a4 authored by alexpott's avatar alexpott

Issue #1823398 by olli, damiankloip, fastangel: Incorrect name for anonymous...

Issue #1823398 by olli, damiankloip, fastangel: Incorrect name for anonymous when is used title in one view with Contextual filters (UID).
parent 7d42bc24
......@@ -2,13 +2,15 @@
/**
* @file
* Definition of Drupal\user\Plugin\views\argument\Uid.
* Contains \Drupal\user\Plugin\views\argument\Uid.
*/
namespace Drupal\user\Plugin\views\argument;
use Drupal\Component\Annotation\PluginID;
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\views\Plugin\views\argument\Numeric;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Argument handler to accept a user id.
......@@ -19,6 +21,38 @@
*/
class Uid extends Numeric {
/**
* The user storage controller.
*
* @var \Drupal\Core\Entity\EntityStorageControllerInterface
*/
protected $storageController;
/**
* Constructs a Drupal\Component\Plugin\PluginBase object.
*
* @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\Entity\EntityStorageControllerInterface $storage_controller
* The user storage controller.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageControllerInterface $storage_controller) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->storageController = $storage_controller;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition,
$container->get('entity.manager')->getStorageController('user'));
}
/**
* Override the behavior of title(). Get the name of the user.
*
......@@ -26,17 +60,9 @@ class Uid extends Numeric {
* A list of usernames.
*/
public function titleQuery() {
if (!$this->argument) {
return array(\Drupal::config('user.settings')->get('anonymous'));
}
$titles = array();
$users = user_load_multiple($this->value);
foreach ($users as $account) {
$titles[] = check_plain($account->label());
}
return $titles;
return array_map(function($account) {
return String::checkPlain($account->label());
}, $this->storageController->loadMultiple($this->value));
}
}
......@@ -43,6 +43,17 @@ public function testArgumentTitle() {
$this->executeView($view, array($account->id()));
$this->assertEqual($view->getTitle(), $account->label());
$view->destroy();
// Tests the anonymous user.
$anonymous = $this->container->get('config.factory')->get('user.settings')->get('anonymous');
$this->executeView($view, array(0));
$this->assertEqual($view->getTitle(), $anonymous);
$view->destroy();
$view->getDisplay()->getHandler('argument', 'uid')->options['break_phrase'] = TRUE;
$this->executeView($view, array($account->id() . ',0'));
$this->assertEqual($view->getTitle(), $account->label() . ', ' . $anonymous);
$view->destroy();
}
}
......@@ -34,6 +34,7 @@ function user_views_data() {
'argument' => array(
'id' => 'user_uid',
'name field' => 'name',
'empty field name' => \Drupal::config('user.settings')->get('anonymous'),
),
'filter' => array(
'title' => t('Name'),
......
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