class ContentStateStatistic in Content Planner 8
Provides a Dashboard block for Content Planner Dashboard.
Plugin annotation
@DashboardBlock(
id = "content_state_statistic",
name = @Translation("Content Status Widget")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\content_planner\DashboardBlockBase implements DashboardBlockInterface, ContainerFactoryPluginInterface uses ConfigFormBaseTrait
- class \Drupal\content_kanban\Plugin\DashboardBlock\ContentStateStatistic implements ContainerFactoryPluginInterface uses MessengerTrait
- class \Drupal\content_planner\DashboardBlockBase implements DashboardBlockInterface, ContainerFactoryPluginInterface uses ConfigFormBaseTrait
Expanded class hierarchy of ContentStateStatistic
File
- modules/
content_kanban/ src/ Plugin/ DashboardBlock/ ContentStateStatistic.php, line 24
Namespace
Drupal\content_kanban\Plugin\DashboardBlockView source
class ContentStateStatistic extends DashboardBlockBase implements ContainerFactoryPluginInterface {
use MessengerTrait;
/**
* The Kanban Statistic service.
*
* @var \Drupal\content_kanban\KanbanStatisticService
*/
protected $kanbanStatisticService;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager);
$this
->setMessenger($messenger);
$this->kanbanStatisticService = \Drupal::service('content_kanban.kanban_statistic_service');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('messenger'));
}
/**
* {@inheritdoc}
*/
public function getConfigSpecificFormFields(FormStateInterface &$form_state, Request &$request, array $block_configuration) {
$form = [];
$workflow_options = [];
// Get all workflows.
$workflows = Workflow::loadMultiple();
/* @var $workflow \Drupal\workflows\Entity\Workflow */
foreach ($workflows as $workflow) {
if ($workflow
->status()) {
$workflow_options[$workflow
->id()] = $workflow
->label();
}
}
$form['workflow_id'] = [
'#type' => 'select',
'#title' => t('Select workflow'),
'#required' => TRUE,
'#options' => $workflow_options,
'#default_value' => $this
->getCustomConfigByKey($block_configuration, 'workflow_id', ''),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function build() {
// Get config.
$config = $this
->getConfiguration();
// Get Workflow ID from config.
$workflow_id = $this
->getCustomConfigByKey($config, 'workflow_id', '');
// Load workflow.
$workflow = Workflow::load($workflow_id);
// If workflow does not exist.
if (!$workflow) {
$message = t('Content Status Statistic: Workflow with ID @id does not exist. Block will not be shown.', [
'@id' => $workflow_id,
]);
$this
->messenger()
->addError($message);
return [];
}
// Get data.
$data = $this->kanbanStatisticService
->getWorkflowStateContentCounts($workflow);
$build = [
'#theme' => 'content_state_statistic',
'#data' => $data,
'#attached' => [
'library' => [
'content_kanban/content_state_statistic',
],
],
];
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
ContentStateStatistic:: |
protected | property | The Kanban Statistic service. | |
ContentStateStatistic:: |
public | function |
Build the block and return a renderable array. Overrides DashboardBlockBase:: |
|
ContentStateStatistic:: |
public static | function |
Creates an instance of the plugin. Overrides DashboardBlockBase:: |
|
ContentStateStatistic:: |
public | function |
Add additonal form elements specific to the Plugin. Overrides DashboardBlockBase:: |
|
ContentStateStatistic:: |
public | function |
Constructs a new UserLoginBlock instance. Overrides DashboardBlockBase:: |
|
DashboardBlockBase:: |
protected | property | The route match. | |
DashboardBlockBase:: |
public static | function | Get basic configuration structure for the block configuration. | |
DashboardBlockBase:: |
public | function |
Get Configuration passed in by Plugin Manager. Overrides DashboardBlockInterface:: |
|
DashboardBlockBase:: |
protected | function | Get custom config. | |
DashboardBlockBase:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
DashboardBlockBase:: |
public | function |
Return the name of the block. Overrides DashboardBlockInterface:: |
|
DashboardBlockBase:: |
public | function |
Determines if the plugin is configurable. Overrides PluginBase:: |
|
DashboardBlockBase:: |
public | function |
Submit form handler. Overrides DashboardBlockInterface:: |
|
DashboardBlockBase:: |
public | function |
Validates teh plugin config form. Overrides DashboardBlockInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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:: |