class NodeStatistics in Dashboards with Layout Builder 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Dashboard/NodeStatistics.php \Drupal\dashboards\Plugin\Dashboard\NodeStatistics
Show account info.
Plugin annotation
@Dashboard(
id = "node_statistics",
label = @Translation("Show node types."),
category = @Translation("Statistics"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\dashboards\Plugin\DashboardBase implements ContainerFactoryPluginInterface, DashboardInterface uses StringTranslationTrait
- class \Drupal\dashboards\Plugin\Dashboard\NodeStatistics uses ChartTrait
- class \Drupal\dashboards\Plugin\DashboardBase implements ContainerFactoryPluginInterface, DashboardInterface uses StringTranslationTrait
Expanded class hierarchy of NodeStatistics
File
- src/
Plugin/ Dashboard/ NodeStatistics.php, line 22
Namespace
Drupal\dashboards\Plugin\DashboardView source
class NodeStatistics extends DashboardBase {
use ChartTrait;
/**
* Entity query.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
*/
protected $entityQuery;
/**
* Entity Type Manager.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeInfo;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CacheBackendInterface $cache, QueryInterface $query_factory, EntityTypeBundleInfoInterface $entity_type_info) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $cache);
$this->entityQuery = $query_factory;
$this->entityTypeInfo = $entity_type_info;
}
/**
* {@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('entity_type.manager')
->getStorage('node')
->getQuery(), $container
->get('entity_type.bundle.info'));
}
/**
* {@inheritdoc}
*/
public function buildSettingsForm(array $form, FormStateInterface $form_state, array $configuration) : array {
$form['chart_type'] = [
'#type' => 'select',
'#options' => $this
->getAllowedStyles(),
'#default_value' => isset($configuration['chart_type']) ? $configuration['chart_type'] : 'pie',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function buildRenderArray($configuration) : array {
if (isset($configuration['chart_type'])) {
$this
->setChartType($configuration['chart_type']);
}
$types = $this->entityTypeInfo
->getBundleInfo('node');
$rows = [];
$empty = TRUE;
foreach ($types as $bundle => $type) {
$data = $this->entityQuery
->condition('type', $bundle)
->count()
->execute();
$rows[] = [
$type['label'],
$data,
];
if ($data > 0) {
$empty = FALSE;
}
}
if ($empty) {
$rows = [];
$this
->setEmpty(TRUE);
}
$this
->setLabels([
$this
->t('Node Type'),
$this
->t('Count'),
]);
$this
->setRows($rows);
return $this
->renderChart($configuration);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChartTrait:: |
protected | property | Empty flag. | |
ChartTrait:: |
protected | property | Labels. | |
ChartTrait:: |
protected | property | Rows. | |
ChartTrait:: |
protected | property | Chart type. | |
ChartTrait:: |
public | function | Add a label. | |
ChartTrait:: |
public | function | Add a row. | |
ChartTrait:: |
public | function | Get allowed styles. | |
ChartTrait:: |
public | function | Set all rows. | |
ChartTrait:: |
public | function | Add a label. | |
ChartTrait:: |
public | function | Set this chart is empty. | |
ChartTrait:: |
public | function | Set all labels. | |
ChartTrait:: |
public | function | Set all rows. | |
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 |
NodeStatistics:: |
protected | property | Entity query. | |
NodeStatistics:: |
protected | property | Entity Type Manager. | |
NodeStatistics:: |
public | function |
Build render array. Overrides DashboardBase:: |
|
NodeStatistics:: |
public | function |
Build render array. Overrides DashboardBase:: |
|
NodeStatistics:: |
public static | function |
Creates an instance of the plugin. Overrides DashboardBase:: |
|
NodeStatistics:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides DashboardBase:: |
|
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. |