class Account in Dashboards with Layout Builder 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Dashboard/Account.php \Drupal\dashboards\Plugin\Dashboard\Account
Show account info.
Plugin annotation
@Dashboard(
id = "account",
label = @Translation("Show current user"),
category = @Translation("Account")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\dashboards\Plugin\DashboardBase implements ContainerFactoryPluginInterface, DashboardInterface uses StringTranslationTrait
- class \Drupal\dashboards\Plugin\Dashboard\Account
- class \Drupal\dashboards\Plugin\DashboardBase implements ContainerFactoryPluginInterface, DashboardInterface uses StringTranslationTrait
Expanded class hierarchy of Account
File
- src/
Plugin/ Dashboard/ Account.php, line 23
Namespace
Drupal\dashboards\Plugin\DashboardView source
class Account extends DashboardBase {
/**
* AccountInterface definition.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* Entity query for entity views displays.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* EntityTypeManagerInterface.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CacheBackendInterface $cache, AccountInterface $account, EntityDisplayRepositoryInterface $entity_display_repository, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $cache);
$this->account = $account;
$this->entityDisplayRepository = $entity_display_repository;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('dashboards.cache'), $container
->get('current_user'), $container
->get('entity_display.repository'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function buildRenderArray($configuration) : array {
$user = User::load($this->account
->id());
return $this->entityTypeManager
->getViewBuilder($user
->getEntityTypeId())
->view($user, $configuration['view_mode']);
}
/**
* {@inheritdoc}
*/
public function buildSettingsForm(array $form, FormStateInterface $form_state, array $configuration) : array {
$form['view_mode'] = [
'#type' => 'select',
'#options' => $this->entityDisplayRepository
->getViewModeOptions('user'),
'#default_value' => isset($configuration['view_mode']) ? $configuration['view_mode'] : FALSE,
];
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Account:: |
protected | property | AccountInterface definition. | |
Account:: |
protected | property | Entity query for entity views displays. | |
Account:: |
protected | property | EntityTypeManagerInterface. | |
Account:: |
public | function |
Build render array. Overrides DashboardBase:: |
|
Account:: |
public | function |
Build render array. Overrides DashboardBase:: |
|
Account:: |
public static | function |
Creates an instance of the plugin. Overrides DashboardBase:: |
|
Account:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides DashboardBase:: |
|
DashboardBase:: |
protected | property | Cache backend. | |
DashboardBase:: |
protected | function | Get cache for cid. | |
DashboardBase:: |
public | function | Validate settings form. | |
DashboardBase:: |
protected | function | Set a new cache entry. Cache is prefixed by pluginid. | |
DashboardBase:: |
public | function | Validate settings form. | 1 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |