TfaEnabledField.php in Two-factor Authentication (TFA) 8
File
src/Plugin/views/field/TfaEnabledField.php
View source
<?php
namespace Drupal\tfa\Plugin\views\field;
use Drupal\Component\Utility\Xss as UtilityXss;
use Drupal\user\UserDataInterface;
use Drupal\views\Plugin\views\field\Boolean;
use Drupal\views\Render\ViewsRenderPipelineMarkup;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TfaEnabledField extends Boolean {
protected $userData;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('user.data'));
}
public function __construct(array $configuration, $plugin_id, $plugin_definition, UserDataInterface $user_data) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->userData = $user_data;
}
public function render(ResultRow $values) {
$uid = $this
->getValue($values);
$data = $this->userData
->get('tfa', $uid, 'tfa_user_settings');
$value = $data['saved'] ?? FALSE;
if ($this->options['type'] == 'custom') {
$custom_value = $value ? $this->options['type_custom_true'] : $this->options['type_custom_false'];
return ViewsRenderPipelineMarkup::create(UtilityXss::filterAdmin($custom_value));
}
elseif (isset($this->formats[$this->options['type']])) {
return $value ? $this->formats[$this->options['type']][0] : $this->formats[$this->options['type']][1];
}
else {
return $value ? $this->formats['yes-no'][0] : $this->formats['yes-no'][1];
}
}
}
Classes
Name |
Description |
TfaEnabledField |
Provides a views field to show if the selected user has enabled TFA. |